OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/storage_monitor/media_transfer_protocol_device_observer_lin
ux.h" | 5 #include "components/storage_monitor/media_transfer_protocol_device_observer_lin
ux.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const std::string data_store_id = | 87 const std::string data_store_id = |
88 GetStorageIdFromStorageName(storage_info.storage_name()); | 88 GetStorageIdFromStorageName(storage_info.storage_name()); |
89 if (!data_store_id.empty()) | 89 if (!data_store_id.empty()) |
90 device_label += GetFormattedIdString(data_store_id); | 90 device_label += GetFormattedIdString(data_store_id); |
91 } | 91 } |
92 } | 92 } |
93 return base::UTF8ToUTF16(device_label); | 93 return base::UTF8ToUTF16(device_label); |
94 } | 94 } |
95 | 95 |
96 // Helper function to get the device storage details such as device id, label | 96 // Helper function to get the device storage details such as device id, label |
97 // and location. On success and fills in |id|, |label| and |location|. | 97 // and location. On success and fills in |id|, |label|, |location|, |
| 98 // |vendor_name|, and |product_name|. |
98 void GetStorageInfo(const std::string& storage_name, | 99 void GetStorageInfo(const std::string& storage_name, |
99 device::MediaTransferProtocolManager* mtp_manager, | 100 device::MediaTransferProtocolManager* mtp_manager, |
100 std::string* id, | 101 std::string* id, |
101 base::string16* label, | 102 base::string16* label, |
102 std::string* location) { | 103 std::string* location, |
| 104 base::string16* vendor_name, |
| 105 base::string16* product_name) { |
103 DCHECK(!storage_name.empty()); | 106 DCHECK(!storage_name.empty()); |
104 const MtpStorageInfo* storage_info = | 107 const MtpStorageInfo* storage_info = |
105 mtp_manager->GetStorageInfo(storage_name); | 108 mtp_manager->GetStorageInfo(storage_name); |
106 | 109 |
107 if (!storage_info) | 110 if (!storage_info) |
108 return; | 111 return; |
109 | 112 |
110 *id = GetDeviceIdFromStorageInfo(*storage_info); | 113 *id = GetDeviceIdFromStorageInfo(*storage_info); |
111 *label = GetDeviceLabelFromStorageInfo(*storage_info); | 114 *label = GetDeviceLabelFromStorageInfo(*storage_info); |
112 *location = GetDeviceLocationFromStorageName(storage_name); | 115 *location = GetDeviceLocationFromStorageName(storage_name); |
| 116 *vendor_name = base::UTF8ToUTF16(storage_info->vendor()); |
| 117 *product_name = base::UTF8ToUTF16(storage_info->product()); |
113 } | 118 } |
114 | 119 |
115 } // namespace | 120 } // namespace |
116 | 121 |
117 MediaTransferProtocolDeviceObserverLinux:: | 122 MediaTransferProtocolDeviceObserverLinux:: |
118 MediaTransferProtocolDeviceObserverLinux( | 123 MediaTransferProtocolDeviceObserverLinux( |
119 StorageMonitor::Receiver* receiver, | 124 StorageMonitor::Receiver* receiver, |
120 device::MediaTransferProtocolManager* mtp_manager) | 125 device::MediaTransferProtocolManager* mtp_manager) |
121 : mtp_manager_(mtp_manager), | 126 : mtp_manager_(mtp_manager), |
122 get_storage_info_func_(&GetStorageInfo), | 127 get_storage_info_func_(&GetStorageInfo), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 void MediaTransferProtocolDeviceObserverLinux::StorageChanged( | 190 void MediaTransferProtocolDeviceObserverLinux::StorageChanged( |
186 bool is_attached, | 191 bool is_attached, |
187 const std::string& storage_name) { | 192 const std::string& storage_name) { |
188 DCHECK(!storage_name.empty()); | 193 DCHECK(!storage_name.empty()); |
189 | 194 |
190 // New storage is attached. | 195 // New storage is attached. |
191 if (is_attached) { | 196 if (is_attached) { |
192 std::string device_id; | 197 std::string device_id; |
193 base::string16 storage_label; | 198 base::string16 storage_label; |
194 std::string location; | 199 std::string location; |
| 200 base::string16 vendor_name; |
| 201 base::string16 product_name; |
195 get_storage_info_func_(storage_name, mtp_manager_, | 202 get_storage_info_func_(storage_name, mtp_manager_, |
196 &device_id, &storage_label, &location); | 203 &device_id, &storage_label, &location, |
| 204 &vendor_name, &product_name); |
197 | 205 |
198 // Keep track of device id and device name to see how often we receive | 206 // Keep track of device id and device name to see how often we receive |
199 // empty values. | 207 // empty values. |
200 MediaStorageUtil::RecordDeviceInfoHistogram(false, device_id, | 208 MediaStorageUtil::RecordDeviceInfoHistogram(false, device_id, |
201 storage_label); | 209 storage_label); |
202 if (device_id.empty() || storage_label.empty()) | 210 if (device_id.empty() || storage_label.empty()) |
203 return; | 211 return; |
204 | 212 |
205 DCHECK(!ContainsKey(storage_map_, location)); | 213 DCHECK(!ContainsKey(storage_map_, location)); |
206 | 214 |
207 StorageInfo storage_info(device_id, location, storage_label, | 215 StorageInfo storage_info(device_id, location, storage_label, |
208 base::string16(), base::string16(), 0); | 216 vendor_name, product_name, 0); |
209 storage_map_[location] = storage_info; | 217 storage_map_[location] = storage_info; |
210 notifications_->ProcessAttach(storage_info); | 218 notifications_->ProcessAttach(storage_info); |
211 } else { | 219 } else { |
212 // Existing storage is detached. | 220 // Existing storage is detached. |
213 StorageLocationToInfoMap::iterator it = | 221 StorageLocationToInfoMap::iterator it = |
214 storage_map_.find(GetDeviceLocationFromStorageName(storage_name)); | 222 storage_map_.find(GetDeviceLocationFromStorageName(storage_name)); |
215 if (it == storage_map_.end()) | 223 if (it == storage_map_.end()) |
216 return; | 224 return; |
217 notifications_->ProcessDetach(it->second.device_id()); | 225 notifications_->ProcessDetach(it->second.device_id()); |
218 storage_map_.erase(it); | 226 storage_map_.erase(it); |
(...skipping 16 matching lines...) Expand all Loading... |
235 if (it->second.device_id() == device_id) { | 243 if (it->second.device_id() == device_id) { |
236 *location = it->first; | 244 *location = it->first; |
237 return true; | 245 return true; |
238 } | 246 } |
239 } | 247 } |
240 | 248 |
241 return false; | 249 return false; |
242 } | 250 } |
243 | 251 |
244 } // namespace storage_monitor | 252 } // namespace storage_monitor |
OLD | NEW |