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

Side by Side Diff: components/metrics/drive_metrics_provider.h

Issue 1254983003: Componentize DriveMetricsProvider* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 4 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
« no previous file with comments | « components/metrics/BUILD.gn ('k') | components/metrics/drive_metrics_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_ 5 #ifndef COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_
6 #define CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_ 6 #define COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/sequenced_task_runner.h"
12 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
13 #include "components/metrics/metrics_provider.h" 15 #include "components/metrics/metrics_provider.h"
14 #include "components/metrics/proto/system_profile.pb.h" 16 #include "components/metrics/proto/system_profile.pb.h"
15 17
16 namespace base { 18 namespace base {
17 class FilePath; 19 class FilePath;
18 } 20 }
19 21
22 namespace metrics {
23
20 // Provides metrics about the local drives on a user's computer. Currently only 24 // Provides metrics about the local drives on a user's computer. Currently only
21 // checks to see if they incur a seek-time penalty (e.g. if they're SSDs). 25 // checks to see if they incur a seek-time penalty (e.g. if they're SSDs).
22 // 26 //
23 // Defers gathering metrics until after "rush hour" (startup) so as to not bog 27 // Defers gathering metrics until after "rush hour" (startup) so as to not bog
24 // down the FILE thread. 28 // down the file thread.
25 class DriveMetricsProvider : public metrics::MetricsProvider { 29 class DriveMetricsProvider : public metrics::MetricsProvider {
26 public: 30 public:
27 DriveMetricsProvider(); 31 DriveMetricsProvider(scoped_refptr<base::SequencedTaskRunner> file_thread,
32 int local_state_path_key);
28 ~DriveMetricsProvider() override; 33 ~DriveMetricsProvider() override;
29 34
30 // metrics::MetricsDataProvider: 35 // metrics::MetricsDataProvider:
31 void ProvideSystemProfileMetrics( 36 void ProvideSystemProfileMetrics(
32 metrics::SystemProfileProto* system_profile_proto) override; 37 metrics::SystemProfileProto* system_profile_proto) override;
33 38
34 // Called by ChromeMetricsServiceClient to start gathering metrics. 39 // Called to start gathering metrics.
35 void GetDriveMetrics(const base::Closure& done); 40 void GetDriveMetrics(const base::Closure& done);
36 41
37 private: 42 private:
38 FRIEND_TEST_ALL_PREFIXES(DriveMetricsProviderTest, HasSeekPenalty); 43 FRIEND_TEST_ALL_PREFIXES(DriveMetricsProviderTest, HasSeekPenalty);
39 44
40 // A response to querying a drive as to whether it incurs a seek penalty. 45 // A response to querying a drive as to whether it incurs a seek penalty.
41 // |has_seek_penalty| is set if |success| is true. 46 // |has_seek_penalty| is set if |success| is true.
42 struct SeekPenaltyResponse { 47 struct SeekPenaltyResponse {
43 SeekPenaltyResponse(); 48 SeekPenaltyResponse();
44 bool success; 49 bool success;
45 bool has_seek_penalty; 50 bool has_seek_penalty;
46 }; 51 };
47 52
48 struct DriveMetrics { 53 struct DriveMetrics {
49 SeekPenaltyResponse app_drive; 54 SeekPenaltyResponse app_drive;
50 SeekPenaltyResponse user_data_drive; 55 SeekPenaltyResponse user_data_drive;
51 }; 56 };
52 57
53 // Determine whether the device that services |path| has a seek penalty. 58 // Determine whether the device that services |path| has a seek penalty.
54 // Returns false if it couldn't be determined (e.g., |path| doesn't exist). 59 // Returns false if it couldn't be determined (e.g., |path| doesn't exist).
55 static bool HasSeekPenalty(const base::FilePath& path, 60 static bool HasSeekPenalty(const base::FilePath& path,
56 bool* has_seek_penalty); 61 bool* has_seek_penalty);
57 62
58 // Gather metrics about various drives on the FILE thread. 63 // Gather metrics about various drives on |file_thread_|.
59 static DriveMetrics GetDriveMetricsOnFileThread(); 64 static DriveMetrics GetDriveMetricsOnFileThread(int local_state_path_key);
60 65
61 // Tries to determine whether there is a penalty for seeking on the drive that 66 // Tries to determine whether there is a penalty for seeking on the drive that
62 // hosts |path_service_key| (for example: the drive that holds "Local State"). 67 // hosts |path_service_key| (for example: the drive that holds "Local State").
63 static void QuerySeekPenalty(int path_service_key, 68 static void QuerySeekPenalty(int path_service_key,
64 SeekPenaltyResponse* response); 69 SeekPenaltyResponse* response);
65 70
66 // Called when metrics are done being gathered from the FILE thread. 71 // Called when metrics are done being gathered from the FILE thread.
67 void GotDriveMetrics(const DriveMetrics& metrics); 72 void GotDriveMetrics(const DriveMetrics& metrics);
68 73
69 // Fills |drive| with information from successful |response|s. 74 // Fills |drive| with information from successful |response|s.
70 void FillDriveMetrics( 75 void FillDriveMetrics(const SeekPenaltyResponse& response,
71 const SeekPenaltyResponse& response, 76 metrics::SystemProfileProto::Hardware::Drive* drive);
72 metrics::SystemProfileProto::Hardware::Drive* drive); 77
78 // The thread on which file operations are performed (supplied by the
79 // embedder).
80 scoped_refptr<base::SequencedTaskRunner> file_thread_;
81
82 // The key to give to base::PathService to obtain the path to local state
83 // (supplied by the embedder).
84 int local_state_path_key_;
73 85
74 // Information gathered about various important drives. 86 // Information gathered about various important drives.
75 DriveMetrics metrics_; 87 DriveMetrics metrics_;
76 88
77 // Called when metrics are done being collected. 89 // Called when metrics are done being collected.
78 base::Closure got_metrics_callback_; 90 base::Closure got_metrics_callback_;
79 91
80 base::ThreadChecker thread_checker_; 92 base::ThreadChecker thread_checker_;
81 base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_; 93 base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_;
82 94
83 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider); 95 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider);
84 }; 96 };
85 97
86 #endif // CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_ 98 } // namespace metrics
99
100 #endif // COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_
OLDNEW
« no previous file with comments | « components/metrics/BUILD.gn ('k') | components/metrics/drive_metrics_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698