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

Unified Diff: chrome/browser/metrics/drive_metrics_provider_mac.mm

Issue 1069473003: Detect seek penalties on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698