chromium/components/feedback/system_logs/system_logs_fetcher.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// List of keys in the SystemLogsResponse map whose corresponding values will
// not be redacted.
constexpr const char* const kKeysExemptOfRedaction[] =;

#if BUILDFLAG(IS_CHROMEOS_ASH)
constexpr char kLacrosLogEntryPrefix[] = "Lacros ";
#endif

// Returns true if the given |key| and its corresponding value are exempt from
// redaction.
bool IsKeyExempt(const std::string& key) {}

// Runs the Redaction tool over the entris of |response|.
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

}  // namespace

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)
// TODO(crbug.com/40736068): Add test cases to exercise this code path.
void SystemLogsFetcher::MergeAshAndLacrosCrashReportIdsInReponse() {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  // Merge the lacros and ash recent crash report ids into a single log entry
  // with the key defined by kCrashReportIdsKey, i.e. crash_report_ids.
  auto ash_crash_iter =
      response_->find(feedback::FeedbackReport::kCrashReportIdsKey);
  // If ash crash_report_ids log entry is not found, it means CrashIdsSource
  // is not included in log sources, for example, the code is called by
  // BuildShellSystemLogsFetcher. Stop further processing.
  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;

  // Update the crash_report_ids with the merged value.
  ash_crash_iter->second =
      MergeStingsByComma(ash_crash_report_ids, lacros_crash_report_ids);
  // Remove the lacros log entry of recent crash report ids.
  response_->erase(lacros_crash_report_key);

  // Merge the lacros and ash all crash report ids into a single log entry
  // with key defined by kAllCrashReportIdsKey, i.e. all_crash_report_ids.
  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 there are only recent crashes from Lacros, let lacros crash ids
  // go first; otherwise, ash crash ids will go first.
  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);
  }

  // Update all_crash_report_ids with merged value.
  ash_all_crash_iter->second = all_crash_report_ids;
  // Remove the Lacros log entry of all crash report ids.
  response_->erase(lacros_all_crash_report_key);
}
#endif

void SystemLogsFetcher::RunCallbackAndDeleteSoon() {}

}  // namespace system_logs