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 |
| 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 <vector> | 16 #include <vector> |
| 16 | 17 |
| 18 #include "base/callback_forward.h" | |
| 17 #include "base/files/file.h" | 19 #include "base/files/file.h" |
| 18 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
| 19 #include "base/gtest_prod_util.h" | 21 #include "base/gtest_prod_util.h" |
| 20 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/strings/string16.h" | |
| 21 #include "components/browser_watcher/stability_report.pb.h" | 24 #include "components/browser_watcher/stability_report.pb.h" |
| 22 #include "third_party/crashpad/crashpad/client/crash_report_database.h" | 25 #include "third_party/crashpad/crashpad/client/crash_report_database.h" |
| 23 | 26 |
| 24 namespace browser_watcher { | 27 namespace browser_watcher { |
| 25 | 28 |
| 26 // Collects unclean shutdown information and creates Crashpad minidumps. | 29 // Collects unclean shutdown information and creates Crashpad minidumps. |
| 27 // TODO(manzagop): throttling, graceful handling of accumulating data. | 30 // TODO(manzagop): throttling, graceful handling of accumulating data. |
| 28 // TODO(manzagop): UMA metrics and some error logging. | 31 // TODO(manzagop): UMA metrics and some error logging. |
| 29 class PostmortemReportCollector { | 32 class PostmortemReportCollector { |
| 30 public: | 33 public: |
| 34 using GetExecutableDetailsCallback = | |
|
grt (UTC plus 2)
2016/09/28 19:42:45
wdyt of getting rid of this callback and instead h
manzagop (departed)
2016/09/29 15:23:14
Done.
| |
| 35 base::Callback<void(base::string16*, base::string16*, base::string16*)>; | |
| 36 | |
| 31 // DO NOT CHANGE VALUES. This is logged persistently in a histogram. | 37 // DO NOT CHANGE VALUES. This is logged persistently in a histogram. |
| 32 enum CollectionStatus { | 38 enum CollectionStatus { |
| 33 NONE = 0, | 39 NONE = 0, |
| 34 SUCCESS = 1, // Successfully registered a report with Crashpad. | 40 SUCCESS = 1, // Successfully registered a report with Crashpad. |
| 35 ANALYZER_CREATION_FAILED = 2, | 41 ANALYZER_CREATION_FAILED = 2, |
| 36 DEBUG_FILE_NO_DATA = 3, | 42 DEBUG_FILE_NO_DATA = 3, |
| 37 PREPARE_NEW_CRASH_REPORT_FAILED = 4, | 43 PREPARE_NEW_CRASH_REPORT_FAILED = 4, |
| 38 WRITE_TO_MINIDUMP_FAILED = 5, | 44 WRITE_TO_MINIDUMP_FAILED = 5, |
| 39 DEBUG_FILE_DELETION_FAILED = 6, | 45 DEBUG_FILE_DELETION_FAILED = 6, |
| 40 FINISHED_WRITING_CRASH_REPORT_FAILED = 7, | 46 FINISHED_WRITING_CRASH_REPORT_FAILED = 7, |
| 41 COLLECTION_STATUS_MAX = 8 | 47 COLLECTION_STATUS_MAX = 8 |
| 42 }; | 48 }; |
| 43 | 49 |
| 44 PostmortemReportCollector() = default; | 50 explicit PostmortemReportCollector( |
| 51 const GetExecutableDetailsCallback& exe_details_cb); | |
| 45 virtual ~PostmortemReportCollector() = default; | 52 virtual ~PostmortemReportCollector() = default; |
| 46 | 53 |
| 47 // Collects postmortem stability reports from files found in |debug_info_dir|, | 54 // Collects postmortem stability reports from files found in |debug_info_dir|, |
| 48 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are | 55 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are |
| 49 // then wrapped in Crashpad reports, manufactured via |report_database|. | 56 // then wrapped in Crashpad reports, manufactured via |report_database|. |
| 50 // Returns the number crash reports successfully registered with the reporter. | 57 // Returns the number crash reports successfully registered with the reporter. |
| 51 // TODO(manzagop): consider mechanisms for partial collection if this is to be | 58 // TODO(manzagop): consider mechanisms for partial collection if this is to be |
| 52 // used on a critical path. | 59 // used on a critical path. |
| 53 int CollectAndSubmitForUpload( | 60 int CollectAndSubmitForUpload( |
| 54 const base::FilePath& debug_info_dir, | 61 const base::FilePath& debug_info_dir, |
| 55 const base::FilePath::StringType& debug_file_pattern, | 62 const base::FilePath::StringType& debug_file_pattern, |
| 56 const std::set<base::FilePath>& excluded_debug_files, | 63 const std::set<base::FilePath>& excluded_debug_files, |
| 57 crashpad::CrashReportDatabase* report_database); | 64 crashpad::CrashReportDatabase* report_database); |
| 58 | 65 |
| 66 const std::string& product_name() const { return product_name_; } | |
| 67 const std::string& version_number() const { return version_number_; } | |
| 68 const std::string& channel_name() const { return channel_name_; } | |
| 69 | |
| 59 private: | 70 private: |
| 60 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, | 71 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, |
| 61 GetDebugStateFilePaths); | 72 GetDebugStateFilePaths); |
| 62 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); | 73 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); |
| 63 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); | 74 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); |
| 64 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, | 75 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, |
| 65 CollectSuccess); | 76 CollectSuccess); |
| 66 | 77 |
| 67 // Virtual for unittesting. | 78 // Virtual for unittesting. |
| 68 virtual std::vector<base::FilePath> GetDebugStateFilePaths( | 79 virtual std::vector<base::FilePath> GetDebugStateFilePaths( |
| 69 const base::FilePath& debug_info_dir, | 80 const base::FilePath& debug_info_dir, |
| 70 const base::FilePath::StringType& debug_file_pattern, | 81 const base::FilePath::StringType& debug_file_pattern, |
| 71 const std::set<base::FilePath>& excluded_debug_files); | 82 const std::set<base::FilePath>& excluded_debug_files); |
| 72 | 83 |
| 73 CollectionStatus CollectAndSubmit( | 84 CollectionStatus CollectAndSubmit( |
| 74 const crashpad::UUID& client_id, | 85 const crashpad::UUID& client_id, |
| 75 const base::FilePath& file, | 86 const base::FilePath& file, |
| 76 crashpad::CrashReportDatabase* report_database); | 87 crashpad::CrashReportDatabase* report_database); |
| 77 | 88 |
| 78 // Virtual for unittesting. | 89 // Virtual for unittesting. |
| 79 // TODO(manzagop): move this for reuse in live scenario. | 90 // TODO(manzagop): move this for reuse in live scenario. |
| 80 virtual CollectionStatus Collect(const base::FilePath& debug_state_file, | 91 virtual CollectionStatus Collect(const base::FilePath& debug_state_file, |
| 81 std::unique_ptr<StabilityReport>* report); | 92 std::unique_ptr<StabilityReport>* report); |
| 82 | 93 |
| 83 virtual bool WriteReportToMinidump(const StabilityReport& report, | 94 virtual bool WriteReportToMinidump(const StabilityReport& report, |
| 84 const crashpad::UUID& client_id, | 95 const crashpad::UUID& client_id, |
| 85 const crashpad::UUID& report_id, | 96 const crashpad::UUID& report_id, |
| 86 base::PlatformFile minidump_file); | 97 base::PlatformFile minidump_file); |
| 87 | 98 |
| 99 std::string product_name_; | |
| 100 std::string version_number_; | |
| 101 std::string channel_name_; | |
| 102 | |
| 88 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); | 103 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); |
| 89 }; | 104 }; |
| 90 | 105 |
| 91 } // namespace browser_watcher | 106 } // namespace browser_watcher |
| 92 | 107 |
| 93 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | 108 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ |
| OLD | NEW |