OLD | NEW |
---|---|
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/scoped_ptr.h" | |
Alexei Svitkine (slow)
2015/07/30 16:59:52
If this is for the scoped_refptr, should it be bas
blundell
2015/07/30 19:17:14
Yep. Done.
| |
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 scoped_refptr<base::SequencedTaskRunner> file_thread_; | |
79 | |
80 int local_state_path_key_; | |
Alexei Svitkine (slow)
2015/07/30 16:59:52
Nit: Add comments above the members.
blundell
2015/07/30 19:17:14
Done.
| |
73 | 81 |
74 // Information gathered about various important drives. | 82 // Information gathered about various important drives. |
75 DriveMetrics metrics_; | 83 DriveMetrics metrics_; |
76 | 84 |
77 // Called when metrics are done being collected. | 85 // Called when metrics are done being collected. |
78 base::Closure got_metrics_callback_; | 86 base::Closure got_metrics_callback_; |
79 | 87 |
80 base::ThreadChecker thread_checker_; | 88 base::ThreadChecker thread_checker_; |
81 base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_; | 89 base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_; |
82 | 90 |
83 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider); | 91 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider); |
84 }; | 92 }; |
85 | 93 |
86 #endif // CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_ | 94 } // namespace metrics |
95 | |
96 #endif // COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_ | |
OLD | NEW |