Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // Following an unclean shutdown, a stability report can be collected and | |
| 6 // submitted for upload to a reporter. | |
| 7 | |
| 8 #ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | |
| 9 #define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | |
| 10 | |
| 11 #include <stdio.h> | |
| 12 | |
| 13 #include <memory> | |
| 14 #include <set> | |
| 15 #include <vector> | |
| 16 | |
| 17 #include "base/files/file.h" | |
| 18 #include "base/files/file_path.h" | |
| 19 #include "base/gtest_prod_util.h" | |
| 20 #include "base/macros.h" | |
| 21 #include "components/browser_watcher/stability_report.pb.h" | |
| 22 #include "third_party/crashpad/crashpad/client/crash_report_database.h" | |
| 23 | |
| 24 namespace browser_watcher { | |
| 25 | |
| 26 // Collects unclean shutdown information, builds reports out of it and submits | |
| 27 // the reports for upload to a delegate. | |
| 28 // TODO(manzagop): throttling, graceful handling of accumulating data. | |
| 29 // TODO(manzagop): UMA metrics and some error logging. | |
|
Sigurður Ásgeirsson
2016/08/11 17:44:15
as we discussed earlier today, it'd be better^Weas
manzagop (departed)
2016/08/12 21:23:22
Sgtm. Let's include moving the code and this TODO
| |
| 30 class PostmortemReportCollector { | |
| 31 public: | |
| 32 // Creates a postmortem report collector that will look for unclean shutdown | |
| 33 // data in |debug_dir| using |debug_file_pattern|. If data is found, | |
| 34 // |delegate| will be used for reporting. | |
| 35 PostmortemReportCollector( | |
| 36 const base::FilePath& debug_dir, | |
| 37 const base::FilePath::StringType& debug_file_pattern, | |
| 38 std::unique_ptr<crashpad::CrashReportDatabase> report_database); | |
| 39 virtual ~PostmortemReportCollector() = default; | |
| 40 | |
| 41 // Collects reports about unclean shutdowns and submits them for upload. | |
| 42 // |excluded_debug_files| is a set of files to exclude, such as files | |
| 43 // pertaining to a running instance. | |
| 44 void CollectAndSubmitForUpload( | |
| 45 const std::set<base::FilePath>& excluded_debug_files); | |
| 46 | |
| 47 private: | |
| 48 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, | |
| 49 GetDebugStateFilePaths); | |
| 50 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile); | |
| 51 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile); | |
| 52 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest, | |
| 53 CollectSuccess); | |
| 54 | |
| 55 PostmortemReportCollector(); | |
| 56 | |
| 57 // Virtual for unittesting. | |
|
Sigurður Ásgeirsson
2016/08/11 17:44:15
I do hope there's a test for this method, as it ge
manzagop (departed)
2016/08/12 21:23:22
Well... there is a test!
The reason: I was thinki
| |
| 58 virtual std::vector<base::FilePath> GetDebugStateFilePaths( | |
| 59 const std::set<base::FilePath>& excluded_debug_files); | |
| 60 | |
| 61 // Virtual for unittesting. | |
| 62 // TODO(manzagop): move this for reuse in live scenario. | |
| 63 virtual std::unique_ptr<StabilityReport> Collect( | |
| 64 const base::FilePath& debug_state_file); | |
| 65 | |
| 66 virtual bool WriteReportToMinidump(const StabilityReport& report, | |
| 67 const crashpad::UUID& client_id, | |
| 68 const crashpad::UUID& report_id, | |
| 69 FILE* minidump_file); | |
| 70 | |
| 71 base::FilePath debug_state_dir_; | |
|
Sigurður Ásgeirsson
2016/08/11 17:44:15
there doesn't seem to be any benefit to the debug_
manzagop (departed)
2016/08/12 21:23:22
Agreed, removed. The class is now an empty husk. I
| |
| 72 base::FilePath::StringType debug_file_pattern_; | |
| 73 std::unique_ptr<crashpad::CrashReportDatabase> report_database_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector); | |
| 76 }; | |
| 77 | |
| 78 } // namespace browser_watcher | |
| 79 | |
| 80 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_ | |
| OLD | NEW |