OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/api/music_manager_private/device_id.h" | 5 #include "chrome/browser/extensions/api/music_manager_private/device_id.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <DiskArbitration/DASession.h> | 8 #include <DiskArbitration/DASession.h> |
9 #include <DiskArbitration/DADisk.h> | 9 #include <DiskArbitration/DADisk.h> |
10 #include <sys/mount.h> | 10 #include <sys/mount.h> |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 VLOG(1) << "Cannot find disk mounted as '" << kRootDirectory << "'."; | 40 VLOG(1) << "Cannot find disk mounted as '" << kRootDirectory << "'."; |
41 return std::string(); | 41 return std::string(); |
42 } | 42 } |
43 | 43 |
44 // Return the Volume UUID property of a BSD disk name (e.g. '/dev/disk1'). | 44 // Return the Volume UUID property of a BSD disk name (e.g. '/dev/disk1'). |
45 // Return "" if an error occured. | 45 // Return "" if an error occured. |
46 std::string GetVolumeUUIDFromBSDName(const std::string& bsd_name) { | 46 std::string GetVolumeUUIDFromBSDName(const std::string& bsd_name) { |
47 const CFAllocatorRef allocator = NULL; | 47 const CFAllocatorRef allocator = NULL; |
48 | 48 |
49 base::mac::ScopedCFTypeRef<DASessionRef> session(DASessionCreate(allocator)); | 49 base::ScopedCFTypeRef<DASessionRef> session(DASessionCreate(allocator)); |
50 if (session.get() == NULL) { | 50 if (session.get() == NULL) { |
51 VLOG(1) << "Error creating DA Session."; | 51 VLOG(1) << "Error creating DA Session."; |
52 return std::string(); | 52 return std::string(); |
53 } | 53 } |
54 | 54 |
55 base::mac::ScopedCFTypeRef<DADiskRef> disk( | 55 base::ScopedCFTypeRef<DADiskRef> disk( |
56 DADiskCreateFromBSDName(allocator, session, bsd_name.c_str())); | 56 DADiskCreateFromBSDName(allocator, session, bsd_name.c_str())); |
57 if (disk.get() == NULL) { | 57 if (disk.get() == NULL) { |
58 VLOG(1) << "Error creating DA disk from BSD disk name."; | 58 VLOG(1) << "Error creating DA disk from BSD disk name."; |
59 return std::string(); | 59 return std::string(); |
60 } | 60 } |
61 | 61 |
62 base::mac::ScopedCFTypeRef<CFDictionaryRef> disk_description( | 62 base::ScopedCFTypeRef<CFDictionaryRef> disk_description( |
63 DADiskCopyDescription(disk)); | 63 DADiskCopyDescription(disk)); |
64 if (disk_description.get() == NULL) { | 64 if (disk_description.get() == NULL) { |
65 VLOG(1) << "Error getting disk description."; | 65 VLOG(1) << "Error getting disk description."; |
66 return std::string(); | 66 return std::string(); |
67 } | 67 } |
68 | 68 |
69 CFUUIDRef volume_uuid = base::mac::GetValueFromDictionary<CFUUIDRef>( | 69 CFUUIDRef volume_uuid = base::mac::GetValueFromDictionary<CFUUIDRef>( |
70 disk_description, | 70 disk_description, |
71 kDADiskDescriptionVolumeUUIDKey); | 71 kDADiskDescriptionVolumeUUIDKey); |
72 if (volume_uuid == NULL) { | 72 if (volume_uuid == NULL) { |
73 VLOG(1) << "Error getting volume UUID of disk."; | 73 VLOG(1) << "Error getting volume UUID of disk."; |
74 return std::string(); | 74 return std::string(); |
75 } | 75 } |
76 | 76 |
77 base::mac::ScopedCFTypeRef<CFStringRef> volume_uuid_string( | 77 base::ScopedCFTypeRef<CFStringRef> volume_uuid_string( |
78 CFUUIDCreateString(allocator, volume_uuid)); | 78 CFUUIDCreateString(allocator, volume_uuid)); |
79 if (volume_uuid_string.get() == NULL) { | 79 if (volume_uuid_string.get() == NULL) { |
80 VLOG(1) << "Error creating string from CSStringRef."; | 80 VLOG(1) << "Error creating string from CSStringRef."; |
81 return std::string(); | 81 return std::string(); |
82 } | 82 } |
83 | 83 |
84 return base::SysCFStringRefToUTF8(volume_uuid_string.get()); | 84 return base::SysCFStringRefToUTF8(volume_uuid_string.get()); |
85 } | 85 } |
86 | 86 |
87 // Return Volume UUID property of disk mounted as "/". | 87 // Return Volume UUID property of disk mounted as "/". |
(...skipping 23 matching lines...) Expand all Loading... |
111 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 111 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
112 | 112 |
113 content::BrowserThread::PostTask( | 113 content::BrowserThread::PostTask( |
114 content::BrowserThread::FILE, | 114 content::BrowserThread::FILE, |
115 FROM_HERE, | 115 FROM_HERE, |
116 base::Bind(GetVolumeUUID, callback)); | 116 base::Bind(GetVolumeUUID, callback)); |
117 } | 117 } |
118 | 118 |
119 } // namespace api | 119 } // namespace api |
120 } // namespace extensions | 120 } // namespace extensions |
OLD | NEW |