Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / metrics / drive_metrics_provider.cc
blob2df320d3bb9c1ef30c17439138c8f8d5d5fdcb3f
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 #include "components/metrics/drive_metrics_provider.h"
7 #include "base/base_paths.h"
8 #include "base/bind.h"
9 #include "base/files/file_path.h"
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "base/metrics/histogram_macros.h"
13 #include "base/path_service.h"
14 #include "base/task_runner_util.h"
15 #include "base/time/time.h"
17 namespace metrics {
19 DriveMetricsProvider::DriveMetricsProvider(
20 scoped_refptr<base::SequencedTaskRunner> file_thread,
21 int local_state_path_key)
22 : file_thread_(file_thread),
23 local_state_path_key_(local_state_path_key),
24 weak_ptr_factory_(this) {}
26 DriveMetricsProvider::~DriveMetricsProvider() {}
28 void DriveMetricsProvider::ProvideSystemProfileMetrics(
29 metrics::SystemProfileProto* system_profile_proto) {
30 auto* hardware = system_profile_proto->mutable_hardware();
31 FillDriveMetrics(metrics_.app_drive, hardware->mutable_app_drive());
32 FillDriveMetrics(metrics_.user_data_drive,
33 hardware->mutable_user_data_drive());
36 void DriveMetricsProvider::GetDriveMetrics(const base::Closure& done) {
37 got_metrics_callback_ = done;
39 base::PostTaskAndReplyWithResult(
40 file_thread_.get(), FROM_HERE,
41 base::Bind(&DriveMetricsProvider::GetDriveMetricsOnFileThread,
42 local_state_path_key_),
43 base::Bind(&DriveMetricsProvider::GotDriveMetrics,
44 weak_ptr_factory_.GetWeakPtr()));
47 DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse()
48 : success(false) {}
50 // static
51 DriveMetricsProvider::DriveMetrics
52 DriveMetricsProvider::GetDriveMetricsOnFileThread(int local_state_path_key) {
53 DriveMetricsProvider::DriveMetrics metrics;
54 QuerySeekPenalty(base::FILE_EXE, &metrics.app_drive);
55 QuerySeekPenalty(local_state_path_key, &metrics.user_data_drive);
56 return metrics;
59 // static
60 void DriveMetricsProvider::QuerySeekPenalty(
61 int path_service_key,
62 DriveMetricsProvider::SeekPenaltyResponse* response) {
63 DCHECK(response);
65 base::FilePath path;
66 if (!PathService::Get(path_service_key, &path))
67 return;
69 base::TimeTicks start = base::TimeTicks::Now();
71 response->success = HasSeekPenalty(path, &response->has_seek_penalty);
73 UMA_HISTOGRAM_TIMES("Hardware.Drive.HasSeekPenalty_Time",
74 base::TimeTicks::Now() - start);
75 UMA_HISTOGRAM_BOOLEAN("Hardware.Drive.HasSeekPenalty_Success",
76 response->success);
77 if (response->success) {
78 UMA_HISTOGRAM_BOOLEAN("Hardware.Drive.HasSeekPenalty",
79 response->has_seek_penalty);
83 void DriveMetricsProvider::GotDriveMetrics(
84 const DriveMetricsProvider::DriveMetrics& metrics) {
85 DCHECK(thread_checker_.CalledOnValidThread());
86 metrics_ = metrics;
87 got_metrics_callback_.Run();
90 void DriveMetricsProvider::FillDriveMetrics(
91 const DriveMetricsProvider::SeekPenaltyResponse& response,
92 metrics::SystemProfileProto::Hardware::Drive* drive) {
93 if (response.success)
94 drive->set_has_seek_penalty(response.has_seek_penalty);
97 } // namespace metrics