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

Side by Side Diff: chrome/browser/system_monitor/disk_info_mac.mm

Issue 10919185: Implement RemovableDeviceNotifications for Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix threading Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/system_monitor/disk_info_mac.h"
6
7 #include "base/mac/foundation_util.h"
8 #include "base/sys_string_conversions.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/system_monitor/media_device_notifications_utils.h"
11 #include "chrome/browser/system_monitor/media_storage_util.h"
12 #include "content/public/browser/browser_thread.h"
13
14 namespace chrome {
15 namespace {
16
17 string16 GetUTF16FromDictionary(CFDictionaryRef dictionary, CFStringRef key) {
18 CFStringRef value =
19 base::mac::GetValueFromDictionary<CFStringRef>(dictionary, key);
20 return base::SysCFStringRefToUTF16(value);
21 }
22
23 string16 JoinName(const string16& name, const string16& addition) {
24 if (addition.empty())
25 return name;
26 if (name.empty())
27 return addition;
28 return name + ASCIIToUTF16(" ") + addition;
29 }
30
31 MediaStorageUtil::Type GetDeviceType(bool is_removable, bool has_dcim) {
32 if (is_removable) {
33 if (has_dcim) {
34 return MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM;
35 } else {
36 return MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
37 }
38 } else {
39 return MediaStorageUtil::FIXED_MASS_STORAGE;
40 }
Nico 2012/09/10 07:02:34 nit: gets a bit shorter with early outs: if (!is_
sail 2012/09/10 21:58:43 Done.
41 }
42
43 } // namespace
44
45 DiskInfoMac::DiskInfoMac() {
46 }
47
48 DiskInfoMac::~DiskInfoMac() {
49 }
50
51 // static
52 DiskInfoMac DiskInfoMac::BuildDiskInfoOnFileThread(CFDictionaryRef dict) {
53 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
54 DiskInfoMac info;
55
56 CFStringRef bsd_name = base::mac::GetValueFromDictionary<CFStringRef>(
57 dict, kDADiskDescriptionMediaBSDNameKey);
58 info.bsd_name_ = base::SysCFStringRefToUTF8(bsd_name);
Nico 2012/09/10 07:02:34 I'd do the null checking here instead of changing
sail 2012/09/10 21:58:43 Unless you feel strongly about this I'd prefer to
59
60 CFURLRef url = base::mac::GetValueFromDictionary<CFURLRef>(
61 dict, kDADiskDescriptionVolumePathKey);
62 NSURL* nsurl = base::mac::CFToNSCast(url);
63 info.mount_point_ = base::mac::NSStringToFilePath([nsurl path]);
64
65 string16 vendor_name = GetUTF16FromDictionary(
66 dict, kDADiskDescriptionDeviceVendorKey);
67 string16 model_name = GetUTF16FromDictionary(
68 dict, kDADiskDescriptionDeviceModelKey);
69 string16 volume_name = GetUTF16FromDictionary(
70 dict, kDADiskDescriptionVolumeNameKey);
71 info.display_name_ = vendor_name;
72 info.display_name_ = JoinName(info.display_name_, model_name);
73 info.display_name_ = JoinName(info.display_name_, volume_name);
74
75 CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>(
76 dict, kDADiskDescriptionVolumeUUIDKey);
77 std::string unique_id;
78 if (uuid) {
79 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string(
80 CFUUIDCreateString(NULL, uuid));
81 unique_id = base::SysCFStringRefToUTF8(uuid_string);
82 }
83 if (unique_id.empty())
84 unique_id = info.bsd_name_;
vandebo (ex-Chrome) 2012/09/10 18:45:03 This is ok for non-removable devices, but not for
sail 2012/09/10 21:58:43 Unfortunately I couldn't find a better solution. M
vandebo (ex-Chrome) 2012/09/10 22:53:05 Fair, though bsd_name isn't helpful.... The Disk
sail 2012/09/11 00:14:06 Done. Changed to use "vendor model revision unit"
85
86 CFBooleanRef is_removable_ref =
87 base::mac::GetValueFromDictionary<CFBooleanRef>(
88 dict, kDADiskDescriptionMediaRemovableKey);
89 bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref);
90 bool has_dcim = IsMediaDevice(info.mount_point_.value());
91 info.type_ = GetDeviceType(is_removable, has_dcim);
92 info.device_id_ = MediaStorageUtil::MakeDeviceId(info.type_, unique_id);
93
94 return info;
95 }
96
97 } // chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698