| OLD | NEW | 
|    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |    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 |    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/storage_monitor/disk_info_mac.h" |    5 #include "chrome/browser/storage_monitor/disk_info_mac.h" | 
|    6  |    6  | 
|    7 #include "base/mac/foundation_util.h" |    7 #include "base/mac/foundation_util.h" | 
|    8 #include "base/sys_string_conversions.h" |    8 #include "base/sys_string_conversions.h" | 
|    9 #include "base/utf_string_conversions.h" |    9 #include "base/utf_string_conversions.h" | 
|   10 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" |  | 
|   11 #include "chrome/browser/storage_monitor/media_storage_util.h" |   10 #include "chrome/browser/storage_monitor/media_storage_util.h" | 
|   12 #include "content/public/browser/browser_thread.h" |   11 #include "content/public/browser/browser_thread.h" | 
|   13  |   12  | 
|   14 namespace chrome { |   13 namespace chrome { | 
|   15 namespace { |   14 namespace { | 
|   16  |   15  | 
|   17 string16 GetUTF16FromDictionary(CFDictionaryRef dictionary, CFStringRef key) { |   16 string16 GetUTF16FromDictionary(CFDictionaryRef dictionary, CFStringRef key) { | 
|   18   CFStringRef value = |   17   CFStringRef value = | 
|   19       base::mac::GetValueFromDictionary<CFStringRef>(dictionary, key); |   18       base::mac::GetValueFromDictionary<CFStringRef>(dictionary, key); | 
|   20   if (!value) |   19   if (!value) | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   71   string16 vendor_name = GetUTF16FromDictionary( |   70   string16 vendor_name = GetUTF16FromDictionary( | 
|   72       dict, kDADiskDescriptionDeviceVendorKey); |   71       dict, kDADiskDescriptionDeviceVendorKey); | 
|   73   string16 model_name = GetUTF16FromDictionary( |   72   string16 model_name = GetUTF16FromDictionary( | 
|   74       dict, kDADiskDescriptionDeviceModelKey); |   73       dict, kDADiskDescriptionDeviceModelKey); | 
|   75   string16 volume_name = GetUTF16FromDictionary( |   74   string16 volume_name = GetUTF16FromDictionary( | 
|   76       dict, kDADiskDescriptionVolumeNameKey); |   75       dict, kDADiskDescriptionVolumeNameKey); | 
|   77  |   76  | 
|   78   if (!volume_name.empty()) { |   77   if (!volume_name.empty()) { | 
|   79     info.device_name_ = volume_name; |   78     info.device_name_ = volume_name; | 
|   80   } else { |   79   } else { | 
|   81     info.device_name_ = GetFullProductName(UTF16ToUTF8(vendor_name), |   80     info.device_name_ = MediaStorageUtil::GetFullProductName( | 
|   82                                            UTF16ToUTF8(model_name)); |   81         UTF16ToUTF8(vendor_name), | 
 |   82         UTF16ToUTF8(model_name)); | 
|   83   } |   83   } | 
|   84   info.model_name_ = UTF16ToUTF8(model_name); |   84   info.model_name_ = UTF16ToUTF8(model_name); | 
|   85  |   85  | 
|   86   CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>( |   86   CFUUIDRef uuid = base::mac::GetValueFromDictionary<CFUUIDRef>( | 
|   87       dict, kDADiskDescriptionVolumeUUIDKey); |   87       dict, kDADiskDescriptionVolumeUUIDKey); | 
|   88   std::string unique_id; |   88   std::string unique_id; | 
|   89   if (uuid) { |   89   if (uuid) { | 
|   90     base::mac::ScopedCFTypeRef<CFStringRef> uuid_string( |   90     base::mac::ScopedCFTypeRef<CFStringRef> uuid_string( | 
|   91         CFUUIDCreateString(NULL, uuid)); |   91         CFUUIDCreateString(NULL, uuid)); | 
|   92     if (uuid_string.get()) |   92     if (uuid_string.get()) | 
|   93       unique_id = base::SysCFStringRefToUTF8(uuid_string); |   93       unique_id = base::SysCFStringRefToUTF8(uuid_string); | 
|   94   } |   94   } | 
|   95   if (unique_id.empty()) { |   95   if (unique_id.empty()) { | 
|   96     string16 revision = GetUTF16FromDictionary( |   96     string16 revision = GetUTF16FromDictionary( | 
|   97         dict, kDADiskDescriptionDeviceRevisionKey); |   97         dict, kDADiskDescriptionDeviceRevisionKey); | 
|   98     string16 unique_id2 = vendor_name; |   98     string16 unique_id2 = vendor_name; | 
|   99     unique_id2 = JoinName(unique_id2, model_name); |   99     unique_id2 = JoinName(unique_id2, model_name); | 
|  100     unique_id2 = JoinName(unique_id2, revision); |  100     unique_id2 = JoinName(unique_id2, revision); | 
|  101     unique_id = UTF16ToUTF8(unique_id2); |  101     unique_id = UTF16ToUTF8(unique_id2); | 
|  102   } |  102   } | 
|  103  |  103  | 
|  104   CFBooleanRef is_removable_ref = |  104   CFBooleanRef is_removable_ref = | 
|  105       base::mac::GetValueFromDictionary<CFBooleanRef>( |  105       base::mac::GetValueFromDictionary<CFBooleanRef>( | 
|  106           dict, kDADiskDescriptionMediaRemovableKey); |  106           dict, kDADiskDescriptionMediaRemovableKey); | 
|  107   bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref); |  107   bool is_removable = is_removable_ref && CFBooleanGetValue(is_removable_ref); | 
|  108   // Checking for DCIM only matters on removable devices. |  108   // Checking for DCIM only matters on removable devices. | 
|  109   bool has_dcim = is_removable && IsMediaDevice(info.mount_point_.value()); |  109   bool has_dcim = | 
 |  110       is_removable && MediaStorageUtil::HasDcim(info.mount_point_.value()); | 
|  110   info.type_ = GetDeviceType(is_removable, has_dcim); |  111   info.type_ = GetDeviceType(is_removable, has_dcim); | 
|  111   if (!unique_id.empty()) |  112   if (!unique_id.empty()) | 
|  112     info.device_id_ = MediaStorageUtil::MakeDeviceId(info.type_, unique_id); |  113     info.device_id_ = MediaStorageUtil::MakeDeviceId(info.type_, unique_id); | 
|  113  |  114  | 
|  114   return info; |  115   return info; | 
|  115 } |  116 } | 
|  116  |  117  | 
|  117 }  // namesapce chrome |  118 }  // namesapce chrome | 
| OLD | NEW |