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.
5 #ifndef CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_
6 #define CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_
8 #include "base/callback.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/metrics/metrics_provider.h"
14 #include "components/metrics/proto/system_profile.pb.h"
20 // 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).
23 // Defers gathering metrics until after "rush hour" (startup) so as to not bog
24 // down the FILE thread.
25 class DriveMetricsProvider
: public metrics::MetricsProvider
{
27 DriveMetricsProvider();
28 ~DriveMetricsProvider() override
;
30 // metrics::MetricsDataProvider:
31 void ProvideSystemProfileMetrics(
32 metrics::SystemProfileProto
* system_profile_proto
) override
;
34 // Called by ChromeMetricsServiceClient to start gathering metrics.
35 void GetDriveMetrics(const base::Closure
& done
);
38 FRIEND_TEST_ALL_PREFIXES(DriveMetricsProviderTest
, HasSeekPenalty
);
40 // A response to querying a drive as to whether it incurs a seek penalty.
41 // |has_seek_penalty| is set if |success| is true.
42 struct SeekPenaltyResponse
{
43 SeekPenaltyResponse();
45 bool has_seek_penalty
;
49 SeekPenaltyResponse app_drive
;
50 SeekPenaltyResponse user_data_drive
;
53 // 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).
55 static bool HasSeekPenalty(const base::FilePath
& path
,
56 bool* has_seek_penalty
);
58 // Gather metrics about various drives on the FILE thread.
59 static DriveMetrics
GetDriveMetricsOnFileThread();
61 // 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").
63 static void QuerySeekPenalty(int path_service_key
,
64 SeekPenaltyResponse
* response
);
66 // Called when metrics are done being gathered from the FILE thread.
67 void GotDriveMetrics(const DriveMetrics
& metrics
);
69 // Fills |drive| with information from successful |response|s.
70 void FillDriveMetrics(
71 const SeekPenaltyResponse
& response
,
72 metrics::SystemProfileProto::Hardware::Drive
* drive
);
74 // Information gathered about various important drives.
75 DriveMetrics metrics_
;
77 // Called when metrics are done being collected.
78 base::Closure got_metrics_callback_
;
80 base::ThreadChecker thread_checker_
;
81 base::WeakPtrFactory
<DriveMetricsProvider
> weak_ptr_factory_
;
83 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider
);
86 #endif // CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_