Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/metrics/drive_metrics_provider.h" | 5 #include "chrome/browser/metrics/drive_metrics_provider.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | |
| 8 #include <DiskArbitration/DiskArbitration.h> | |
| 9 #import <Foundation/NSURL.h> | |
|
Dan Beam
2015/04/08 00:15:54
full disclosure: i little idea when to #include vs
groby-ooo-7-16
2015/04/08 00:41:02
You guessed well :) (If it's ObjC stuff, it's impo
groby-ooo-7-16
2015/04/08 00:41:02
Instead of picking on NSUrl, just use
#import <
Dan Beam
2015/04/08 01:04:43
that was actually exactly my reasoning, lol
Dan Beam
2015/04/08 01:04:43
Done.
| |
| 10 #include <IOKit/IOKitLib.h> | |
| 11 #include <IOKit/storage/IOStorageDeviceCharacteristics.h> | |
| 12 | |
| 13 #include "base/mac/foundation_util.h" | |
| 14 #include "base/mac/mac_util.h" | |
| 15 #include "base/mac/scoped_cftyperef.h" | |
| 16 #include "base/mac/scoped_ioobject.h" | |
| 17 | |
| 7 // static | 18 // static |
| 8 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, | 19 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, |
| 9 bool* has_seek_penalty) { | 20 bool* has_seek_penalty) { |
| 10 // TODO(dbeam): implement. | 21 NSURL* url = [NSURL fileURLWithPath:base::mac::FilePathToNSString(path)]; |
| 11 return false; | 22 if (!url) |
|
groby-ooo-7-16
2015/04/08 00:41:02
Can't return nil
Dan Beam
2015/04/08 01:04:43
Done.
| |
| 23 return false; | |
| 24 | |
| 25 NSURL* volume; | |
|
groby-ooo-7-16
2015/04/08 00:41:02
Cocoa usually spells out the type, so volumeUrl
Dan Beam
2015/04/08 01:04:43
Done.
| |
| 26 if (![url getResourceValue:&volume forKey:NSURLVolumeURLKey error:nil]) | |
| 27 return false; | |
| 28 | |
| 29 base::ScopedCFTypeRef<DASessionRef> session(DASessionCreate(nullptr)); | |
|
groby-ooo-7-16
2015/04/08 00:41:02
Please don't nullptr - kCFAllocatorDefault (It's t
Dan Beam
2015/04/08 01:04:43
Done.
| |
| 30 if (!session) | |
| 31 return false; | |
| 32 | |
| 33 base::ScopedCFTypeRef<DADiskRef> disk( | |
| 34 DADiskCreateFromVolumePath(nullptr, session, (CFURLRef)volume)); | |
|
Dan Beam
2015/04/08 00:17:35
i don't know our stance on toll-free bridging... o
groby-ooo-7-16
2015/04/08 00:41:02
nullptr is kCFAllocatorDefault
groby-ooo-7-16
2015/04/08 00:41:02
base::mac::NSToCFCast(volumeUrl)
Dan Beam
2015/04/08 01:04:43
Done.
Dan Beam
2015/04/08 01:04:43
Done.
| |
| 35 if (!disk) | |
| 36 return false; | |
| 37 | |
| 38 base::mac::ScopedIOObject<io_object_t> media(DADiskCopyIOMedia(disk)); | |
| 39 base::ScopedCFTypeRef<CFDictionaryRef> characteristics( | |
| 40 static_cast<CFDictionaryRef>(IORegistryEntrySearchCFProperty( | |
| 41 media, | |
| 42 kIOServicePlane, | |
| 43 CFSTR(kIOPropertyDeviceCharacteristicsKey), | |
| 44 kCFAllocatorDefault, | |
|
Dan Beam
2015/04/08 00:17:35
also i wasn't sure when to pass kCFAllocatorDefaul
groby-ooo-7-16
2015/04/08 00:41:02
Heh - see above :)
| |
| 45 kIORegistryIterateRecursively | kIORegistryIterateParents))); | |
| 46 if (!characteristics) | |
| 47 return false; | |
| 48 | |
| 49 CFStringRef type = base::mac::GetValueFromDictionary<CFStringRef>( | |
| 50 characteristics, CFSTR(kIOPropertyMediumTypeKey)); | |
| 51 if (!type) | |
| 52 return false; | |
| 53 | |
| 54 return [@"Solid State" isEqualToString:(NSString*)type]; | |
|
groby-ooo-7-16
2015/04/08 00:41:02
Eeeeeeew. base::mac::CFToNSCast, please. :)
Dan Beam
2015/04/08 01:04:43
Done.
| |
| 12 } | 55 } |
| OLD | NEW |