Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / metrics / drive_metrics_provider.cc
blob50c6270e6f4bb1fc2f9c420f18b631cf82bc1829
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"
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/sys_info.h"
15 #include "base/time/time.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "content/public/browser/browser_thread.h"
19 DriveMetricsProvider::DriveMetricsProvider() : weak_ptr_factory_(this) {}
21 DriveMetricsProvider::~DriveMetricsProvider() {}
23 void DriveMetricsProvider::ProvideSystemProfileMetrics(
24 metrics::SystemProfileProto* system_profile_proto) {
25 auto* hardware = system_profile_proto->mutable_hardware();
26 FillDriveMetrics(metrics_.app_drive, hardware->mutable_app_drive());
27 FillDriveMetrics(metrics_.user_data_drive,
28 hardware->mutable_user_data_drive());
31 void DriveMetricsProvider::GetDriveMetrics(const base::Closure& done) {
32 got_metrics_callback_ = done;
34 content::BrowserThread::PostTaskAndReplyWithResult(
35 content::BrowserThread::FILE, FROM_HERE,
36 base::Bind(&DriveMetricsProvider::GetDriveMetricsOnFileThread),
37 base::Bind(&DriveMetricsProvider::GotDriveMetrics,
38 weak_ptr_factory_.GetWeakPtr()));
41 DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse()
42 : success(false) {}
44 // static
45 DriveMetricsProvider::DriveMetrics
46 DriveMetricsProvider::GetDriveMetricsOnFileThread() {
47 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
49 DriveMetricsProvider::DriveMetrics metrics;
50 QuerySeekPenalty(base::FILE_EXE, &metrics.app_drive);
51 QuerySeekPenalty(chrome::FILE_LOCAL_STATE, &metrics.user_data_drive);
52 return metrics;
55 // static
56 void DriveMetricsProvider::QuerySeekPenalty(
57 int path_service_key,
58 DriveMetricsProvider::SeekPenaltyResponse* response) {
59 DCHECK(response);
61 base::FilePath path;
62 if (!PathService::Get(path_service_key, &path))
63 return;
65 base::TimeTicks start = base::TimeTicks::Now();
67 response->success =
68 base::SysInfo::HasSeekPenalty(path, &response->has_seek_penalty);
70 UMA_HISTOGRAM_TIMES("Hardware.Drive.HasSeekPenalty_Time",
71 base::TimeTicks::Now() - start);
72 UMA_HISTOGRAM_BOOLEAN("Hardware.Drive.HasSeekPenalty_Success",
73 response->success);
74 if (response->success) {
75 UMA_HISTOGRAM_BOOLEAN("Hardware.Drive.HasSeekPenalty",
76 response->has_seek_penalty);
80 void DriveMetricsProvider::GotDriveMetrics(
81 const DriveMetricsProvider::DriveMetrics& metrics) {
82 DCHECK(thread_checker_.CalledOnValidThread());
83 metrics_ = metrics;
84 got_metrics_callback_.Run();
87 void DriveMetricsProvider::FillDriveMetrics(
88 const DriveMetricsProvider::SeekPenaltyResponse& response,
89 metrics::SystemProfileProto::Hardware::Drive* drive) {
90 if (response.success)
91 drive->set_has_seek_penalty(response.has_seek_penalty);