Chromium Code Reviews| 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/system_monitor/media_transfer_protocol_device_observer_ chromeos.h" | 5 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_ chromeos.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 chrome::kNonSpaceDelim, | 66 chrome::kNonSpaceDelim, |
| 67 model_id.c_str(), | 67 model_id.c_str(), |
| 68 chrome::kNonSpaceDelim, | 68 chrome::kNonSpaceDelim, |
| 69 volume_id.c_str(), | 69 volume_id.c_str(), |
| 70 chrome::kNonSpaceDelim, | 70 chrome::kNonSpaceDelim, |
| 71 storage_id.c_str()); | 71 storage_id.c_str()); |
| 72 return MediaStorageUtil::MakeDeviceId(MediaStorageUtil::MTP_OR_PTP, | 72 return MediaStorageUtil::MakeDeviceId(MediaStorageUtil::MTP_OR_PTP, |
| 73 unique_id); | 73 unique_id); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Returns the |data_store_id| string in the required format. | |
| 77 // If the |data_store_id| is 65537, this function returns "(65537)". | |
| 78 std::string GetFormattedIdString(const std::string& data_store_id) { | |
| 79 return base::StringPrintf("%s%s%s", | |
|
Lei Zhang
2012/09/19 19:03:32
Please format this function call correctly. http:/
kmadhusu
2012/09/19 19:06:05
Done.
| |
| 80 chrome::kLeftParen, data_store_id.c_str(), | |
| 81 chrome::kRightParen); | |
| 82 } | |
| 83 | |
| 76 // Helper function to get device label from storage information. | 84 // Helper function to get device label from storage information. |
| 77 string16 GetDeviceLabelFromStorageInfo(const MtpStorageInfo& storage_info) { | 85 string16 GetDeviceLabelFromStorageInfo(const MtpStorageInfo& storage_info) { |
| 78 std::string device_label; | 86 std::string device_label; |
| 79 const std::string& vendor_name = storage_info.vendor(); | 87 const std::string& vendor_name = storage_info.vendor(); |
| 80 device_label = vendor_name; | 88 device_label = vendor_name; |
| 81 | 89 |
| 82 const std::string& product_name = storage_info.product(); | 90 const std::string& product_name = storage_info.product(); |
| 83 if (!product_name.empty()) { | 91 if (!product_name.empty()) { |
| 84 if (!device_label.empty()) | 92 if (!device_label.empty()) |
| 85 device_label += chrome::kSpaceDelim; | 93 device_label += chrome::kSpaceDelim; |
| 86 device_label += product_name; | 94 device_label += product_name; |
| 87 } | 95 } |
| 88 | 96 |
| 89 // Add the data store id to the device label. | 97 // Add the data store id to the device label. |
| 90 if (!device_label.empty()) { | 98 if (!device_label.empty()) { |
| 91 const std::string& volume_id = storage_info.volume_identifier(); | 99 const std::string& volume_id = storage_info.volume_identifier(); |
| 92 if (!volume_id.empty()) { | 100 if (!volume_id.empty()) { |
| 93 // TODO(kmadhusu): Use StringPrintf here and on line 98. | 101 device_label += GetFormattedIdString(volume_id); |
| 94 device_label += chrome::kLeftParen + volume_id + chrome::kRightParen; | |
| 95 } else { | 102 } else { |
| 96 const std::string data_store_id = | 103 const std::string data_store_id = |
| 97 GetStorageIdFromStorageName(storage_info.storage_name()); | 104 GetStorageIdFromStorageName(storage_info.storage_name()); |
| 98 if (!data_store_id.empty()) { | 105 if (!data_store_id.empty()) |
| 99 device_label += chrome::kLeftParen + data_store_id + | 106 device_label += GetFormattedIdString(data_store_id); |
| 100 chrome::kRightParen; | |
| 101 } | |
| 102 } | 107 } |
| 103 } | 108 } |
| 104 return UTF8ToUTF16(device_label); | 109 return UTF8ToUTF16(device_label); |
| 105 } | 110 } |
| 106 | 111 |
| 107 // Helper function to get the device storage details such as device id, label | 112 // Helper function to get the device storage details such as device id, label |
| 108 // and location. On success and fills in |id|, |label| and |location|. | 113 // and location. On success and fills in |id|, |label| and |location|. |
| 109 void GetStorageInfo(const std::string& storage_name, | 114 void GetStorageInfo(const std::string& storage_name, |
| 110 std::string* id, | 115 std::string* id, |
| 111 string16* label, | 116 string16* label, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 DCHECK(mtp_manager); | 251 DCHECK(mtp_manager); |
| 247 StorageList storages = mtp_manager->GetStorages(); | 252 StorageList storages = mtp_manager->GetStorages(); |
| 248 for (StorageList::const_iterator storage_iter = storages.begin(); | 253 for (StorageList::const_iterator storage_iter = storages.begin(); |
| 249 storage_iter != storages.end(); ++storage_iter) { | 254 storage_iter != storages.end(); ++storage_iter) { |
| 250 StorageChanged(true, *storage_iter); | 255 StorageChanged(true, *storage_iter); |
| 251 } | 256 } |
| 252 } | 257 } |
| 253 | 258 |
| 254 } // namespace mtp | 259 } // namespace mtp |
| 255 } // namespace chromeos | 260 } // namespace chromeos |
| OLD | NEW |