Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / components / metrics / drive_metrics_provider.h
blobcab799d40ea1a85f5ee2160e67b6cb98e4bb0cc5
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_forward.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_callback);
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 // |done_callback| is the callback that should be called once all metrics are
73 // gathered.
74 void GotDriveMetrics(const base::Closure& done_callback,
75 const DriveMetrics& metrics);
77 // Fills |drive| with information from successful |response|s.
78 void FillDriveMetrics(const SeekPenaltyResponse& response,
79 metrics::SystemProfileProto::Hardware::Drive* drive);
81 // The thread on which file operations are performed (supplied by the
82 // embedder).
83 scoped_refptr<base::SequencedTaskRunner> file_thread_;
85 // The key to give to base::PathService to obtain the path to local state
86 // (supplied by the embedder).
87 int local_state_path_key_;
89 // Information gathered about various important drives.
90 DriveMetrics metrics_;
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_