Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Following an unclean shutdown, a stability report can be collected and | 5 // Following an unclean shutdown, a stability report can be collected and |
| 6 // submitted for upload to a reporter. | 6 // submitted for upload to a reporter. |
| 7 | 7 |
| 8 #ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | 8 #ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ |
| 9 #define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | 9 #define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/gtest_prod_util.h" | 21 #include "base/gtest_prod_util.h" |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
| 24 #include "components/browser_watcher/stability_report.pb.h" | 24 #include "components/browser_watcher/stability_report.pb.h" |
| 25 #include "components/browser_watcher/stability_report_extractor.h" | 25 #include "components/browser_watcher/stability_report_extractor.h" |
| 26 #include "components/browser_watcher/system_session_analyzer_win.h" | 26 #include "components/browser_watcher/system_session_analyzer_win.h" |
| 27 #include "third_party/crashpad/crashpad/client/crash_report_database.h" | 27 #include "third_party/crashpad/crashpad/client/crash_report_database.h" |
| 28 | 28 |
| 29 namespace browser_watcher { | 29 namespace browser_watcher { |
| 30 | 30 |
| 31 // An interface to process postmortem stability files. | |
| 32 class PostmortemProcessor { | |
|
Sigurður Ásgeirsson
2017/06/05 15:39:39
I don't see that hoisting an interface here is hel
manzagop (departed)
2017/06/05 18:02:16
I initially thought there'd be a factory, but didn
| |
| 33 public: | |
| 34 virtual ~PostmortemProcessor() = default; | |
| 35 | |
| 36 virtual void Process(const std::vector<base::FilePath>& stability_files) = 0; | |
| 37 }; | |
| 38 | |
| 39 class PostmortemDeleter : public PostmortemProcessor { | |
| 40 public: | |
| 41 PostmortemDeleter() = default; | |
| 42 ~PostmortemDeleter() override = default; | |
| 43 | |
| 44 void Process(const std::vector<base::FilePath>& stability_files); | |
| 45 }; | |
| 46 | |
| 31 // Handles postmortem report collection by establishing the set of stability | 47 // Handles postmortem report collection by establishing the set of stability |
| 32 // files to collect, then for each file: | 48 // files to collect, then for each file: |
| 33 // - extracting a report protocol buffer | 49 // - extracting a report protocol buffer |
| 34 // - registering a crash report with the crash database | 50 // - registering a crash report with the crash database |
| 35 // - writing a minidump file for the report | 51 // - writing a minidump file for the report |
| 36 // TODO(manzagop): throttling, graceful handling of accumulating data. | 52 // TODO(manzagop): throttling, graceful handling of accumulating data. |
| 37 class PostmortemReportCollector { | 53 class PostmortemReportCollector : public PostmortemProcessor { |
| 38 public: | 54 public: |
| 39 PostmortemReportCollector(const std::string& product_name, | 55 PostmortemReportCollector(const std::string& product_name, |
| 40 const std::string& version_number, | 56 const std::string& version_number, |
| 41 const std::string& channel_name, | 57 const std::string& channel_name, |
| 58 crashpad::CrashReportDatabase* report_database, | |
| 42 SystemSessionAnalyzer* analyzer); | 59 SystemSessionAnalyzer* analyzer); |
| 43 virtual ~PostmortemReportCollector(); | 60 ~PostmortemReportCollector() override; |
| 44 | 61 |
| 45 // Collects postmortem stability reports from files found in |debug_info_dir|, | 62 // Collects postmortem stability reports from |stability_files|. Reports are |
| 46 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are | 63 // then wrapped in Crashpad reports and registered with the crash database. |
| 47 // then wrapped in Crashpad reports, manufactured via |report_database|. | 64 void Process(const std::vector<base::FilePath>& stability_files); |
| 48 // Returns the number crash reports successfully registered with the reporter. | |
| 49 // TODO(manzagop): consider mechanisms for partial collection if this is to be | |
| 50 // used on a critical path. | |
| 51 int CollectAndSubmitAllPendingReports( | |
| 52 const base::FilePath& debug_info_dir, | |
| 53 const base::FilePath::StringType& debug_file_pattern, | |
| 54 const std::set<base::FilePath>& excluded_debug_files, | |
| 55 crashpad::CrashReportDatabase* report_database); | |
| 56 | 65 |
| 57 const std::string& product_name() const { return product_name_; } | 66 const std::string& product_name() const { return product_name_; } |
| 58 const std::string& version_number() const { return version_number_; } | 67 const std::string& version_number() const { return version_number_; } |
| 59 const std::string& channel_name() const { return channel_name_; } | 68 const std::string& channel_name() const { return channel_name_; } |
| 60 | 69 |
| 61 private: | 70 private: |
| 62 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, | 71 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, |
| 63 GetDebugStateFilePaths); | 72 GetDebugStateFilePaths); |
| 64 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); | 73 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); |
| 65 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); | 74 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); |
| 66 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, | 75 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, |
| 67 CollectSuccess); | 76 CollectSuccess); |
| 68 FRIEND_TEST_ALL_PREFIXES( | 77 FRIEND_TEST_ALL_PREFIXES( |
| 69 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 78 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 70 LogCollection); | 79 LogCollection); |
| 71 FRIEND_TEST_ALL_PREFIXES( | 80 FRIEND_TEST_ALL_PREFIXES( |
| 72 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 81 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 73 ProcessUserDataCollection); | 82 ProcessUserDataCollection); |
| 74 FRIEND_TEST_ALL_PREFIXES( | 83 FRIEND_TEST_ALL_PREFIXES( |
| 75 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 84 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 76 FieldTrialCollection); | 85 FieldTrialCollection); |
| 77 FRIEND_TEST_ALL_PREFIXES( | 86 FRIEND_TEST_ALL_PREFIXES( |
| 78 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 87 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 79 ModuleCollection); | 88 ModuleCollection); |
| 80 FRIEND_TEST_ALL_PREFIXES( | 89 FRIEND_TEST_ALL_PREFIXES( |
| 81 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 90 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 82 SystemStateTest); | 91 SystemStateTest); |
| 83 | 92 |
| 84 // Virtual for unittesting. | |
| 85 virtual std::vector<base::FilePath> GetDebugStateFilePaths( | |
| 86 const base::FilePath& debug_info_dir, | |
| 87 const base::FilePath::StringType& debug_file_pattern, | |
| 88 const std::set<base::FilePath>& excluded_debug_files); | |
| 89 | |
| 90 // Collects a stability file, generates a report and registers it with the | 93 // Collects a stability file, generates a report and registers it with the |
| 91 // database. Returns true on success. False otherwise. | 94 // database. |
| 92 bool CollectAndSubmitOneReport(const crashpad::UUID& client_id, | 95 void CollectAndSubmitOneReport(const crashpad::UUID& client_id, |
| 93 const base::FilePath& file, | 96 const base::FilePath& file); |
| 94 crashpad::CrashReportDatabase* report_database, | |
| 95 bool* system_unclean); | |
| 96 | 97 |
| 97 virtual CollectionStatus CollectOneReport( | 98 virtual CollectionStatus CollectOneReport( |
| 98 const base::FilePath& stability_file, | 99 const base::FilePath& stability_file, |
| 99 StabilityReport* report); | 100 StabilityReport* report); |
| 100 | 101 |
| 101 void SetReporterDetails(StabilityReport* report) const; | 102 void SetReporterDetails(StabilityReport* report) const; |
| 102 | 103 |
| 103 void RecordSystemShutdownState(StabilityReport* report) const; | 104 void RecordSystemShutdownState(StabilityReport* report) const; |
| 104 | 105 |
| 105 virtual bool WriteReportToMinidump(StabilityReport* report, | 106 virtual bool WriteReportToMinidump(StabilityReport* report, |
| 106 const crashpad::UUID& client_id, | 107 const crashpad::UUID& client_id, |
| 107 const crashpad::UUID& report_id, | 108 const crashpad::UUID& report_id, |
| 108 base::PlatformFile minidump_file); | 109 base::PlatformFile minidump_file); |
| 109 | 110 |
| 110 std::string product_name_; | 111 std::string product_name_; |
| 111 std::string version_number_; | 112 std::string version_number_; |
| 112 std::string channel_name_; | 113 std::string channel_name_; |
| 113 | 114 |
| 115 crashpad::CrashReportDatabase* report_database_; // Not owned. | |
| 114 SystemSessionAnalyzer* system_session_analyzer_; // Not owned. | 116 SystemSessionAnalyzer* system_session_analyzer_; // Not owned. |
| 115 | 117 |
| 116 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); | 118 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); |
| 117 }; | 119 }; |
| 118 | 120 |
| 119 } // namespace browser_watcher | 121 } // namespace browser_watcher |
| 120 | 122 |
| 121 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | 123 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ |
| OLD | NEW |