Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: components/browser_watcher/postmortem_report_collector.h

Issue 2339193003: A collector for postmortem reports (Closed)
Patch Set: Address nits Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 and creates Crashpad minidumps.
27 // TODO(manzagop): throttling, graceful handling of accumulating data.
28 // TODO(manzagop): UMA metrics and some error logging.
29 class PostmortemReportCollector {
30 public:
31 // DO NOT CHANGE VALUES. This is logged persistently in a histogram.
32 enum CollectionStatus {
33 NONE = 0,
34 SUCCESS = 1, // Successfully registered a report with Crashpad.
35 ANALYZER_CREATION_FAILED = 2,
36 DEBUG_FILE_NO_DATA = 3,
37 PREPARE_NEW_CRASH_REPORT_FAILED = 4,
38 WRITE_TO_MINIDUMP_FAILED = 5,
39 DEBUG_FILE_DELETION_FAILED = 6,
40 FINISHED_WRITING_CRASH_REPORT_FAILED = 7,
41 COLLECTION_STATUS_MAX = 8
42 };
43
44 PostmortemReportCollector() = default;
45 virtual ~PostmortemReportCollector() = default;
46
47 // Collects postmortem stability reports from files found in |debug_info_dir|,
48 // relying on |debug_file_pattern| and |excluded_debug_files|. Reports are
49 // then wrapped in Crashpad reports, manufactured via |report_database|.
50 // Returns the number crash reports successfully registered with the reporter.
51 // TODO(manzagop): consider mechanisms for partial collection if this is to be
52 // used on a critical path.
53 int CollectAndSubmitForUpload(
54 const base::FilePath& debug_info_dir,
55 const base::FilePath::StringType& debug_file_pattern,
56 const std::set<base::FilePath>& excluded_debug_files,
57 crashpad::CrashReportDatabase* report_database);
58
59 private:
60 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest,
61 GetDebugStateFilePaths);
62 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectEmptyFile);
63 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorTest, CollectRandomFile);
64 FRIEND_TEST_ALL_PREFIXES(PostmortemReportCollectorCollectionTest,
65 CollectSuccess);
66
67 // Virtual for unittesting.
68 virtual std::vector<base::FilePath> GetDebugStateFilePaths(
69 const base::FilePath& debug_info_dir,
70 const base::FilePath::StringType& debug_file_pattern,
71 const std::set<base::FilePath>& excluded_debug_files);
72
73 CollectionStatus CollectAndSubmit(
74 const crashpad::UUID& client_id,
75 const base::FilePath& file,
76 crashpad::CrashReportDatabase* report_database);
77
78 // Virtual for unittesting.
79 // TODO(manzagop): move this for reuse in live scenario.
80 virtual CollectionStatus Collect(const base::FilePath& debug_state_file,
81 std::unique_ptr<StabilityReport>* report);
82
83 virtual bool WriteReportToMinidump(const StabilityReport& report,
84 const crashpad::UUID& client_id,
85 const crashpad::UUID& report_id,
86 base::PlatformFile minidump_file);
87
88 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollector);
89 };
90
91 } // namespace browser_watcher
92
93 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_REPORT_COLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698