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 "chrome/browser/metrics/drive_metrics_provider.h"
7 #include "base/base_paths.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/time/time.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "content/public/browser/browser_thread.h"
18 DriveMetricsProvider::DriveMetricsProvider() : weak_ptr_factory_(this) {}
20 DriveMetricsProvider::~DriveMetricsProvider() {}
22 void DriveMetricsProvider::ProvideSystemProfileMetrics(
23 metrics::SystemProfileProto
* system_profile_proto
) {
24 auto* hardware
= system_profile_proto
->mutable_hardware();
25 FillDriveMetrics(metrics_
.app_drive
, hardware
->mutable_app_drive());
26 FillDriveMetrics(metrics_
.user_data_drive
,
27 hardware
->mutable_user_data_drive());
30 void DriveMetricsProvider::GetDriveMetrics(const base::Closure
& done
) {
31 got_metrics_callback_
= done
;
33 content::BrowserThread::PostTaskAndReplyWithResult(
34 content::BrowserThread::FILE, FROM_HERE
,
35 base::Bind(&DriveMetricsProvider::GetDriveMetricsOnFileThread
),
36 base::Bind(&DriveMetricsProvider::GotDriveMetrics
,
37 weak_ptr_factory_
.GetWeakPtr()));
40 DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse()
44 DriveMetricsProvider::DriveMetrics
45 DriveMetricsProvider::GetDriveMetricsOnFileThread() {
46 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
48 DriveMetricsProvider::DriveMetrics metrics
;
49 QuerySeekPenalty(base::FILE_EXE
, &metrics
.app_drive
);
50 QuerySeekPenalty(chrome::FILE_LOCAL_STATE
, &metrics
.user_data_drive
);
55 void DriveMetricsProvider::QuerySeekPenalty(
57 DriveMetricsProvider::SeekPenaltyResponse
* response
) {
61 if (!PathService::Get(path_service_key
, &path
))
64 base::TimeTicks start
= base::TimeTicks::Now();
66 response
->success
= HasSeekPenalty(path
, &response
->has_seek_penalty
);
68 UMA_HISTOGRAM_TIMES("Hardware.Drive.HasSeekPenalty_Time",
69 base::TimeTicks::Now() - start
);
70 UMA_HISTOGRAM_BOOLEAN("Hardware.Drive.HasSeekPenalty_Success",
72 if (response
->success
) {
73 UMA_HISTOGRAM_BOOLEAN("Hardware.Drive.HasSeekPenalty",
74 response
->has_seek_penalty
);
78 void DriveMetricsProvider::GotDriveMetrics(
79 const DriveMetricsProvider::DriveMetrics
& metrics
) {
80 DCHECK(thread_checker_
.CalledOnValidThread());
82 got_metrics_callback_
.Run();
85 void DriveMetricsProvider::FillDriveMetrics(
86 const DriveMetricsProvider::SeekPenaltyResponse
& response
,
87 metrics::SystemProfileProto::Hardware::Drive
* drive
) {
89 drive
->set_has_seek_penalty(response
.has_seek_penalty
);