OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #include "components/browser_watcher/stability_report_user_stream_data_source.h" | |
6 | |
7 #include <string> | |
8 #include <utility> | |
9 | |
10 #include "base/files/file.h" | |
11 #include "base/files/file_util.h" | |
12 #include "base/memory/ptr_util.h" | |
13 #include "base/metrics/histogram_macros.h" | |
14 #include "base/strings/string16.h" | |
15 #include "base/time/time.h" | |
16 #include "components/browser_watcher/minidump_user_streams.h" | |
17 #include "components/browser_watcher/stability_paths.h" | |
18 #include "components/browser_watcher/stability_report_extractor.h" | |
19 #include "third_party/crashpad/crashpad/minidump/minidump_user_extension_stream_ data_source.h" | |
20 #include "third_party/crashpad/crashpad/snapshot/process_snapshot.h" | |
21 | |
22 namespace browser_watcher { | |
23 | |
24 namespace { | |
25 | |
26 void GetStabilityFileName(const base::string16& user_data_dir, | |
Sigurður Ásgeirsson
2017/05/11 19:28:29
Actually, might as well return the file path?
grt (UTC plus 2)
2017/05/11 21:08:16
yes, please. we treat FilePath as a value type --
manzagop (departed)
2017/05/12 19:27:32
Done.
| |
27 crashpad::ProcessSnapshot* process_snapshot, | |
28 base::FilePath* stability_file) { | |
29 DCHECK(process_snapshot); | |
30 DCHECK(stability_file); | |
31 | |
32 timeval creation_time{}; | |
grt (UTC plus 2)
2017/05/11 21:08:16
nit: chromium prefers assignment when possible (ht
manzagop (departed)
2017/05/12 19:27:32
Done.
| |
33 process_snapshot->ProcessStartTime(&creation_time); | |
34 | |
35 *stability_file = | |
36 GetStabilityFileForProcess(process_snapshot->ProcessID(), creation_time, | |
37 base::FilePath(user_data_dir)); | |
38 } | |
39 | |
40 class BufferExtensionStreamDataSource final | |
grt (UTC plus 2)
2017/05/11 21:08:16
i see precious few classes marked "final" in chrom
manzagop (departed)
2017/05/12 19:27:32
Validating before sending the email. It seems to b
grt (UTC plus 2)
2017/05/15 13:03:18
Yes. I read through some of the discussions, and e
manzagop (departed)
2017/05/15 13:43:45
Sent the email. Done.
| |
41 : public crashpad::MinidumpUserExtensionStreamDataSource { | |
42 public: | |
43 BufferExtensionStreamDataSource(uint32_t stream_type, | |
44 const StabilityReport& report); | |
45 | |
46 bool Init() { return is_init_; } | |
Sigurður Ásgeirsson
2017/05/11 19:28:29
Hmmm, this seems contrived and/or not super well n
manzagop (departed)
2017/05/12 19:27:32
Done.
| |
47 | |
48 // Precondition: Init() returns true. | |
49 size_t StreamDataSize() override; | |
50 bool ReadStreamData(Delegate* delegate) override; | |
51 | |
52 private: | |
53 bool is_init_; | |
54 std::string data_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(BufferExtensionStreamDataSource); | |
57 }; | |
58 | |
59 BufferExtensionStreamDataSource::BufferExtensionStreamDataSource( | |
60 uint32_t stream_type, | |
61 const StabilityReport& report) | |
62 : crashpad::MinidumpUserExtensionStreamDataSource(stream_type), | |
63 is_init_(true) { | |
64 if (!report.SerializeToString(&data_)) { | |
65 data_.clear(); | |
66 is_init_ = false; | |
67 } | |
68 } | |
69 | |
70 size_t BufferExtensionStreamDataSource::StreamDataSize() { | |
71 DCHECK(Init()); | |
72 return data_.size(); | |
73 } | |
74 | |
75 bool BufferExtensionStreamDataSource::ReadStreamData(Delegate* delegate) { | |
76 DCHECK(Init()); | |
77 return delegate->ExtensionStreamDataSourceRead( | |
78 data_.size() ? data_.data() : nullptr, data_.size()); | |
79 } | |
80 | |
81 std::unique_ptr<BufferExtensionStreamDataSource> CollectReport( | |
82 const base::FilePath& path) { | |
83 StabilityReport report; | |
84 CollectionStatus status = Extract(path, &report); | |
85 UMA_HISTOGRAM_ENUMERATION("ActivityTracker.CollectCrash.Status", status, | |
86 COLLECTION_STATUS_MAX); | |
87 if (status != SUCCESS) | |
88 return nullptr; | |
89 | |
90 // Open (with delete) and then immediately close the file by going out of | |
91 // scope. This should cause the stability debugging file to be deleted prior | |
92 // to the next execution. | |
93 // TODO(manzagop): set the persistent allocator file's state to deleted in | |
94 // case the file can't be deleted. | |
95 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | | |
96 base::File::FLAG_DELETE_ON_CLOSE); | |
97 UMA_HISTOGRAM_BOOLEAN("ActivityTracker.CollectCrash.OpenForDeleteSuccess", | |
98 file.IsValid()); | |
99 | |
100 std::unique_ptr<BufferExtensionStreamDataSource> source( | |
101 new BufferExtensionStreamDataSource(kStabilityReportStreamType, report)); | |
102 return source->Init() ? std::move(source) : nullptr; | |
103 } | |
104 | |
105 } // namespace | |
106 | |
107 StabilityReportUserStreamDataSource::StabilityReportUserStreamDataSource( | |
108 const base::string16& user_data_dir) | |
109 : user_data_dir_(user_data_dir) {} | |
110 | |
111 std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource> | |
112 StabilityReportUserStreamDataSource::ProduceStreamData( | |
113 crashpad::ProcessSnapshot* process_snapshot) { | |
114 DCHECK(process_snapshot); | |
115 | |
116 if (user_data_dir_.empty()) | |
117 return nullptr; | |
118 | |
119 base::FilePath stability_file; | |
120 GetStabilityFileName(user_data_dir_, process_snapshot, &stability_file); | |
121 if (!PathExists(stability_file)) { | |
122 // Either this is not an instrumented process (currenlty only browser | |
Sigurður Ásgeirsson
2017/05/11 19:28:29
nit: speling [sic]
manzagop (departed)
2017/05/12 19:27:32
Done.
| |
123 // processes can be instrumented), or the stability file cannot be found. | |
124 return nullptr; | |
125 } | |
126 | |
127 return CollectReport(stability_file); | |
128 } | |
129 | |
130 } // namespace browser_watcher | |
OLD | NEW |