Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / metrics / drive_metrics_provider.h
blobf936d98238d9c5f4e85bcae964b98782c3f098db
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 COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_
6 #define COMPONENTS_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/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/sequenced_task_runner.h"
14 #include "base/threading/thread_checker.h"
15 #include "components/metrics/metrics_provider.h"
16 #include "components/metrics/proto/system_profile.pb.h"
18 namespace base {
19 class FilePath;
22 namespace metrics {
24 // Provides metrics about the local drives on a user's computer. Currently only
25 // checks to see if they incur a seek-time penalty (e.g. if they're SSDs).
27 // Defers gathering metrics until after "rush hour" (startup) so as to not bog
28 // down the file thread.
29 class DriveMetricsProvider : public metrics::MetricsProvider {
30 public:
31 DriveMetricsProvider(scoped_refptr<base::SequencedTaskRunner> file_thread,
32 int local_state_path_key);
33 ~DriveMetricsProvider() override;
35 // metrics::MetricsDataProvider:
36 void ProvideSystemProfileMetrics(
37 metrics::SystemProfileProto* system_profile_proto) override;
39 // Called to start gathering metrics.
40 void GetDriveMetrics(const base::Closure& done);
42 private:
43 FRIEND_TEST_ALL_PREFIXES(DriveMetricsProviderTest, HasSeekPenalty);
45 // A response to querying a drive as to whether it incurs a seek penalty.
46 // |has_seek_penalty| is set if |success| is true.
47 struct SeekPenaltyResponse {
48 SeekPenaltyResponse();
49 bool success;
50 bool has_seek_penalty;
53 struct DriveMetrics {
54 SeekPenaltyResponse app_drive;
55 SeekPenaltyResponse user_data_drive;
58 // Determine whether the device that services |path| has a seek penalty.
59 // Returns false if it couldn't be determined (e.g., |path| doesn't exist).
60 static bool HasSeekPenalty(const base::FilePath& path,
61 bool* has_seek_penalty);
63 // Gather metrics about various drives on |file_thread_|.
64 static DriveMetrics GetDriveMetricsOnFileThread(int local_state_path_key);
66 // Tries to determine whether there is a penalty for seeking on the drive that
67 // hosts |path_service_key| (for example: the drive that holds "Local State").
68 static void QuerySeekPenalty(int path_service_key,
69 SeekPenaltyResponse* response);
71 // Called when metrics are done being gathered from the FILE thread.
72 void GotDriveMetrics(const DriveMetrics& metrics);
74 // Fills |drive| with information from successful |response|s.
75 void FillDriveMetrics(const SeekPenaltyResponse& response,
76 metrics::SystemProfileProto::Hardware::Drive* drive);
78 // The thread on which file operations are performed (supplied by the
79 // embedder).
80 scoped_refptr<base::SequencedTaskRunner> file_thread_;
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_;
86 // Information gathered about various important drives.
87 DriveMetrics metrics_;
89 // Called when metrics are done being collected.
90 base::Closure got_metrics_callback_;
92 base::ThreadChecker thread_checker_;
93 base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_;
95 DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider);
98 } // namespace metrics
100 #endif // COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_