| 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 // Deletes stability files. |
| 32 class PostmortemDeleter { |
| 33 public: |
| 34 PostmortemDeleter() = default; |
| 35 ~PostmortemDeleter() = default; |
| 36 |
| 37 void Process(const std::vector<base::FilePath>& stability_files); |
| 38 }; |
| 39 |
| 31 // Handles postmortem report collection by establishing the set of stability | 40 // Handles postmortem report collection by establishing the set of stability |
| 32 // files to collect, then for each file: | 41 // files to collect, then for each file: |
| 33 // - extracting a report protocol buffer | 42 // - extracting a report protocol buffer |
| 34 // - registering a crash report with the crash database | 43 // - registering a crash report with the crash database |
| 35 // - writing a minidump file for the report | 44 // - writing a minidump file for the report |
| 36 // TODO(manzagop): throttling, graceful handling of accumulating data. | 45 // TODO(manzagop): throttling, graceful handling of accumulating data. |
| 37 class PostmortemReportCollector { | 46 class PostmortemReportCollector { |
| 38 public: | 47 public: |
| 39 PostmortemReportCollector(const std::string& product_name, | 48 PostmortemReportCollector(const std::string& product_name, |
| 40 const std::string& version_number, | 49 const std::string& version_number, |
| 41 const std::string& channel_name, | 50 const std::string& channel_name, |
| 51 crashpad::CrashReportDatabase* report_database, |
| 42 SystemSessionAnalyzer* analyzer); | 52 SystemSessionAnalyzer* analyzer); |
| 43 virtual ~PostmortemReportCollector(); | 53 ~PostmortemReportCollector(); |
| 44 | 54 |
| 45 // Collects postmortem stability reports from files found in |debug_info_dir|, | 55 // Collects postmortem stability reports from |stability_files|. Reports are |
| 46 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are | 56 // then wrapped in Crashpad reports and registered with the crash database. |
| 47 // then wrapped in Crashpad reports, manufactured via |report_database|. | 57 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 | 58 |
| 57 const std::string& product_name() const { return product_name_; } | 59 const std::string& product_name() const { return product_name_; } |
| 58 const std::string& version_number() const { return version_number_; } | 60 const std::string& version_number() const { return version_number_; } |
| 59 const std::string& channel_name() const { return channel_name_; } | 61 const std::string& channel_name() const { return channel_name_; } |
| 60 | 62 |
| 61 private: | 63 private: |
| 62 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, | 64 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, |
| 63 GetDebugStateFilePaths); | 65 GetDebugStateFilePaths); |
| 64 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); | 66 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); |
| 65 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); | 67 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); |
| 66 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, | 68 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, |
| 67 CollectSuccess); | 69 CollectSuccess); |
| 68 FRIEND_TEST_ALL_PREFIXES( | 70 FRIEND_TEST_ALL_PREFIXES( |
| 69 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 71 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 70 LogCollection); | 72 LogCollection); |
| 71 FRIEND_TEST_ALL_PREFIXES( | 73 FRIEND_TEST_ALL_PREFIXES( |
| 72 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 74 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 73 ProcessUserDataCollection); | 75 ProcessUserDataCollection); |
| 74 FRIEND_TEST_ALL_PREFIXES( | 76 FRIEND_TEST_ALL_PREFIXES( |
| 75 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 77 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 76 FieldTrialCollection); | 78 FieldTrialCollection); |
| 77 FRIEND_TEST_ALL_PREFIXES( | 79 FRIEND_TEST_ALL_PREFIXES( |
| 78 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 80 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 79 ModuleCollection); | 81 ModuleCollection); |
| 80 FRIEND_TEST_ALL_PREFIXES( | 82 FRIEND_TEST_ALL_PREFIXES( |
| 81 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 83 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 82 SystemStateTest); | 84 SystemStateTest); |
| 83 | 85 |
| 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 | 86 // Collects a stability file, generates a report and registers it with the |
| 91 // database. Returns true on success. False otherwise. | 87 // database. |
| 92 bool CollectAndSubmitOneReport(const crashpad::UUID& client_id, | 88 void CollectAndSubmitOneReport(const crashpad::UUID& client_id, |
| 93 const base::FilePath& file, | 89 const base::FilePath& file); |
| 94 crashpad::CrashReportDatabase* report_database, | |
| 95 bool* system_unclean); | |
| 96 | 90 |
| 97 virtual CollectionStatus CollectOneReport( | 91 virtual CollectionStatus CollectOneReport( |
| 98 const base::FilePath& stability_file, | 92 const base::FilePath& stability_file, |
| 99 StabilityReport* report); | 93 StabilityReport* report); |
| 100 | 94 |
| 101 void SetReporterDetails(StabilityReport* report) const; | 95 void SetReporterDetails(StabilityReport* report) const; |
| 102 | 96 |
| 103 void RecordSystemShutdownState(StabilityReport* report) const; | 97 void RecordSystemShutdownState(StabilityReport* report) const; |
| 104 | 98 |
| 105 virtual bool WriteReportToMinidump(StabilityReport* report, | 99 virtual bool WriteReportToMinidump(StabilityReport* report, |
| 106 const crashpad::UUID& client_id, | 100 const crashpad::UUID& client_id, |
| 107 const crashpad::UUID& report_id, | 101 const crashpad::UUID& report_id, |
| 108 base::PlatformFile minidump_file); | 102 base::PlatformFile minidump_file); |
| 109 | 103 |
| 110 std::string product_name_; | 104 std::string product_name_; |
| 111 std::string version_number_; | 105 std::string version_number_; |
| 112 std::string channel_name_; | 106 std::string channel_name_; |
| 113 | 107 |
| 108 crashpad::CrashReportDatabase* report_database_; // Not owned. |
| 114 SystemSessionAnalyzer* system_session_analyzer_; // Not owned. | 109 SystemSessionAnalyzer* system_session_analyzer_; // Not owned. |
| 115 | 110 |
| 116 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); | 111 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); |
| 117 }; | 112 }; |
| 118 | 113 |
| 119 } // namespace browser_watcher | 114 } // namespace browser_watcher |
| 120 | 115 |
| 121 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | 116 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ |
| OLD | NEW |