summaryrefslogtreecommitdiffstats
path: root/chrome/browser/metrics
diff options
context:
space:
mode:
authorblundell <blundell@chromium.org>2015-07-30 13:18:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-30 20:19:42 +0000
commitb5c6b5a18863e2e9094b5bb3328edab690fa7111 (patch)
tree0c36eec1009b7a9ab601ebcf91c4590058f4e775 /chrome/browser/metrics
parent34960e7a547930177cc05020921b7ee3eec4fd39 (diff)
downloadchromium_src-b5c6b5a18863e2e9094b5bb3328edab690fa7111.zip
chromium_src-b5c6b5a18863e2e9094b5bb3328edab690fa7111.tar.gz
chromium_src-b5c6b5a18863e2e9094b5bb3328edab690fa7111.tar.bz2
Componentize DriveMetricsProvider*
This metrics provider is used on iOS, so to enable clean integration on iOS this CL componentizes it and injects its //chrome-level dependencies from the embedder. BUG=512426 Review URL: https://codereview.chromium.org/1254983003 Cr-Commit-Position: refs/heads/master@{#341183}
Diffstat (limited to 'chrome/browser/metrics')
-rw-r--r--chrome/browser/metrics/chrome_metrics_service_client.cc8
-rw-r--r--chrome/browser/metrics/chrome_metrics_service_client.h4
-rw-r--r--chrome/browser/metrics/drive_metrics_provider.cc90
-rw-r--r--chrome/browser/metrics/drive_metrics_provider.h86
-rw-r--r--chrome/browser/metrics/drive_metrics_provider_android.cc12
-rw-r--r--chrome/browser/metrics/drive_metrics_provider_ios.mm12
-rw-r--r--chrome/browser/metrics/drive_metrics_provider_linux.cc60
-rw-r--r--chrome/browser/metrics/drive_metrics_provider_mac.mm74
-rw-r--r--chrome/browser/metrics/drive_metrics_provider_unittest.cc16
-rw-r--r--chrome/browser/metrics/drive_metrics_provider_win.cc90
10 files changed, 8 insertions, 444 deletions
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.cc b/chrome/browser/metrics/chrome_metrics_service_client.cc
index e77d03c..ae947c3 100644
--- a/chrome/browser/metrics/chrome_metrics_service_client.cc
+++ b/chrome/browser/metrics/chrome_metrics_service_client.cc
@@ -20,17 +20,18 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/google/google_brand.h"
#include "chrome/browser/metrics/chrome_stability_metrics_provider.h"
-#include "chrome/browser/metrics/drive_metrics_provider.h"
#include "chrome/browser/metrics/omnibox_metrics_provider.h"
#include "chrome/browser/metrics/time_ticks_experiment_win.h"
#include "chrome/browser/process_resource_usage.h"
#include "chrome/browser/ui/browser_otr_state.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/crash_keys.h"
#include "chrome/common/metrics/version_utils.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/call_stack_profile_metrics_provider.h"
+#include "components/metrics/drive_metrics_provider.h"
#include "components/metrics/gpu/gpu_metrics_provider.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics/net/net_metrics_log_uploader.h"
@@ -350,7 +351,10 @@ void ChromeMetricsServiceClient::Initialize() {
metrics_service_->RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new metrics::GPUMetricsProvider));
- drive_metrics_provider_ = new DriveMetricsProvider;
+ drive_metrics_provider_ = new metrics::DriveMetricsProvider(
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::FILE),
+ chrome::FILE_LOCAL_STATE);
metrics_service_->RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(drive_metrics_provider_));
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.h b/chrome/browser/metrics/chrome_metrics_service_client.h
index d4fe09c..ee879a5 100644
--- a/chrome/browser/metrics/chrome_metrics_service_client.h
+++ b/chrome/browser/metrics/chrome_metrics_service_client.h
@@ -20,7 +20,6 @@
#include "content/public/browser/notification_registrar.h"
class ChromeOSMetricsProvider;
-class DriveMetricsProvider;
class GoogleUpdateMetricsProviderWin;
class PluginMetricsProvider;
class PrefRegistrySimple;
@@ -36,6 +35,7 @@ class FilePath;
} // namespace base
namespace metrics {
+class DriveMetricsProvider;
class MetricsService;
class MetricsStateManager;
class ProfilerMetricsProvider;
@@ -174,7 +174,7 @@ class ChromeMetricsServiceClient
// The DriveMetricsProvider instance that was registered with MetricsService.
// Has the same lifetime as |metrics_service_|.
- DriveMetricsProvider* drive_metrics_provider_;
+ metrics::DriveMetricsProvider* drive_metrics_provider_;
// Callback that is called when initial metrics gathering is complete.
base::Closure finished_gathering_initial_metrics_callback_;
diff --git a/chrome/browser/metrics/drive_metrics_provider.cc b/chrome/browser/metrics/drive_metrics_provider.cc
deleted file mode 100644
index 4b88849..0000000
--- a/chrome/browser/metrics/drive_metrics_provider.cc
+++ /dev/null
@@ -1,90 +0,0 @@
-// 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/metrics/histogram_macros.h"
-#include "base/path_service.h"
-#include "base/time/time.h"
-#include "chrome/common/chrome_paths.h"
-#include "content/public/browser/browser_thread.h"
-
-DriveMetricsProvider::DriveMetricsProvider() : weak_ptr_factory_(this) {}
-
-DriveMetricsProvider::~DriveMetricsProvider() {}
-
-void DriveMetricsProvider::ProvideSystemProfileMetrics(
- metrics::SystemProfileProto* system_profile_proto) {
- auto* hardware = system_profile_proto->mutable_hardware();
- FillDriveMetrics(metrics_.app_drive, hardware->mutable_app_drive());
- FillDriveMetrics(metrics_.user_data_drive,
- hardware->mutable_user_data_drive());
-}
-
-void DriveMetricsProvider::GetDriveMetrics(const base::Closure& done) {
- got_metrics_callback_ = done;
-
- content::BrowserThread::PostTaskAndReplyWithResult(
- content::BrowserThread::FILE, FROM_HERE,
- base::Bind(&DriveMetricsProvider::GetDriveMetricsOnFileThread),
- base::Bind(&DriveMetricsProvider::GotDriveMetrics,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse()
- : success(false) {}
-
-// static
-DriveMetricsProvider::DriveMetrics
-DriveMetricsProvider::GetDriveMetricsOnFileThread() {
- DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
-
- DriveMetricsProvider::DriveMetrics metrics;
- QuerySeekPenalty(base::FILE_EXE, &metrics.app_drive);
- QuerySeekPenalty(chrome::FILE_LOCAL_STATE, &metrics.user_data_drive);
- return metrics;
-}
-
-// static
-void DriveMetricsProvider::QuerySeekPenalty(
- int path_service_key,
- DriveMetricsProvider::SeekPenaltyResponse* response) {
- DCHECK(response);
-
- base::FilePath path;
- if (!PathService::Get(path_service_key, &path))
- return;
-
- base::TimeTicks start = base::TimeTicks::Now();
-
- response->success = HasSeekPenalty(path, &response->has_seek_penalty);
-
- UMA_HISTOGRAM_TIMES("Hardware.Drive.HasSeekPenalty_Time",
- base::TimeTicks::Now() - start);
- UMA_HISTOGRAM_BOOLEAN("Hardware.Drive.HasSeekPenalty_Success",
- response->success);
- if (response->success) {
- UMA_HISTOGRAM_BOOLEAN("Hardware.Drive.HasSeekPenalty",
- response->has_seek_penalty);
- }
-}
-
-void DriveMetricsProvider::GotDriveMetrics(
- const DriveMetricsProvider::DriveMetrics& metrics) {
- DCHECK(thread_checker_.CalledOnValidThread());
- metrics_ = metrics;
- got_metrics_callback_.Run();
-}
-
-void DriveMetricsProvider::FillDriveMetrics(
- const DriveMetricsProvider::SeekPenaltyResponse& response,
- metrics::SystemProfileProto::Hardware::Drive* drive) {
- if (response.success)
- drive->set_has_seek_penalty(response.has_seek_penalty);
-}
diff --git a/chrome/browser/metrics/drive_metrics_provider.h b/chrome/browser/metrics/drive_metrics_provider.h
deleted file mode 100644
index 6ddccec..0000000
--- a/chrome/browser/metrics/drive_metrics_provider.h
+++ /dev/null
@@ -1,86 +0,0 @@
-// 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.
-
-#ifndef CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_
-#define CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_
-
-#include "base/callback.h"
-#include "base/gtest_prod_util.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "base/threading/thread_checker.h"
-#include "components/metrics/metrics_provider.h"
-#include "components/metrics/proto/system_profile.pb.h"
-
-namespace base {
-class FilePath;
-}
-
-// Provides metrics about the local drives on a user's computer. Currently only
-// checks to see if they incur a seek-time penalty (e.g. if they're SSDs).
-//
-// Defers gathering metrics until after "rush hour" (startup) so as to not bog
-// down the FILE thread.
-class DriveMetricsProvider : public metrics::MetricsProvider {
- public:
- DriveMetricsProvider();
- ~DriveMetricsProvider() override;
-
- // metrics::MetricsDataProvider:
- void ProvideSystemProfileMetrics(
- metrics::SystemProfileProto* system_profile_proto) override;
-
- // Called by ChromeMetricsServiceClient to start gathering metrics.
- void GetDriveMetrics(const base::Closure& done);
-
- private:
- FRIEND_TEST_ALL_PREFIXES(DriveMetricsProviderTest, HasSeekPenalty);
-
- // A response to querying a drive as to whether it incurs a seek penalty.
- // |has_seek_penalty| is set if |success| is true.
- struct SeekPenaltyResponse {
- SeekPenaltyResponse();
- bool success;
- bool has_seek_penalty;
- };
-
- struct DriveMetrics {
- SeekPenaltyResponse app_drive;
- SeekPenaltyResponse user_data_drive;
- };
-
- // Determine whether the device that services |path| has a seek penalty.
- // Returns false if it couldn't be determined (e.g., |path| doesn't exist).
- static bool HasSeekPenalty(const base::FilePath& path,
- bool* has_seek_penalty);
-
- // Gather metrics about various drives on the FILE thread.
- static DriveMetrics GetDriveMetricsOnFileThread();
-
- // Tries to determine whether there is a penalty for seeking on the drive that
- // hosts |path_service_key| (for example: the drive that holds "Local State").
- static void QuerySeekPenalty(int path_service_key,
- SeekPenaltyResponse* response);
-
- // Called when metrics are done being gathered from the FILE thread.
- void GotDriveMetrics(const DriveMetrics& metrics);
-
- // Fills |drive| with information from successful |response|s.
- void FillDriveMetrics(
- const SeekPenaltyResponse& response,
- metrics::SystemProfileProto::Hardware::Drive* drive);
-
- // Information gathered about various important drives.
- DriveMetrics metrics_;
-
- // Called when metrics are done being collected.
- base::Closure got_metrics_callback_;
-
- base::ThreadChecker thread_checker_;
- base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(DriveMetricsProvider);
-};
-
-#endif // CHROME_BROWSER_METRICS_DRIVE_METRICS_PROVIDER_H_
diff --git a/chrome/browser/metrics/drive_metrics_provider_android.cc b/chrome/browser/metrics/drive_metrics_provider_android.cc
deleted file mode 100644
index beb9e8c..0000000
--- a/chrome/browser/metrics/drive_metrics_provider_android.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-// 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"
-
-// static
-bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
- bool* has_seek_penalty) {
- *has_seek_penalty = false;
- return true;
-}
diff --git a/chrome/browser/metrics/drive_metrics_provider_ios.mm b/chrome/browser/metrics/drive_metrics_provider_ios.mm
deleted file mode 100644
index beb9e8c..0000000
--- a/chrome/browser/metrics/drive_metrics_provider_ios.mm
+++ /dev/null
@@ -1,12 +0,0 @@
-// 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"
-
-// static
-bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
- bool* has_seek_penalty) {
- *has_seek_penalty = false;
- return true;
-}
diff --git a/chrome/browser/metrics/drive_metrics_provider_linux.cc b/chrome/browser/metrics/drive_metrics_provider_linux.cc
deleted file mode 100644
index 93c37a0..0000000
--- a/chrome/browser/metrics/drive_metrics_provider_linux.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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 <linux/kdev_t.h> // For MAJOR()/MINOR().
-#include <sys/stat.h>
-#include <string>
-
-#include "base/files/file.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/strings/stringprintf.h"
-
-#if defined(OS_CHROMEOS)
-#include "base/sys_info.h"
-#endif
-
-namespace {
-
-// See http://www.kernel.org/doc/Documentation/devices.txt for more info.
-const int kFirstScsiMajorNumber = 8;
-const int kPartitionsPerScsiDevice = 16;
-const char kRotationalFormat[] = "/sys/block/sd%c/queue/rotational";
-
-} // namespace
-
-// static
-bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
- bool* has_seek_penalty) {
-#if defined(OS_CHROMEOS)
- std::string board = base::SysInfo::GetLsbReleaseBoard();
- if (board != "unknown" && board != "parrot") {
- // All ChromeOS devices have SSDs. Except some parrots.
- *has_seek_penalty = false;
- return true;
- }
-#endif
-
- base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
- if (!file.IsValid())
- return false;
-
- struct stat path_stat;
- int error = fstat(file.GetPlatformFile(), &path_stat);
- if (error < 0 || MAJOR(path_stat.st_dev) != kFirstScsiMajorNumber) {
- // TODO(dbeam): support more SCSI major numbers (e.g. /dev/sdq+) and LVM?
- return false;
- }
-
- char sdX = 'a' + MINOR(path_stat.st_dev) / kPartitionsPerScsiDevice;
- std::string rotational_path = base::StringPrintf(kRotationalFormat, sdX);
- std::string rotates;
- if (!base::ReadFileToString(base::FilePath(rotational_path), &rotates))
- return false;
-
- *has_seek_penalty = rotates.substr(0, 1) == "1";
- return true;
-}
diff --git a/chrome/browser/metrics/drive_metrics_provider_mac.mm b/chrome/browser/metrics/drive_metrics_provider_mac.mm
deleted file mode 100644
index 565acd8..0000000
--- a/chrome/browser/metrics/drive_metrics_provider_mac.mm
+++ /dev/null
@@ -1,74 +0,0 @@
-// 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 <CoreFoundation/CoreFoundation.h>
-#include <DiskArbitration/DiskArbitration.h>
-#include <Foundation/Foundation.h>
-#include <IOKit/IOKitLib.h>
-#include <IOKit/storage/IOStorageDeviceCharacteristics.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-
-#include "base/files/file_path.h"
-#include "base/mac/foundation_util.h"
-#include "base/mac/mac_util.h"
-#include "base/mac/scoped_cftyperef.h"
-#include "base/mac/scoped_ioobject.h"
-
-// static
-bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
- bool* has_seek_penalty) {
- struct stat path_stat;
- if (stat(path.value().c_str(), &path_stat) < 0)
- return false;
-
- const char* dev_name = devname(path_stat.st_dev, S_IFBLK);
- if (!dev_name)
- return false;
-
- std::string bsd_name("/dev/");
- bsd_name.append(dev_name);
-
- base::ScopedCFTypeRef<DASessionRef> session(
- DASessionCreate(kCFAllocatorDefault));
- if (!session)
- return false;
-
- base::ScopedCFTypeRef<DADiskRef> disk(DADiskCreateFromBSDName(
- kCFAllocatorDefault, session, bsd_name.c_str()));
- if (!disk)
- return false;
-
- base::mac::ScopedIOObject<io_object_t> io_media(DADiskCopyIOMedia(disk));
- base::ScopedCFTypeRef<CFDictionaryRef> characteristics(
- static_cast<CFDictionaryRef>(IORegistryEntrySearchCFProperty(
- io_media,
- kIOServicePlane,
- CFSTR(kIOPropertyDeviceCharacteristicsKey),
- kCFAllocatorDefault,
- kIORegistryIterateRecursively | kIORegistryIterateParents)));
- if (!characteristics)
- return false;
-
- CFStringRef type_ref = base::mac::GetValueFromDictionary<CFStringRef>(
- characteristics, CFSTR(kIOPropertyMediumTypeKey));
- if (!type_ref)
- return false;
-
- NSString* type = base::mac::CFToNSCast(type_ref);
- if ([type isEqualToString:@kIOPropertyMediumTypeRotationalKey]) {
- *has_seek_penalty = true;
- return true;
- } else if ([type isEqualToString:@kIOPropertyMediumTypeSolidStateKey]) {
- *has_seek_penalty = false;
- return true;
- }
-
- // TODO(dbeam): should I look for these Rotational/Solid State keys in
- // |characteristics|? What if I find device characteristic but there's no
- // type? Assume rotational?
- return false;
-}
diff --git a/chrome/browser/metrics/drive_metrics_provider_unittest.cc b/chrome/browser/metrics/drive_metrics_provider_unittest.cc
deleted file mode 100644
index 7e78442..0000000
--- a/chrome/browser/metrics/drive_metrics_provider_unittest.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-// 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/files/file_path.h"
-#include "base/files/file_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-TEST(DriveMetricsProviderTest, HasSeekPenalty) {
- base::FilePath tmp_path;
- ASSERT_TRUE(base::GetTempDir(&tmp_path));
- bool unused;
- DriveMetricsProvider::HasSeekPenalty(tmp_path, &unused);
-}
diff --git a/chrome/browser/metrics/drive_metrics_provider_win.cc b/chrome/browser/metrics/drive_metrics_provider_win.cc
deleted file mode 100644
index 70cf322..0000000
--- a/chrome/browser/metrics/drive_metrics_provider_win.cc
+++ /dev/null
@@ -1,90 +0,0 @@
-// 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 <windows.h>
-#include <ntddscsi.h>
-#include <winioctl.h>
-#include <vector>
-
-#include "base/files/file.h"
-#include "base/files/file_path.h"
-#include "base/macros.h"
-#include "base/strings/stringprintf.h"
-#include "base/win/windows_version.h"
-
-namespace {
-
-// Semi-copy of similarly named struct from ata.h in WinDDK.
-struct IDENTIFY_DEVICE_DATA {
- USHORT UnusedWords[217];
- USHORT NominalMediaRotationRate;
- USHORT MoreUnusedWords[38];
-};
-COMPILE_ASSERT(sizeof(IDENTIFY_DEVICE_DATA) == 512, IdentifyDeviceDataSize);
-
-struct AtaRequest {
- ATA_PASS_THROUGH_EX query;
- IDENTIFY_DEVICE_DATA result;
-};
-
-} // namespace
-
-// static
-bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
- bool* has_seek_penalty) {
- std::vector<base::FilePath::StringType> components;
- path.GetComponents(&components);
-
- int flags = base::File::FLAG_OPEN;
- bool win7_or_higher = base::win::GetVersion() >= base::win::VERSION_WIN7;
- if (!win7_or_higher)
- flags |= base::File::FLAG_READ | base::File::FLAG_WRITE;
-
- base::File volume(base::FilePath(L"\\\\.\\" + components[0]), flags);
- if (!volume.IsValid())
- return false;
-
- if (win7_or_higher) {
- STORAGE_PROPERTY_QUERY query = {};
- query.QueryType = PropertyStandardQuery;
- query.PropertyId = StorageDeviceSeekPenaltyProperty;
-
- DEVICE_SEEK_PENALTY_DESCRIPTOR result;
- DWORD bytes_returned;
- BOOL success = DeviceIoControl(volume.GetPlatformFile(),
- IOCTL_STORAGE_QUERY_PROPERTY,
- &query, sizeof(query),
- &result, sizeof(result),
- &bytes_returned, NULL);
- if (success == FALSE || bytes_returned < sizeof(result))
- return false;
-
- *has_seek_penalty = result.IncursSeekPenalty != FALSE;
- } else {
- AtaRequest request = {};
- request.query.AtaFlags = ATA_FLAGS_DATA_IN;
- request.query.CurrentTaskFile[6] = ID_CMD;
- request.query.DataBufferOffset = sizeof(request.query);
- request.query.DataTransferLength = sizeof(request.result);
- request.query.Length = sizeof(request.query);
- request.query.TimeOutValue = 10;
-
- DWORD bytes_returned;
- BOOL success = DeviceIoControl(volume.GetPlatformFile(),
- IOCTL_ATA_PASS_THROUGH,
- &request, sizeof(request),
- &request, sizeof(request),
- &bytes_returned, NULL);
- if (success == FALSE || bytes_returned < sizeof(request) ||
- request.query.CurrentTaskFile[0]) {
- return false;
- }
-
- *has_seek_penalty = request.result.NominalMediaRotationRate != 1;
- }
-
- return true;
-}