#include "components/feedback/system_logs/system_logs_fetcher.h"
#include <memory>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/not_fatal_until.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "components/feedback/feedback_report.h"
#endif
namespace system_logs {
namespace {
constexpr const char* const kKeysExemptOfRedaction[] = …;
#if BUILDFLAG(IS_CHROMEOS_ASH)
constexpr char kLacrosLogEntryPrefix[] = "Lacros ";
#endif
bool IsKeyExempt(const std::string& key) { … }
void Redact(redaction::RedactionTool* redactor, SystemLogsResponse* response) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::string MergeStingsByComma(const std::string& str1,
const std::string str2) {
if (str1.empty())
return str2;
if (str2.empty())
return str1;
return str1 + ", " + str2;
}
#endif
}
SystemLogsFetcher::SystemLogsFetcher(
bool scrub_data,
const char* const first_party_extension_ids[])
: … { … }
SystemLogsFetcher::~SystemLogsFetcher() { … }
void SystemLogsFetcher::AddSource(std::unique_ptr<SystemLogsSource> source) { … }
void SystemLogsFetcher::Fetch(SysLogsFetcherCallback callback) { … }
void SystemLogsFetcher::OnFetched(
const std::string& source_name,
std::unique_ptr<SystemLogsResponse> response) { … }
void SystemLogsFetcher::AddResponse(
const std::string& source_name,
std::unique_ptr<SystemLogsResponse> response) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void SystemLogsFetcher::MergeAshAndLacrosCrashReportIdsInReponse() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto ash_crash_iter =
response_->find(feedback::FeedbackReport::kCrashReportIdsKey);
if (ash_crash_iter == response_->end())
return;
std::string ash_crash_report_ids = ash_crash_iter->second;
std::string lacros_crash_report_ids;
std::string lacros_crash_report_key =
std::string(kLacrosLogEntryPrefix) +
feedback::FeedbackReport::kCrashReportIdsKey;
auto lacros_crash_iter = response_->find(lacros_crash_report_key);
if (lacros_crash_iter != response_->end())
lacros_crash_report_ids = lacros_crash_iter->second;
ash_crash_iter->second =
MergeStingsByComma(ash_crash_report_ids, lacros_crash_report_ids);
response_->erase(lacros_crash_report_key);
auto ash_all_crash_iter =
response_->find(feedback::FeedbackReport::kAllCrashReportIdsKey);
CHECK(ash_all_crash_iter != response_->end(), base::NotFatalUntil::M130);
std::string ash_all_crash_report_ids = ash_all_crash_iter->second;
std::string lacros_all_crash_report_ids;
std::string lacros_all_crash_report_key =
std::string(kLacrosLogEntryPrefix) +
feedback::FeedbackReport::kAllCrashReportIdsKey;
auto lacros_all_crash_iter = response_->find(lacros_all_crash_report_key);
if (lacros_all_crash_iter != response_->end())
lacros_all_crash_report_ids = lacros_all_crash_iter->second;
std::string all_crash_report_ids;
if (ash_crash_report_ids.empty() && !lacros_crash_report_ids.empty()) {
all_crash_report_ids = MergeStingsByComma(lacros_all_crash_report_ids,
ash_all_crash_report_ids);
} else {
all_crash_report_ids = MergeStingsByComma(ash_all_crash_report_ids,
lacros_all_crash_report_ids);
}
ash_all_crash_iter->second = all_crash_report_ids;
response_->erase(lacros_all_crash_report_key);
}
#endif
void SystemLogsFetcher::RunCallbackAndDeleteSoon() { … }
}