Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "components/metrics/proto/system_profile.pb.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 void TestSeekPenalty(int path_service_key, | |
|
Alexei Svitkine (slow)
2015/03/16 16:49:36
Nit: Test* can be confusing when it doesn't relate
Dan Beam
2015/03/16 19:20:23
Done.
| |
| 21 DriveMetricsProvider::SeekPenaltyResponse* resp) { | |
| 22 DCHECK(resp); | |
| 23 | |
| 24 base::FilePath path; | |
| 25 if (!PathService::Get(path_service_key, &path)) | |
| 26 return; | |
| 27 | |
| 28 resp->success = base::SysInfo::HasSeekPenalty(path, &resp->has_seek_penalty); | |
|
Alexei Svitkine (slow)
2015/03/16 16:49:36
Nit: resp -> response or result.
Dan Beam
2015/03/16 19:20:23
Done.
| |
| 29 } | |
| 30 | |
| 31 DriveMetricsProvider::DriveMetrics GetDriveMetrics() { | |
| 32 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | |
| 33 | |
| 34 DriveMetricsProvider::DriveMetrics metrics; | |
| 35 TestSeekPenalty(base::FILE_EXE, &metrics.app_drive); | |
| 36 TestSeekPenalty(chrome::FILE_LOCAL_STATE, &metrics.user_data_drive); | |
| 37 return metrics; | |
| 38 } | |
| 39 | |
| 40 void FillDriveMetrics(metrics::SystemProfileProto::Hardware::Drive* drive, | |
|
Alexei Svitkine (slow)
2015/03/16 16:49:36
Please add a short comment above each of the metho
Dan Beam
2015/03/16 19:20:23
Done. (in the .h)
| |
| 41 const DriveMetricsProvider::SeekPenaltyResponse& resp) { | |
|
Alexei Svitkine (slow)
2015/03/16 16:49:36
Nit: Const arguments should come before non-const
Dan Beam
2015/03/16 19:20:23
Done.
| |
| 42 if (resp.success) | |
| 43 drive->set_has_seek_penalty(resp.has_seek_penalty); | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 DriveMetricsProvider::DriveMetricsProvider() | |
| 49 : got_metrics_(false), weak_ptr_factory_(this) {} | |
| 50 | |
| 51 DriveMetricsProvider::~DriveMetricsProvider() {} | |
| 52 | |
| 53 void DriveMetricsProvider::ProvideSystemProfileMetrics( | |
| 54 metrics::SystemProfileProto* system_profile_proto) { | |
| 55 if (!got_metrics_) { | |
|
Alexei Svitkine (slow)
2015/03/16 16:49:36
This will make it so the first log will not have t
Dan Beam
2015/03/16 19:20:23
rvargas@ mentioned we should gather these metrics
Alexei Svitkine (slow)
2015/03/16 19:29:07
I think it would be terribly confusing if some UMA
Dan Beam
2015/03/16 22:25:01
Done. (see updated code)
| |
| 56 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 57 content::BrowserThread::FILE, FROM_HERE, | |
| 58 base::Bind(&GetDriveMetrics), | |
| 59 base::Bind(&DriveMetricsProvider::GotDriveMetrics, | |
| 60 weak_ptr_factory_.GetWeakPtr())); | |
| 61 return; | |
| 62 } | |
| 63 | |
| 64 auto* hardware = system_profile_proto->mutable_hardware(); | |
| 65 FillDriveMetrics(hardware->mutable_app_drive(), metrics_.app_drive); | |
| 66 FillDriveMetrics(hardware->mutable_user_data_drive(), | |
| 67 metrics_.user_data_drive); | |
| 68 } | |
| 69 | |
| 70 DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse() | |
| 71 : success(false) {} | |
| 72 | |
| 73 void DriveMetricsProvider::GotDriveMetrics(const DriveMetrics& metrics) { | |
| 74 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 75 got_metrics_ = true; | |
| 76 metrics_ = metrics; | |
| 77 } | |
| OLD | NEW |