#include "chrome/browser/extensions/api/feedback_private/chrome_feedback_private_delegate.h"
#include <memory>
#include <string>
#include "base/functional/bind.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/feedback/feedback_uploader_chrome.h"
#include "chrome/browser/feedback/feedback_uploader_factory_chrome.h"
#include "chrome/browser/feedback/show_feedback_page.h"
#include "chrome/browser/feedback/system_logs/chrome_system_logs_fetcher.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/grit/generated_resources.h"
#include "components/feedback/system_logs/system_logs_fetcher.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_context.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/strings/string_split.h"
#include "base/system/sys_info.h"
#include "chrome/browser/ash/arc/arc_util.h"
#include "chrome/browser/ash/crosapi/browser_manager.h"
#include "chrome/browser/ash/system_logs/iwlwifi_dump_log_source.h"
#include "chrome/browser/ash/system_logs/single_debug_daemon_log_source.h"
#include "chrome/browser/ash/system_logs/single_log_file_log_source.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "components/feedback/system_logs/system_logs_source.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "google_apis/gaia/gaia_auth_util.h"
#endif
namespace extensions {
namespace {
int GetSysInfoCheckboxStringId(content::BrowserContext* browser_context) { … }
}
ChromeFeedbackPrivateDelegate::ChromeFeedbackPrivateDelegate() = default;
ChromeFeedbackPrivateDelegate::~ChromeFeedbackPrivateDelegate() = default;
base::Value::Dict ChromeFeedbackPrivateDelegate::GetStrings(
content::BrowserContext* browser_context,
bool from_crash) const { … }
void ChromeFeedbackPrivateDelegate::FetchSystemInformation(
content::BrowserContext* context,
system_logs::SysLogsFetcherCallback callback) const { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::unique_ptr<system_logs::SystemLogsSource>
ChromeFeedbackPrivateDelegate::CreateSingleLogSource(
api::feedback_private::LogSource source_type) const {
using SupportedLogFileSource =
system_logs::SingleLogFileLogSource::SupportedSource;
using SupportedDebugDaemonSource =
system_logs::SingleDebugDaemonLogSource::SupportedSource;
switch (source_type) {
case api::feedback_private::LogSource::kMessages:
return std::make_unique<system_logs::SingleLogFileLogSource>(
SupportedLogFileSource::kMessages);
case api::feedback_private::LogSource::kUiLatest:
return std::make_unique<system_logs::SingleLogFileLogSource>(
SupportedLogFileSource::kUiLatest);
case api::feedback_private::LogSource::kAtrusLog:
return std::make_unique<system_logs::SingleLogFileLogSource>(
SupportedLogFileSource::kAtrusLog);
case api::feedback_private::LogSource::kNetLog:
return std::make_unique<system_logs::SingleLogFileLogSource>(
SupportedLogFileSource::kNetLog);
case api::feedback_private::LogSource::kEventLog:
return std::make_unique<system_logs::SingleLogFileLogSource>(
SupportedLogFileSource::kEventLog);
case api::feedback_private::LogSource::kUpdateEngineLog:
return std::make_unique<system_logs::SingleLogFileLogSource>(
SupportedLogFileSource::kUpdateEngineLog);
case api::feedback_private::LogSource::kPowerdLatest:
return std::make_unique<system_logs::SingleLogFileLogSource>(
SupportedLogFileSource::kPowerdLatest);
case api::feedback_private::LogSource::kPowerdPrevious:
return std::make_unique<system_logs::SingleLogFileLogSource>(
SupportedLogFileSource::kPowerdPrevious);
case api::feedback_private::LogSource::kDrmModetest:
return std::make_unique<system_logs::SingleDebugDaemonLogSource>(
SupportedDebugDaemonSource::kModetest);
case api::feedback_private::LogSource::kLsusb:
return std::make_unique<system_logs::SingleDebugDaemonLogSource>(
SupportedDebugDaemonSource::kLsusb);
case api::feedback_private::LogSource::kLspci:
return std::make_unique<system_logs::SingleDebugDaemonLogSource>(
SupportedDebugDaemonSource::kLspci);
case api::feedback_private::LogSource::kIfconfig:
return std::make_unique<system_logs::SingleDebugDaemonLogSource>(
SupportedDebugDaemonSource::kIfconfig);
case api::feedback_private::LogSource::kUptime:
return std::make_unique<system_logs::SingleDebugDaemonLogSource>(
SupportedDebugDaemonSource::kUptime);
case api::feedback_private::LogSource::kNone:
default:
NOTREACHED_IN_MIGRATION() << "Unknown log source type.";
return nullptr;
}
}
void OnFetchedExtraLogs(
scoped_refptr<feedback::FeedbackData> feedback_data,
FetchExtraLogsCallback callback,
std::unique_ptr<system_logs::SystemLogsResponse> response) {
using system_logs::kIwlwifiDumpKey;
if (response && response->count(kIwlwifiDumpKey)) {
feedback_data->AddLog(kIwlwifiDumpKey,
std::move(response->at(kIwlwifiDumpKey)));
}
std::move(callback).Run(feedback_data);
}
void ChromeFeedbackPrivateDelegate::FetchExtraLogs(
scoped_refptr<feedback::FeedbackData> feedback_data,
FetchExtraLogsCallback callback) const {
constexpr bool scrub = true;
if (system_logs::ContainsIwlwifiLogs(feedback_data->sys_info())) {
system_logs::SystemLogsFetcher* fetcher =
new system_logs::SystemLogsFetcher(scrub, nullptr);
fetcher->AddSource(std::make_unique<system_logs::IwlwifiDumpLogSource>());
fetcher->Fetch(base::BindOnce(&OnFetchedExtraLogs, feedback_data,
std::move(callback)));
} else {
std::move(callback).Run(feedback_data);
}
}
api::feedback_private::LandingPageType
ChromeFeedbackPrivateDelegate::GetLandingPageType(
const feedback::FeedbackData& feedback_data) const {
if (!gaia::IsGoogleInternalAccountEmail(feedback_data.user_email()))
return api::feedback_private::LandingPageType::kNormal;
const std::vector<std::string> board =
base::SplitString(base::SysInfo::GetLsbReleaseBoard(), "-",
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
return board[0] == "eve" ? api::feedback_private::LandingPageType::kTechstop
: api::feedback_private::LandingPageType::kNormal;
}
void ChromeFeedbackPrivateDelegate::GetLacrosHistograms(
GetHistogramsCallback callback) {
crosapi::BrowserManager* browser_manager = crosapi::BrowserManager::Get();
if (browser_manager->GetHistogramsSupported() &&
browser_manager->IsRunning()) {
browser_manager->GetHistograms(std::move(callback));
} else {
std::move(callback).Run(std::string());
}
}
#endif
std::string ChromeFeedbackPrivateDelegate::GetSignedInUserEmail(
content::BrowserContext* context) const { … }
void ChromeFeedbackPrivateDelegate::NotifyFeedbackDelayed() const { … }
feedback::FeedbackUploader*
ChromeFeedbackPrivateDelegate::GetFeedbackUploaderForContext(
content::BrowserContext* context) const { … }
void ChromeFeedbackPrivateDelegate::OpenFeedback(
content::BrowserContext* context,
api::feedback_private::FeedbackSource source) const { … }
}