| 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 |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <set> | 14 #include <set> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/debug/activity_analyzer.h" | 18 #include "base/debug/activity_analyzer.h" |
| 19 #include "base/files/file.h" | 19 #include "base/files/file.h" |
| 20 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
| 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/postmortem_report_extractor.h" | 24 #include "components/browser_watcher/postmortem_report_extractor.h" |
| 25 #include "components/browser_watcher/stability_report.pb.h" | 25 #include "components/browser_watcher/stability_report.pb.h" |
| 26 #include "components/browser_watcher/system_session_analyzer_win.h" |
| 26 #include "third_party/crashpad/crashpad/client/crash_report_database.h" | 27 #include "third_party/crashpad/crashpad/client/crash_report_database.h" |
| 27 | 28 |
| 28 namespace browser_watcher { | 29 namespace browser_watcher { |
| 29 | 30 |
| 30 // Handles postmortem report collection by establishing the set of stability | 31 // Handles postmortem report collection by establishing the set of stability |
| 31 // files to collect, then for each file: | 32 // files to collect, then for each file: |
| 32 // - extracting a report protocol buffer | 33 // - extracting a report protocol buffer |
| 33 // - registering a crash report with the crash database | 34 // - registering a crash report with the crash database |
| 34 // - writing a minidump file for the report | 35 // - writing a minidump file for the report |
| 35 // TODO(manzagop): throttling, graceful handling of accumulating data. | 36 // TODO(manzagop): throttling, graceful handling of accumulating data. |
| 36 class PostmortemReportCollector { | 37 class PostmortemReportCollector { |
| 37 public: | 38 public: |
| 38 PostmortemReportCollector(const std::string& product_name, | 39 PostmortemReportCollector(const std::string& product_name, |
| 39 const std::string& version_number, | 40 const std::string& version_number, |
| 40 const std::string& channel_name); | 41 const std::string& channel_name, |
| 42 SystemSessionAnalyzer* analyzer); |
| 41 virtual ~PostmortemReportCollector(); | 43 virtual ~PostmortemReportCollector(); |
| 42 | 44 |
| 43 // Collects postmortem stability reports from files found in |debug_info_dir|, | 45 // Collects postmortem stability reports from files found in |debug_info_dir|, |
| 44 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are | 46 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are |
| 45 // then wrapped in Crashpad reports, manufactured via |report_database|. | 47 // then wrapped in Crashpad reports, manufactured via |report_database|. |
| 46 // Returns the number crash reports successfully registered with the reporter. | 48 // Returns the number crash reports successfully registered with the reporter. |
| 47 // TODO(manzagop): consider mechanisms for partial collection if this is to be | 49 // TODO(manzagop): consider mechanisms for partial collection if this is to be |
| 48 // used on a critical path. | 50 // used on a critical path. |
| 49 int CollectAndSubmitForUpload( | 51 int CollectAndSubmitAllPendingReports( |
| 50 const base::FilePath& debug_info_dir, | 52 const base::FilePath& debug_info_dir, |
| 51 const base::FilePath::StringType& debug_file_pattern, | 53 const base::FilePath::StringType& debug_file_pattern, |
| 52 const std::set<base::FilePath>& excluded_debug_files, | 54 const std::set<base::FilePath>& excluded_debug_files, |
| 53 crashpad::CrashReportDatabase* report_database); | 55 crashpad::CrashReportDatabase* report_database); |
| 54 | 56 |
| 55 const std::string& product_name() const { return product_name_; } | 57 const std::string& product_name() const { return product_name_; } |
| 56 const std::string& version_number() const { return version_number_; } | 58 const std::string& version_number() const { return version_number_; } |
| 57 const std::string& channel_name() const { return channel_name_; } | 59 const std::string& channel_name() const { return channel_name_; } |
| 58 | 60 |
| 59 private: | 61 private: |
| 60 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, | 62 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, |
| 61 GetDebugStateFilePaths); | 63 GetDebugStateFilePaths); |
| 62 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); | 64 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); |
| 63 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); | 65 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); |
| 64 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, | 66 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, |
| 65 CollectSuccess); | 67 CollectSuccess); |
| 66 FRIEND_TEST_ALL_PREFIXES( | 68 FRIEND_TEST_ALL_PREFIXES( |
| 67 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 69 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 68 LogCollection); | 70 LogCollection); |
| 69 FRIEND_TEST_ALL_PREFIXES( | 71 FRIEND_TEST_ALL_PREFIXES( |
| 70 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 72 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 71 GlobalUserDataCollection); | 73 GlobalUserDataCollection); |
| 72 FRIEND_TEST_ALL_PREFIXES( | 74 FRIEND_TEST_ALL_PREFIXES( |
| 73 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 75 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 74 FieldTrialCollection); | 76 FieldTrialCollection); |
| 75 FRIEND_TEST_ALL_PREFIXES( | 77 FRIEND_TEST_ALL_PREFIXES( |
| 76 PostmortemReportCollectorCollectionFromGlobalTrackerTest, | 78 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 77 ModuleCollection); | 79 ModuleCollection); |
| 80 FRIEND_TEST_ALL_PREFIXES( |
| 81 PostmortemReportCollectorCollectionFromGlobalTrackerTest, |
| 82 SystemStateTest); |
| 78 | 83 |
| 79 // Virtual for unittesting. | 84 // Virtual for unittesting. |
| 80 virtual std::vector<base::FilePath> GetDebugStateFilePaths( | 85 virtual std::vector<base::FilePath> GetDebugStateFilePaths( |
| 81 const base::FilePath& debug_info_dir, | 86 const base::FilePath& debug_info_dir, |
| 82 const base::FilePath::StringType& debug_file_pattern, | 87 const base::FilePath::StringType& debug_file_pattern, |
| 83 const std::set<base::FilePath>& excluded_debug_files); | 88 const std::set<base::FilePath>& excluded_debug_files); |
| 84 | 89 |
| 85 CollectionStatus CollectAndSubmit( | 90 CollectionStatus CollectAndSubmitOneReport( |
| 86 const crashpad::UUID& client_id, | 91 const crashpad::UUID& client_id, |
| 87 const base::FilePath& file, | 92 const base::FilePath& file, |
| 88 crashpad::CrashReportDatabase* report_database); | 93 crashpad::CrashReportDatabase* report_database); |
| 89 | 94 |
| 90 virtual CollectionStatus Collect(const base::FilePath& stability_file, | 95 virtual CollectionStatus CollectOneReport( |
| 91 StabilityReport* report); | 96 const base::FilePath& stability_file, |
| 97 StabilityReport* report); |
| 98 |
| 99 void SetReporterDetails(StabilityReport* report) const; |
| 100 |
| 101 void RecordSystemShutdownState(StabilityReport* report) const; |
| 92 | 102 |
| 93 virtual bool WriteReportToMinidump(StabilityReport* report, | 103 virtual bool WriteReportToMinidump(StabilityReport* report, |
| 94 const crashpad::UUID& client_id, | 104 const crashpad::UUID& client_id, |
| 95 const crashpad::UUID& report_id, | 105 const crashpad::UUID& report_id, |
| 96 base::PlatformFile minidump_file); | 106 base::PlatformFile minidump_file); |
| 97 | 107 |
| 98 std::string product_name_; | 108 std::string product_name_; |
| 99 std::string version_number_; | 109 std::string version_number_; |
| 100 std::string channel_name_; | 110 std::string channel_name_; |
| 101 | 111 |
| 112 SystemSessionAnalyzer* system_session_analyzer_; // Not owned. |
| 113 |
| 102 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); | 114 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); |
| 103 }; | 115 }; |
| 104 | 116 |
| 105 } // namespace browser_watcher | 117 } // namespace browser_watcher |
| 106 | 118 |
| 107 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | 119 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ |
| OLD | NEW |