OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 #ifndef COMPONENTS_BROWSER_WATCHER_WATCHER_METRICS_PROVIDER_WIN_H_ | 5 #ifndef COMPONENTS_BROWSER_WATCHER_WATCHER_METRICS_PROVIDER_WIN_H_ |
6 #define COMPONENTS_BROWSER_WATCHER_WATCHER_METRICS_PROVIDER_WIN_H_ | 6 #define COMPONENTS_BROWSER_WATCHER_WATCHER_METRICS_PROVIDER_WIN_H_ |
7 | 7 |
| 8 #include "base/files/file_path.h" |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" |
9 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
10 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
| 13 #include "base/threading/thread_checker.h" |
11 #include "components/metrics/metrics_provider.h" | 14 #include "components/metrics/metrics_provider.h" |
12 | 15 |
13 namespace browser_watcher { | 16 namespace browser_watcher { |
14 | 17 |
15 // Provides stability data captured by the Chrome Watcher, namely the browser | 18 // Provides stability data captured by the Chrome Watcher, namely the browser |
16 // process exit codes. | 19 // process exit codes. |
17 class WatcherMetricsProviderWin : public metrics::MetricsProvider { | 20 class WatcherMetricsProviderWin : public metrics::MetricsProvider { |
18 public: | 21 public: |
19 static const char kBrowserExitCodeHistogramName[]; | 22 static const char kBrowserExitCodeHistogramName[]; |
20 | 23 |
21 // Initializes the reporter. |cleanup_io_task_runner| is used to clear | 24 // Initializes the reporter. |io_task_runner| is used for collecting |
22 // leftover data in registry if metrics reporting is disabled. | 25 // postmortem reports and clearing leftover data in registry if metrics |
| 26 // reporting is disabled. |
23 WatcherMetricsProviderWin(const base::string16& registry_path, | 27 WatcherMetricsProviderWin(const base::string16& registry_path, |
24 base::TaskRunner* cleanup_io_task_runner); | 28 const base::FilePath& user_data_dir, |
| 29 const base::FilePath& crash_dir, |
| 30 base::TaskRunner* io_task_runner); |
25 ~WatcherMetricsProviderWin() override; | 31 ~WatcherMetricsProviderWin() override; |
26 | 32 |
27 // metrics::MetricsProvider implementation. | 33 // metrics::MetricsProvider implementation. |
28 void OnRecordingEnabled() override; | 34 void OnRecordingEnabled() override; |
29 void OnRecordingDisabled() override; | 35 void OnRecordingDisabled() override; |
| 36 // Note: this function collects metrics, some of which are related to the |
| 37 // previous run's version and some to the current version. Doing the correct |
| 38 // attribution on upgrade is difficult, and currently ignored. Metrics |
| 39 // clearing is one mechanism to avoid misattribution, but is not used in this |
| 40 // case (ClearSavedStabilityMetrics is not overridden) as version |
| 41 // misattribution is preferred to data loss. Metrics will likely be attributed |
| 42 // to the previous run's version, unless no initial log is sent, in which case |
| 43 // they should be attributed to the current version (though they may actually |
| 44 // be attributed to still another following version). |
| 45 // TODO(manzagop): proper metric version attribution on upgrade. |
30 void ProvideStabilityMetrics( | 46 void ProvideStabilityMetrics( |
31 metrics::SystemProfileProto* system_profile_proto) override; | 47 metrics::SystemProfileProto* system_profile_proto) override; |
32 | 48 |
| 49 // Collects postmortem reports asynchronously and calls |done_callback| when |
| 50 // done. |
| 51 void CollectPostmortemReports(const base::Closure& done_callback); |
| 52 |
33 private: | 53 private: |
| 54 // TODO(manzagop): avoid collecting reports for clean exits from the fast exit |
| 55 // path. |
| 56 void CollectPostmortemReportsOnBlockingPool(); |
| 57 |
34 bool recording_enabled_; | 58 bool recording_enabled_; |
35 bool cleanup_scheduled_; | 59 bool cleanup_scheduled_; |
36 const base::string16 registry_path_; | 60 const base::string16 registry_path_; |
37 scoped_refptr<base::TaskRunner> cleanup_io_task_runner_; | 61 const base::FilePath user_data_dir_; |
| 62 const base::FilePath crash_dir_; |
| 63 scoped_refptr<base::TaskRunner> io_task_runner_; |
| 64 base::WeakPtrFactory<WatcherMetricsProviderWin> weak_ptr_factory_; |
38 | 65 |
39 DISALLOW_COPY_AND_ASSIGN(WatcherMetricsProviderWin); | 66 DISALLOW_COPY_AND_ASSIGN(WatcherMetricsProviderWin); |
40 }; | 67 }; |
41 | 68 |
42 } // namespace browser_watcher | 69 } // namespace browser_watcher |
43 | 70 |
44 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_METRICS_PROVIDER_WIN_H_ | 71 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_METRICS_PROVIDER_WIN_H_ |
OLD | NEW |