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