diff options
-rw-r--r-- | base/sys_info.h | 4 | ||||
-rw-r--r-- | base/sys_info_android.cc | 6 | ||||
-rw-r--r-- | base/sys_info_chromeos.cc | 5 | ||||
-rw-r--r-- | base/sys_info_freebsd.cc | 4 | ||||
-rw-r--r-- | base/sys_info_ios.mm | 6 | ||||
-rw-r--r-- | base/sys_info_linux.cc | 7 | ||||
-rw-r--r-- | base/sys_info_mac.cc | 5 | ||||
-rw-r--r-- | base/sys_info_openbsd.cc | 4 | ||||
-rw-r--r-- | base/sys_info_unittest.cc | 7 | ||||
-rw-r--r-- | base/sys_info_win.cc | 78 | ||||
-rw-r--r-- | chrome/browser/metrics/drive_metrics_provider.cc | 13 | ||||
-rw-r--r-- | chrome/browser/metrics/drive_metrics_provider.h | 12 | ||||
-rw-r--r-- | chrome/browser/metrics/drive_metrics_provider_android.cc | 12 | ||||
-rw-r--r-- | chrome/browser/metrics/drive_metrics_provider_ios.mm | 12 | ||||
-rw-r--r-- | chrome/browser/metrics/drive_metrics_provider_unittest.cc | 16 | ||||
-rw-r--r-- | chrome/browser/metrics/drive_metrics_provider_win.cc | 90 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 3 | ||||
-rw-r--r-- | chrome/chrome_tests_unit.gypi | 1 |
18 files changed, 156 insertions, 129 deletions
diff --git a/base/sys_info.h b/base/sys_info.h index d3476d9..660343d 100644 --- a/base/sys_info.h +++ b/base/sys_info.h @@ -48,10 +48,6 @@ class BASE_EXPORT SysInfo { // or -1 on failure. static int64 AmountOfFreeDiskSpace(const FilePath& path); - // 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 FilePath& path, bool* has_seek_penalty); - // Returns system uptime in milliseconds. static int64 Uptime(); diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc index 0f2abc5..245097f 100644 --- a/base/sys_info_android.cc +++ b/base/sys_info_android.cc @@ -155,12 +155,6 @@ int GetDalvikHeapGrowthLimitMB() { namespace base { -bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { - // Find a case where this is incorrect and dbeam@ will buy you a beer. - *has_seek_penalty = false; - return true; -} - std::string SysInfo::OperatingSystemName() { return "Android"; } diff --git a/base/sys_info_chromeos.cc b/base/sys_info_chromeos.cc index 2a5f5d7..ef5f1fe 100644 --- a/base/sys_info_chromeos.cc +++ b/base/sys_info_chromeos.cc @@ -169,11 +169,6 @@ ChromeOSVersionInfo& GetChromeOSVersionInfo() { } // namespace -bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { - // TODO(dbeam): implement. Can we just use boards/models? - return false; -} - // static void SysInfo::OperatingSystemVersionNumbers(int32* major_version, int32* minor_version, diff --git a/base/sys_info_freebsd.cc b/base/sys_info_freebsd.cc index 338f1cd..832b3598 100644 --- a/base/sys_info_freebsd.cc +++ b/base/sys_info_freebsd.cc @@ -22,10 +22,6 @@ int64 SysInfo::AmountOfPhysicalMemory() { return static_cast<int64>(pages) * page_size; } -bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { - return false; -} - // static size_t SysInfo::MaxSharedMemorySize() { size_t limit; diff --git a/base/sys_info_ios.mm b/base/sys_info_ios.mm index 324bef6..49d618c 100644 --- a/base/sys_info_ios.mm +++ b/base/sys_info_ios.mm @@ -16,12 +16,6 @@ namespace base { -bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { - // Find a case where this is incorrect and dbeam@ will buy you a beer. - *has_seek_penalty = false; - return true; -} - // static std::string SysInfo::OperatingSystemName() { static dispatch_once_t get_system_name_once; diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc index 401d55c..c698f91 100644 --- a/base/sys_info_linux.cc +++ b/base/sys_info_linux.cc @@ -68,13 +68,6 @@ int64 SysInfo::AmountOfPhysicalMemory() { return g_lazy_physical_memory.Get().value(); } -#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) -bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { - // TODO(dbeam): implement. - return false; -} -#endif - // static size_t SysInfo::MaxSharedMemorySize() { return g_lazy_max_shared_memory.Get().value(); diff --git a/base/sys_info_mac.cc b/base/sys_info_mac.cc index 8635088..18df624 100644 --- a/base/sys_info_mac.cc +++ b/base/sys_info_mac.cc @@ -76,11 +76,6 @@ int64 SysInfo::AmountOfAvailablePhysicalMemory() { vm_info.free_count - vm_info.speculative_count) * PAGE_SIZE; } -bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { - // TODO(dbeam): implement. - return false; -} - // static std::string SysInfo::CPUModelName() { char name[256]; diff --git a/base/sys_info_openbsd.cc b/base/sys_info_openbsd.cc index 68d2ea14..edbb2c9 100644 --- a/base/sys_info_openbsd.cc +++ b/base/sys_info_openbsd.cc @@ -48,10 +48,6 @@ int64 SysInfo::AmountOfAvailablePhysicalMemory() { return AmountOfMemory(_SC_AVPHYS_PAGES); } -bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { - return false; -} - // static size_t SysInfo::MaxSharedMemorySize() { int mib[] = { CTL_KERN, KERN_SHMINFO, KERN_SHMINFO_SHMMAX }; diff --git a/base/sys_info_unittest.cc b/base/sys_info_unittest.cc index da47861..15ae098 100644 --- a/base/sys_info_unittest.cc +++ b/base/sys_info_unittest.cc @@ -41,13 +41,6 @@ TEST_F(SysInfoTest, AmountOfFreeDiskSpace) { << tmp_path.value(); } -TEST_F(SysInfoTest, HasSeekPenalty) { - FilePath tmp_path; - ASSERT_TRUE(base::GetTempDir(&tmp_path)); - bool unused; - base::SysInfo::HasSeekPenalty(tmp_path, &unused); -} - #if defined(OS_WIN) || defined(OS_MACOSX) TEST_F(SysInfoTest, OperatingSystemVersionNumbers) { int32 os_major_version = -1; diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc index eccb6ac..c8314c7 100644 --- a/base/sys_info_win.cc +++ b/base/sys_info_win.cc @@ -4,14 +4,10 @@ #include "base/sys_info.h" -#include <ntddscsi.h> #include <windows.h> -#include <winioctl.h> -#include "base/files/file.h" #include "base/files/file_path.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/strings/stringprintf.h" #include "base/threading/thread_restrictions.h" @@ -19,19 +15,6 @@ 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; -}; - int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) { MEMORYSTATUSEX memory_info; memory_info.dwLength = sizeof(memory_info); @@ -80,67 +63,6 @@ int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { return rv < 0 ? kint64max : rv; } -bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { - ThreadRestrictions::AssertIOAllowed(); - - DCHECK(path.IsAbsolute()); - DCHECK(has_seek_penalty); - - std::vector<FilePath::StringType> components; - path.GetComponents(&components); - - int flags = File::FLAG_OPEN; - const bool win7_or_higher = win::GetVersion() >= win::VERSION_WIN7; - if (!win7_or_higher) - flags |= File::FLAG_READ | File::FLAG_WRITE; - - File volume(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; -} - -// static std::string SysInfo::OperatingSystemName() { return "Windows NT"; } diff --git a/chrome/browser/metrics/drive_metrics_provider.cc b/chrome/browser/metrics/drive_metrics_provider.cc index 50c6270..5873583 100644 --- a/chrome/browser/metrics/drive_metrics_provider.cc +++ b/chrome/browser/metrics/drive_metrics_provider.cc @@ -11,7 +11,6 @@ #include "base/logging.h" #include "base/metrics/histogram_macros.h" #include "base/path_service.h" -#include "base/sys_info.h" #include "base/time/time.h" #include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_thread.h" @@ -41,6 +40,15 @@ void DriveMetricsProvider::GetDriveMetrics(const base::Closure& done) { DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse() : success(false) {} +#if !(defined(OS_WIN) || defined(OS_ANDROID) || defined(OS_IOS)) +// static +bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, + bool* has_seek_penalty) { + // TODO(dbeam): implement on more platforms. + return false; +} +#endif + // static DriveMetricsProvider::DriveMetrics DriveMetricsProvider::GetDriveMetricsOnFileThread() { @@ -64,8 +72,7 @@ void DriveMetricsProvider::QuerySeekPenalty( base::TimeTicks start = base::TimeTicks::Now(); - response->success = - base::SysInfo::HasSeekPenalty(path, &response->has_seek_penalty); + response->success = HasSeekPenalty(path, &response->has_seek_penalty); UMA_HISTOGRAM_TIMES("Hardware.Drive.HasSeekPenalty_Time", base::TimeTicks::Now() - start); diff --git a/chrome/browser/metrics/drive_metrics_provider.h b/chrome/browser/metrics/drive_metrics_provider.h index 530c0a4..6ddccec 100644 --- a/chrome/browser/metrics/drive_metrics_provider.h +++ b/chrome/browser/metrics/drive_metrics_provider.h @@ -6,12 +6,17 @@ #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). // @@ -30,6 +35,8 @@ class DriveMetricsProvider : public metrics::MetricsProvider { 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 { @@ -43,6 +50,11 @@ class DriveMetricsProvider : public metrics::MetricsProvider { 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(); diff --git a/chrome/browser/metrics/drive_metrics_provider_android.cc b/chrome/browser/metrics/drive_metrics_provider_android.cc new file mode 100644 index 0000000..beb9e8c --- /dev/null +++ b/chrome/browser/metrics/drive_metrics_provider_android.cc @@ -0,0 +1,12 @@ +// 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 new file mode 100644 index 0000000..beb9e8c --- /dev/null +++ b/chrome/browser/metrics/drive_metrics_provider_ios.mm @@ -0,0 +1,12 @@ +// 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_unittest.cc b/chrome/browser/metrics/drive_metrics_provider_unittest.cc new file mode 100644 index 0000000..7e78442 --- /dev/null +++ b/chrome/browser/metrics/drive_metrics_provider_unittest.cc @@ -0,0 +1,16 @@ +// 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 new file mode 100644 index 0000000..70cf322 --- /dev/null +++ b/chrome/browser/metrics/drive_metrics_provider_win.cc @@ -0,0 +1,90 @@ +// 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; +} diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 41794f9..59c8fa33 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1735,6 +1735,9 @@ 'browser/metrics/chrome_stability_metrics_provider.cc', 'browser/metrics/chrome_stability_metrics_provider.h', 'browser/metrics/drive_metrics_provider.cc', + 'browser/metrics/drive_metrics_provider_android.cc', + 'browser/metrics/drive_metrics_provider_ios.mm', + 'browser/metrics/drive_metrics_provider_win.cc', 'browser/metrics/drive_metrics_provider.h', 'browser/metrics/field_trial_synchronizer.cc', 'browser/metrics/field_trial_synchronizer.h', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 336a709..703cae6 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -137,6 +137,7 @@ 'browser/media/native_desktop_media_list_unittest.cc', 'browser/metrics/chrome_metrics_service_accessor_unittest.cc', 'browser/metrics/cloned_install_detector_unittest.cc', + 'browser/metrics/drive_metrics_provider_unittest.cc', 'browser/metrics/metrics_services_manager_unittest.cc', 'browser/metrics/signin_status_metrics_provider_chromeos_unittest.cc', 'browser/metrics/signin_status_metrics_provider_unittest.cc', |