Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/browser/metrics/drive_metrics_provider.cc

Issue 999623002: metrics/base: log whether drives have seek penalties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: asvitkine@ review Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/metrics/drive_metrics_provider.h"
6
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/path_service.h"
13 #include "base/sys_info.h"
14 #include "chrome/common/chrome_paths.h"
15 #include "content/public/browser/browser_thread.h"
16
17 DriveMetricsProvider::DriveMetricsProvider()
18 : got_metrics_(false), weak_ptr_factory_(this) {}
19
20 DriveMetricsProvider::~DriveMetricsProvider() {}
21
22 void DriveMetricsProvider::ProvideSystemProfileMetrics(
23 metrics::SystemProfileProto* system_profile_proto) {
24 if (!got_metrics_) {
25 content::BrowserThread::PostTaskAndReplyWithResult(
26 content::BrowserThread::FILE, FROM_HERE,
27 base::Bind(&DriveMetricsProvider::GetDriveMetrics),
Dan Beam 2015/03/16 19:20:24 this does work
28 base::Bind(&DriveMetricsProvider::GotDriveMetrics,
29 weak_ptr_factory_.GetWeakPtr()));
30 return;
31 }
32
33 auto* hardware = system_profile_proto->mutable_hardware();
34 FillDriveMetrics(metrics_.app_drive, hardware->mutable_app_drive());
35 FillDriveMetrics(metrics_.user_data_drive,
36 hardware->mutable_user_data_drive());
37 }
38
39 DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse()
40 : success(false) {}
41
42 // static
43 DriveMetricsProvider::DriveMetrics DriveMetricsProvider::GetDriveMetrics() {
44 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
45
46 DriveMetricsProvider::DriveMetrics metrics;
47 QuerySeekPenalty(base::FILE_EXE, &metrics.app_drive);
48 QuerySeekPenalty(chrome::FILE_LOCAL_STATE, &metrics.user_data_drive);
49 return metrics;
50 }
51
52 // static
53 void DriveMetricsProvider::QuerySeekPenalty(
54 int path_service_key,
55 DriveMetricsProvider::SeekPenaltyResponse* response) {
56 DCHECK(response);
57
58 base::FilePath path;
59 if (!PathService::Get(path_service_key, &path))
60 return;
61
62 response->success =
63 base::SysInfo::HasSeekPenalty(path, &response->has_seek_penalty);
64 }
65
66 void DriveMetricsProvider::GotDriveMetrics(
67 const DriveMetricsProvider::DriveMetrics& metrics) {
68 DCHECK(thread_checker_.CalledOnValidThread());
69 got_metrics_ = true;
70 metrics_ = metrics;
71 }
72
73 void DriveMetricsProvider::FillDriveMetrics(
74 const DriveMetricsProvider::SeekPenaltyResponse& response,
75 metrics::SystemProfileProto::Hardware::Drive* drive) {
76 if (response.success)
77 drive->set_has_seek_penalty(response.has_seek_penalty);
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698