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

Side by Side Diff: chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.cc

Issue 12147002: Add a receiver interface to RemovableStorageNotifications. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 10 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
OLDNEW
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_ linux.h" 5 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_ linux.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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 StorageLocationToInfoMap::const_iterator info_it = 178 StorageLocationToInfoMap::const_iterator info_it =
179 storage_map_.find(GetDeviceLocationFromStorageName(path_components[1])); 179 storage_map_.find(GetDeviceLocationFromStorageName(path_components[1]));
180 if (info_it == storage_map_.end()) 180 if (info_it == storage_map_.end())
181 return false; 181 return false;
182 182
183 if (storage_info) 183 if (storage_info)
184 *storage_info = info_it->second; 184 *storage_info = info_it->second;
185 return true; 185 return true;
186 } 186 }
187 187
188 void MediaTransferProtocolDeviceObserverLinux::SetNotifications(
189 RemovableStorageNotifications::Receiver* notifications) {
190 notifications_ = notifications;
191 }
192
188 // device::MediaTransferProtocolManager::Observer override. 193 // device::MediaTransferProtocolManager::Observer override.
189 void MediaTransferProtocolDeviceObserverLinux::StorageChanged( 194 void MediaTransferProtocolDeviceObserverLinux::StorageChanged(
190 bool is_attached, 195 bool is_attached,
191 const std::string& storage_name) { 196 const std::string& storage_name) {
192 DCHECK(!storage_name.empty()); 197 DCHECK(!storage_name.empty());
193 198
194 RemovableStorageNotifications* notifications =
195 RemovableStorageNotifications::GetInstance();
196 DCHECK(notifications);
197
198 // New storage is attached. 199 // New storage is attached.
199 if (is_attached) { 200 if (is_attached) {
200 std::string device_id; 201 std::string device_id;
201 string16 device_name; 202 string16 device_name;
202 std::string location; 203 std::string location;
203 get_storage_info_func_(storage_name, &device_id, &device_name, &location); 204 get_storage_info_func_(storage_name, &device_id, &device_name, &location);
204 205
205 // 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
206 // empty values. 207 // empty values.
207 MediaStorageUtil::RecordDeviceInfoHistogram(false, device_id, device_name); 208 MediaStorageUtil::RecordDeviceInfoHistogram(false, device_id, device_name);
208 if (device_id.empty() || device_name.empty()) 209 if (device_id.empty() || device_name.empty())
209 return; 210 return;
210 211
211 DCHECK(!ContainsKey(storage_map_, location)); 212 DCHECK(!ContainsKey(storage_map_, location));
212 213
213 RemovableStorageNotifications::StorageInfo storage_info( 214 RemovableStorageNotifications::StorageInfo storage_info(
214 device_id, device_name, location); 215 device_id, device_name, location);
215 storage_map_[location] = storage_info; 216 storage_map_[location] = storage_info;
216 notifications->ProcessAttach(device_id, device_name, location); 217 if (notifications_)
vandebo (ex-Chrome) 2013/01/31 23:51:29 Why the condition? Should always be true, right?
Greg Billock 2013/02/01 18:28:42 Yes. This is defensive and mostly done for uniform
vandebo (ex-Chrome) 2013/02/01 18:59:55 If everything works without it, then lets go that
Greg Billock 2013/02/01 23:05:42 Done.
218 notifications_->ProcessAttach(storage_info);
217 } else { 219 } else {
218 // Existing storage is detached. 220 // Existing storage is detached.
219 StorageLocationToInfoMap::iterator it = 221 StorageLocationToInfoMap::iterator it =
220 storage_map_.find(GetDeviceLocationFromStorageName(storage_name)); 222 storage_map_.find(GetDeviceLocationFromStorageName(storage_name));
221 if (it == storage_map_.end()) 223 if (it == storage_map_.end())
222 return; 224 return;
223 notifications->ProcessDetach(it->second.device_id); 225 if (notifications_)
226 notifications_->ProcessDetach(it->second.device_id);
224 storage_map_.erase(it); 227 storage_map_.erase(it);
225 } 228 }
226 } 229 }
227 230
228 void MediaTransferProtocolDeviceObserverLinux::EnumerateStorages() { 231 void MediaTransferProtocolDeviceObserverLinux::EnumerateStorages() {
229 typedef std::vector<std::string> StorageList; 232 typedef std::vector<std::string> StorageList;
230 device::MediaTransferProtocolManager* mtp_manager = 233 device::MediaTransferProtocolManager* mtp_manager =
231 device::MediaTransferProtocolManager::GetInstance(); 234 device::MediaTransferProtocolManager::GetInstance();
232 StorageList storages = mtp_manager->GetStorages(); 235 StorageList storages = mtp_manager->GetStorages();
233 for (StorageList::const_iterator storage_iter = storages.begin(); 236 for (StorageList::const_iterator storage_iter = storages.begin();
234 storage_iter != storages.end(); ++storage_iter) { 237 storage_iter != storages.end(); ++storage_iter) {
235 StorageChanged(true, *storage_iter); 238 StorageChanged(true, *storage_iter);
236 } 239 }
237 } 240 }
238 241
239 } // namespace chrome 242 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698