OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/thread_checker.h" |
| 12 #include "components/metrics/metrics_provider.h" |
| 13 #include "components/metrics/proto/system_profile.pb.h" |
| 14 |
| 15 // Provides metrics about the local drives on a user's computer. Currently only |
| 16 // checks to see if they incur a seek-time penalty (e.g. if they're SSDs). |
| 17 // |
| 18 // Defers gathering metrics until after "rush hour" (startup) so as to not bog |
| 19 // down the FILE thread. |
| 20 class DriveMetricsProvider : public metrics::MetricsProvider { |
| 21 public: |
| 22 DriveMetricsProvider(); |
| 23 ~DriveMetricsProvider() override; |
| 24 |
| 25 // metrics::MetricsDataProvider: |
| 26 void ProvideSystemProfileMetrics( |
| 27 metrics::SystemProfileProto* system_profile_proto) override; |
| 28 |
| 29 // Called by ChromeMetricsServiceClient to start gathering metrics. |
| 30 void GetDriveMetrics(const base::Closure& done); |
| 31 |
| 32 private: |
| 33 // A response to querying a drive as to whether it incurs a seek penalty. |
| 34 // |has_seek_penalty| is set if |success| is true. |
| 35 struct SeekPenaltyResponse { |
| 36 SeekPenaltyResponse(); |
| 37 bool success; |
| 38 bool has_seek_penalty; |
| 39 }; |
| 40 |
| 41 struct DriveMetrics { |
| 42 SeekPenaltyResponse app_drive; |
| 43 SeekPenaltyResponse user_data_drive; |
| 44 }; |
| 45 |
| 46 // Gather metrics about various drives on the FILE thread. |
| 47 static DriveMetrics GetDriveMetricsOnFileThread(); |
| 48 |
| 49 // Tries to determine whether there is a penalty for seeking on the drive that |
| 50 // hosts |path_service_key| (for example: the drive that holds "Local State"). |
| 51 static void QuerySeekPenalty(int path_service_key, |
| 52 SeekPenaltyResponse* response); |
| 53 |
| 54 // Called when metrics are done being gathered from the FILE thread. |
| 55 void GotDriveMetrics(const DriveMetrics& metrics); |
| 56 |
| 57 // Fills |drive| with information from successful |response|s. |
| 58 void FillDriveMetrics( |
| 59 const SeekPenaltyResponse& response, |
| 60 metrics::SystemProfileProto::Hardware::Drive* drive); |
| 61 |
| 62 // Information gathered about various important drives. |
| 63 DriveMetrics metrics_; |
| 64 |
| 65 // Called when metrics are done being collected. |
| 66 base::Closure got_metrics_callback_; |
| 67 |
| 68 base::ThreadChecker thread_checker_; |
| 69 base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider); |
| 72 }; |
| 73 |
| 74 #endif // CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_ |
OLD | NEW |