Index: chrome/browser/metrics/drive_metrics_provider_mac.mm |
diff --git a/chrome/browser/metrics/drive_metrics_provider_mac.mm b/chrome/browser/metrics/drive_metrics_provider_mac.mm |
index ff98485df15b23257a75939ac01e4370e79ad3e6..4896573253692860af9ab7fa19926bbc560cb781 100644 |
--- a/chrome/browser/metrics/drive_metrics_provider_mac.mm |
+++ b/chrome/browser/metrics/drive_metrics_provider_mac.mm |
@@ -4,9 +4,52 @@ |
#include "chrome/browser/metrics/drive_metrics_provider.h" |
+#include <CoreFoundation/CoreFoundation.h> |
+#include <DiskArbitration/DiskArbitration.h> |
+#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.
|
+#include <IOKit/IOKitLib.h> |
+#include <IOKit/storage/IOStorageDeviceCharacteristics.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) { |
- // TODO(dbeam): implement. |
- return false; |
+ NSURL* url = [NSURL fileURLWithPath:base::mac::FilePathToNSString(path)]; |
+ 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.
|
+ return false; |
+ |
+ 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.
|
+ if (![url getResourceValue:&volume forKey:NSURLVolumeURLKey error:nil]) |
+ return false; |
+ |
+ 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.
|
+ if (!session) |
+ return false; |
+ |
+ base::ScopedCFTypeRef<DADiskRef> disk( |
+ 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.
|
+ if (!disk) |
+ return false; |
+ |
+ base::mac::ScopedIOObject<io_object_t> media(DADiskCopyIOMedia(disk)); |
+ base::ScopedCFTypeRef<CFDictionaryRef> characteristics( |
+ static_cast<CFDictionaryRef>(IORegistryEntrySearchCFProperty( |
+ media, |
+ kIOServicePlane, |
+ CFSTR(kIOPropertyDeviceCharacteristicsKey), |
+ 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 :)
|
+ kIORegistryIterateRecursively | kIORegistryIterateParents))); |
+ if (!characteristics) |
+ return false; |
+ |
+ CFStringRef type = base::mac::GetValueFromDictionary<CFStringRef>( |
+ characteristics, CFSTR(kIOPropertyMediumTypeKey)); |
+ if (!type) |
+ return false; |
+ |
+ 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.
|
} |