Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: components/metrics/drive_metrics_provider_win.cc

Issue 2909943003: Removing useless Win7 checks + standardize its use (Closed)
Patch Set: Fix reversed conditionnal Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/metrics/drive_metrics_provider.h" 5 #include "components/metrics/drive_metrics_provider.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <winioctl.h> 8 #include <winioctl.h>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/files/file.h" 11 #include "base/files/file.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/win/windows_version.h"
15 14
16 namespace metrics { 15 namespace metrics {
17 16
18 // static 17 // static
19 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, 18 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
20 bool* has_seek_penalty) { 19 bool* has_seek_penalty) {
21 if (base::win::GetVersion() < base::win::VERSION_WIN7) {
22 // TODO(dbeam): re-enable XP and Vista detection in a utility process.
23 return false;
24 }
25
26 std::vector<base::FilePath::StringType> components; 20 std::vector<base::FilePath::StringType> components;
27 path.GetComponents(&components); 21 path.GetComponents(&components);
28 22
29 base::File volume(base::FilePath(L"\\\\.\\" + components[0]), 23 base::File volume(base::FilePath(L"\\\\.\\" + components[0]),
30 base::File::FLAG_OPEN); 24 base::File::FLAG_OPEN);
31 if (!volume.IsValid()) 25 if (!volume.IsValid())
32 return false; 26 return false;
33 27
34 STORAGE_PROPERTY_QUERY query = {}; 28 STORAGE_PROPERTY_QUERY query = {};
35 query.QueryType = PropertyStandardQuery; 29 query.QueryType = PropertyStandardQuery;
36 query.PropertyId = StorageDeviceSeekPenaltyProperty; 30 query.PropertyId = StorageDeviceSeekPenaltyProperty;
37 31
38 DEVICE_SEEK_PENALTY_DESCRIPTOR result; 32 DEVICE_SEEK_PENALTY_DESCRIPTOR result;
39 DWORD bytes_returned; 33 DWORD bytes_returned;
40 34
41 BOOL success = DeviceIoControl( 35 BOOL success = DeviceIoControl(
42 volume.GetPlatformFile(), IOCTL_STORAGE_QUERY_PROPERTY, &query, 36 volume.GetPlatformFile(), IOCTL_STORAGE_QUERY_PROPERTY, &query,
43 sizeof(query), &result, sizeof(result), &bytes_returned, NULL); 37 sizeof(query), &result, sizeof(result), &bytes_returned, NULL);
44 38
45 if (success == FALSE || bytes_returned < sizeof(result)) 39 if (success == FALSE || bytes_returned < sizeof(result))
46 return false; 40 return false;
47 41
48 *has_seek_penalty = result.IncursSeekPenalty != FALSE; 42 *has_seek_penalty = result.IncursSeekPenalty != FALSE;
49 return true; 43 return true;
50 } 44 }
51 45
52 } // namespace metrics 46 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698