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

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

Issue 2963573004: [Cleanup] Migrate the WatcherMetricsProvider to use the Task Scheduler. (Closed)
Patch Set: Document that registry interactions can block, and adjust the unittest not to be flaky Created 3 years, 5 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
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/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/task_runner.h" 13 #include "base/task_runner.h"
14 #include "base/threading/thread_checker.h"
15 #include "components/metrics/metrics_provider.h" 14 #include "components/metrics/metrics_provider.h"
16 15
17 namespace browser_watcher { 16 namespace browser_watcher {
18 17
19 // Provides stability data captured by the Chrome Watcher, namely the browser 18 // Provides stability data captured by the Chrome Watcher, namely the browser
20 // process exit codes. 19 // process exit codes.
21 class WatcherMetricsProviderWin : public metrics::MetricsProvider { 20 class WatcherMetricsProviderWin : public metrics::MetricsProvider {
22 public: 21 public:
23 // A callback that provides product name, version number and channel name. 22 // A callback that provides product name, version number and channel name.
24 using GetExecutableDetailsCallback = 23 using GetExecutableDetailsCallback =
25 base::Callback<void(base::string16*, base::string16*, base::string16*)>; 24 base::Callback<void(base::string16*, base::string16*, base::string16*)>;
26 25
27 static const char kBrowserExitCodeHistogramName[]; 26 static const char kBrowserExitCodeHistogramName[];
28 27
29 // Initializes the reporter. |io_task_runner| is used for collecting 28 // Initializes the reporter.
30 // postmortem reports and clearing leftover data in registry if metrics
31 // reporting is disabled.
32 WatcherMetricsProviderWin(const base::string16& registry_path, 29 WatcherMetricsProviderWin(const base::string16& registry_path,
33 const base::FilePath& user_data_dir, 30 const base::FilePath& user_data_dir,
34 const base::FilePath& crash_dir, 31 const base::FilePath& crash_dir,
35 const GetExecutableDetailsCallback& exe_details_cb, 32 const GetExecutableDetailsCallback& exe_details_cb);
36 base::TaskRunner* io_task_runner);
37 ~WatcherMetricsProviderWin() override; 33 ~WatcherMetricsProviderWin() override;
38 34
39 // metrics::MetricsProvider implementation. 35 // metrics::MetricsProvider implementation.
40 void OnRecordingEnabled() override; 36 void OnRecordingEnabled() override;
41 void OnRecordingDisabled() override; 37 void OnRecordingDisabled() override;
42 // Note: this function collects metrics, some of which are related to the 38 // Note: this function collects metrics, some of which are related to the
43 // previous run's version and some to the current version. Doing the correct 39 // previous run's version and some to the current version. Doing the correct
44 // attribution on upgrade is difficult, and currently ignored. Metrics 40 // attribution on upgrade is difficult, and currently ignored. Metrics
45 // clearing is one mechanism to avoid misattribution, but is not used in this 41 // clearing is one mechanism to avoid misattribution, but is not used in this
46 // case (ClearSavedStabilityMetrics is not overridden) as version 42 // case (ClearSavedStabilityMetrics is not overridden) as version
47 // misattribution is preferred to data loss. Metrics will likely be attributed 43 // misattribution is preferred to data loss. Metrics will likely be attributed
48 // to the previous run's version, unless no initial log is sent, in which case 44 // to the previous run's version, unless no initial log is sent, in which case
49 // they should be attributed to the current version (though they may actually 45 // they should be attributed to the current version (though they may actually
50 // be attributed to still another following version). 46 // be attributed to still another following version).
51 // TODO(manzagop): proper metric version attribution on upgrade. 47 // TODO(manzagop): proper metric version attribution on upgrade.
52 void ProvideStabilityMetrics( 48 void ProvideStabilityMetrics(
53 metrics::SystemProfileProto* system_profile_proto) override; 49 metrics::SystemProfileProto* system_profile_proto) override;
54 50
55 // Collects postmortem reports asynchronously and calls |done_callback| when 51 // Collects postmortem reports asynchronously and calls |done_callback| when
56 // done. 52 // done.
57 void CollectPostmortemReports(const base::Closure& done_callback); 53 void CollectPostmortemReports(const base::Closure& done_callback);
58 54
59 private: 55 private:
60 // TODO(manzagop): avoid collecting reports for clean exits from the fast exit 56 // TODO(manzagop): avoid collecting reports for clean exits from the fast exit
61 // path. 57 // path.
62 void CollectPostmortemReportsOnBlockingPool(); 58 void CollectPostmortemReportsImpl();
63 59
64 bool recording_enabled_; 60 bool recording_enabled_;
65 bool cleanup_scheduled_; 61 bool cleanup_scheduled_;
66 const base::string16 registry_path_; 62 const base::string16 registry_path_;
67 const base::FilePath user_data_dir_; 63 const base::FilePath user_data_dir_;
68 const base::FilePath crash_dir_; 64 const base::FilePath crash_dir_;
69 GetExecutableDetailsCallback exe_details_cb_; 65 GetExecutableDetailsCallback exe_details_cb_;
70 scoped_refptr<base::TaskRunner> io_task_runner_; 66
67 // Used for collecting postmortem reports and clearing leftover data in
68 // registry if metrics reporting is disabled.
69 scoped_refptr<base::TaskRunner> task_runner_;
70
71 base::WeakPtrFactory<WatcherMetricsProviderWin> weak_ptr_factory_; 71 base::WeakPtrFactory<WatcherMetricsProviderWin> weak_ptr_factory_;
72 72
73 DISALLOW_COPY_AND_ASSIGN(WatcherMetricsProviderWin); 73 DISALLOW_COPY_AND_ASSIGN(WatcherMetricsProviderWin);
74 }; 74 };
75 75
76 } // namespace browser_watcher 76 } // namespace browser_watcher
77 77
78 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_METRICS_PROVIDER_WIN_H_ 78 #endif // COMPONENTS_BROWSER_WATCHER_WATCHER_METRICS_PROVIDER_WIN_H_
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_service_client.cc ('k') | components/browser_watcher/watcher_metrics_provider_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698