Chromium Code Reviews| Index: chrome/browser/metrics/disk_metrics_provider.cc |
| diff --git a/chrome/browser/metrics/disk_metrics_provider.cc b/chrome/browser/metrics/disk_metrics_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..668bc62185af33a388fb9c7c9d02d23c46b00e80 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/disk_metrics_provider.cc |
| @@ -0,0 +1,68 @@ |
| +// 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/disk_metrics_provider.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 { |
| + |
| +DiskMetrics GetDiskMetrics() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| + |
| + DiskMetrics metrics; |
| + |
| + base::FilePath app_dir; |
| + if (PathService::Get(chrome::DIR_APP, &app_dir)) { |
| + metrics.app_disk.success = base::SysInfo::HasSeekPenalty( |
| + app_dir, &metrics.app_disk.has_seek_penalty); |
| + } |
| + |
| + base::FilePath user_data_dir; |
| + if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { |
| + metrics.user_data_disk.success = base::SysInfo::HasSeekPenalty( |
| + user_data_dir, &metrics.user_data_disk.has_seek_penalty); |
| + } |
| + |
| + return metrics; |
| +} |
| + |
| +} // namespace |
| + |
| +DiskMetricsProvider::DiskMetricsProvider() : weak_ptr_factory_(this) { |
| + content::BrowserThread::PostTaskAndReplyWithResult( |
| + content::BrowserThread::FILE, FROM_HERE, |
|
Alexei Svitkine (slow)
2015/03/12 16:41:06
Any reason to use FILE thread explicitly rather th
Dan Beam
2015/03/13 19:31:32
can't be in components/ AFAIU because it depends o
|
| + base::Bind(&GetDiskMetrics), |
| + base::Bind(&DiskMetricsProvider::GotDiskMetrics, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +DiskMetricsProvider::~DiskMetricsProvider() {} |
| + |
| +void DiskMetricsProvider::ProvideSystemProfileMetrics( |
| + metrics::SystemProfileProto* system_profile_proto) { |
| + if (metrics_.app_disk.success) { |
|
Alexei Svitkine (slow)
2015/03/12 16:41:06
Nit: You can make a helper that takes metrics_.app
Dan Beam
2015/03/13 19:31:32
Done.
|
| + system_profile_proto->mutable_hardware()->mutable_app_disk()-> |
| + set_has_seek_penalty(metrics_.app_disk.has_seek_penalty); |
| + } |
| + if (metrics_.user_data_disk.success) { |
| + system_profile_proto->mutable_hardware()->mutable_user_data_disk()-> |
| + set_has_seek_penalty(metrics_.user_data_disk.has_seek_penalty); |
| + } |
| +} |
| + |
| +SeekPenaltyResponse::SeekPenaltyResponse() : success(false) {} |
| + |
| +void DiskMetricsProvider::GotDiskMetrics(const DiskMetrics& metrics) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + metrics_ = metrics; |
| +} |