Index: chrome/browser/metrics/drive_metrics_provider.cc |
diff --git a/chrome/browser/metrics/drive_metrics_provider.cc b/chrome/browser/metrics/drive_metrics_provider.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9e460e28cb3794f99dbad6316ad94607d797cc84 |
--- /dev/null |
+++ b/chrome/browser/metrics/drive_metrics_provider.cc |
@@ -0,0 +1,77 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/metrics/drive_metrics_provider.h" |
+ |
+#include "base/base_paths.h" |
+#include "base/bind.h" |
+#include "base/files/file_path.h" |
+#include "base/location.h" |
+#include "base/logging.h" |
+#include "base/path_service.h" |
+#include "base/sys_info.h" |
+#include "chrome/common/chrome_paths.h" |
+#include "components/metrics/proto/system_profile.pb.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+namespace { |
+ |
+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.
|
+ DriveMetricsProvider::SeekPenaltyResponse* resp) { |
+ DCHECK(resp); |
+ |
+ base::FilePath path; |
+ if (!PathService::Get(path_service_key, &path)) |
+ return; |
+ |
+ 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.
|
+} |
+ |
+DriveMetricsProvider::DriveMetrics GetDriveMetrics() { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
+ |
+ DriveMetricsProvider::DriveMetrics metrics; |
+ TestSeekPenalty(base::FILE_EXE, &metrics.app_drive); |
+ TestSeekPenalty(chrome::FILE_LOCAL_STATE, &metrics.user_data_drive); |
+ return metrics; |
+} |
+ |
+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)
|
+ 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.
|
+ if (resp.success) |
+ drive->set_has_seek_penalty(resp.has_seek_penalty); |
+} |
+ |
+} // namespace |
+ |
+DriveMetricsProvider::DriveMetricsProvider() |
+ : got_metrics_(false), weak_ptr_factory_(this) {} |
+ |
+DriveMetricsProvider::~DriveMetricsProvider() {} |
+ |
+void DriveMetricsProvider::ProvideSystemProfileMetrics( |
+ metrics::SystemProfileProto* system_profile_proto) { |
+ 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)
|
+ content::BrowserThread::PostTaskAndReplyWithResult( |
+ content::BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&GetDriveMetrics), |
+ base::Bind(&DriveMetricsProvider::GotDriveMetrics, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ return; |
+ } |
+ |
+ auto* hardware = system_profile_proto->mutable_hardware(); |
+ FillDriveMetrics(hardware->mutable_app_drive(), metrics_.app_drive); |
+ FillDriveMetrics(hardware->mutable_user_data_drive(), |
+ metrics_.user_data_drive); |
+} |
+ |
+DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse() |
+ : success(false) {} |
+ |
+void DriveMetricsProvider::GotDriveMetrics(const DriveMetrics& metrics) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ got_metrics_ = true; |
+ metrics_ = metrics; |
+} |