1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SUPPORT_TOOL_ASH_SYSTEM_STATE_DATA_COLLECTOR_H_
#define CHROME_BROWSER_SUPPORT_TOOL_ASH_SYSTEM_STATE_DATA_COLLECTOR_H_
#include <map>
#include <set>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner.h"
#include "chrome/browser/support_tool/data_collector.h"
#include "components/feedback/redaction_tool/pii_types.h"
#include "components/feedback/redaction_tool/redaction_tool.h"
class SystemStateDataCollector : public DataCollector {
public:
SystemStateDataCollector();
~SystemStateDataCollector() override;
// The extra logs that are not returned by GetFeedbackLogs() call but we want
// to include. We will request these logs using GetLogs() call.
static const std::vector<std::string> GetExtraLogNames();
// Overrides from DataCollector.
std::string GetName() const override;
std::string GetDescription() const override;
const PIIMap& GetDetectedPII() override;
void CollectDataAndDetectPII(
DataCollectorDoneCallback on_data_collected_callback,
scoped_refptr<base::SequencedTaskRunner> task_runner_for_redaction_tool,
scoped_refptr<redaction::RedactionToolContainer> redaction_tool_container)
override;
void ExportCollectedDataWithPII(
std::set<redaction::PIIType> pii_types_to_keep,
base::FilePath target_directory,
scoped_refptr<base::SequencedTaskRunner> task_runner_for_redaction_tool,
scoped_refptr<redaction::RedactionToolContainer> redaction_tool_container,
DataCollectorDoneCallback on_exported_callback) override;
private:
struct SystemLog {
SystemLog(std::string log, std::set<redaction::PIIType> detected_pii_types);
~SystemLog();
SystemLog(const SystemLog& other);
// Contents of the system log.
std::string log;
// Set of PII types detected in the logs.
std::set<redaction::PIIType> detected_pii_types;
};
static std::pair<PIIMap, std::map<std::string, SystemLog>> DetectPII(
std::map<std::string, SystemLog> system_logs,
scoped_refptr<redaction::RedactionToolContainer> redaction_tool_container);
static std::map<std::string, std::string> RedactPII(
std::map<std::string, SystemLog> system_logs,
std::set<redaction::PIIType> pii_types_to_keep,
scoped_refptr<redaction::RedactionToolContainer> redaction_tool_container);
void OnGetLog(base::RepeatingClosure barrier_closure,
std::string log_name,
std::optional<std::string> log);
void OnGotAllExtraLogs(
scoped_refptr<base::SequencedTaskRunner> task_runner_for_redaction_tool,
scoped_refptr<redaction::RedactionToolContainer> redaction_tool_containe);
void OnGetFeedbackLogs(
scoped_refptr<base::SequencedTaskRunner> task_runner_for_redaction_tool,
scoped_refptr<redaction::RedactionToolContainer> redaction_tool_container,
bool success,
const std::map<std::string, std::string>& logs);
void OnPIIDetected(
std::pair<PIIMap, std::map<std::string, SystemLog>> detection_result);
void OnPIIRedacted(base::FilePath target_directory,
DataCollectorDoneCallback on_exported_callback,
std::map<std::string, std::string> redacted_logs);
// Runs `on_exported_callback` when file is written.
void OnFilesWritten(DataCollectorDoneCallback on_exported_callback,
bool success);
SEQUENCE_CHECKER(sequence_checker_);
PIIMap pii_map_;
std::map<std::string, SystemLog> system_logs_;
std::vector<std::string> get_log_errors_;
DataCollectorDoneCallback data_collector_done_callback_;
base::WeakPtrFactory<SystemStateDataCollector> weak_ptr_factory_{this};
};
#endif // CHROME_BROWSER_SUPPORT_TOOL_ASH_SYSTEM_STATE_DATA_COLLECTOR_H_
|