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

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: address review comments 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 if (!value)
21 return string16();
22 return base::SysCFStringRefToUTF16(value);
23 }
24
25 string16 JoinName(const string16& name, const string16& addition) {
26 if (addition.empty())
27 return name;
28 if (name.empty())
29 return addition;
30 return name + static_cast<char16>(' ') + addition;
31 }
32
33 MediaStorageUtil::Type GetDeviceType(bool is_removable, bool has_dcim) {
34 if (!is_removable)
35 return MediaStorageUtil::FIXED_MASS_STORAGE;
36 if (has_dcim)
37 return MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM;
38 return MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
39 }
40
41 } // namespace
42
43 DiskInfoMac::DiskInfoMac() {
44 }
45
46 DiskInfoMac::~DiskInfoMac() {
47 }
48
49 // static
50 DiskInfoMac DiskInfoMac::BuildDiskInfoOnFileThread(CFDictionaryRef dict) {
51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
52 DiskInfoMac info;
53
54 CFStringRef bsd_name = base::mac::GetValueFromDictionary<CFStringRef>(
55 dict, kDADiskDescriptionMediaBSDNameKey);
56 if (bsd_name)
57 info.bsd_name_ = base::SysCFStringRefToUTF8(bsd_name);
58
59 CFURLRef url = base::mac::GetValueFromDictionary<CFURLRef>(
60 dict, kDADiskDescriptionVolumePathKey);
61 NSURL* nsurl = base::mac::CFToNSCast(url);
62 info.mount_point_ = base::mac::NSStringToFilePath([nsurl path]);
63
64 string16 vendor_name = GetUTF16FromDictionary(
65 dict, kDADiskDescriptionDeviceVendorKey);
66 string16 model_name = GetUTF16FromDictionary(
67 dict, kDADiskDescriptionDeviceModelKey);
68 string16 volume_name = GetUTF16FromDictionary(
69 dict, kDADiskDescriptionVolumeNameKey);
70 info.display_name_ = vendor_name;
71 info.display_name_ = JoinName(info.display_name_, model_name);
72 info.display_name_ = JoinName(info.display_name_, volume_name);
73
74 CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>(
75 dict, kDADiskDescriptionVolumeUUIDKey);
76 std::string unique_id;
77 if (uuid) {
78 base::mac::ScopedCFTypeRef<CFStringRef> uuid_string(
79 CFUUIDCreateString(NULL, uuid));
80 if (uuid_string.get())
81 unique_id = base::SysCFStringRefToUTF8(uuid_string);
82 }
83 if (unique_id.empty()) {
84 string16 revision = GetUTF16FromDictionary(
85 dict, kDADiskDescriptionDeviceRevisionKey);
86 string16 unique_id2 = vendor_name;
87 unique_id2 = JoinName(unique_id2, model_name);
88 unique_id2 = JoinName(unique_id2, revision);
89 unique_id = UTF16ToUTF8(unique_id2);
90 }
91
92 CFBooleanRef is_removable_ref =
93 base::mac::GetValueFromDictionary<CFBooleanRef>(
94 dict, kDADiskDescriptionMediaRemovableKey);
95 bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref);
96 // Checking for DCIM only matters on removable devices.
97 bool has_dcim = is_removable && IsMediaDevice(info.mount_point_.value());
98 info.type_ = GetDeviceType(is_removable, has_dcim);
99 if (!unique_id.empty())
100 info.device_id_ = MediaStorageUtil::MakeDeviceId(info.type_, unique_id);
101
102 return info;
103 }
104
105 } // namesapce chrome
OLDNEW
« no previous file with comments | « chrome/browser/system_monitor/disk_info_mac.h ('k') | chrome/browser/system_monitor/removable_device_notifications_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698