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

Unified Diff: chrome/browser/system_monitor/portable_device_watcher_win.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, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/system_monitor/portable_device_watcher_win.cc
diff --git a/chrome/browser/system_monitor/portable_device_watcher_win.cc b/chrome/browser/system_monitor/portable_device_watcher_win.cc
index 2e1e0c34b9fe2bc5de7100a27f0013bbd3161989..83504d674ad9fac98799d99a3c7b1eb8ac2b5876 100644
--- a/chrome/browser/system_monitor/portable_device_watcher_win.cc
+++ b/chrome/browser/system_monitor/portable_device_watcher_win.cc
@@ -479,6 +479,7 @@ PortableDeviceWatcherWin::DeviceStorageObject::DeviceStorageObject(
PortableDeviceWatcherWin::PortableDeviceWatcherWin()
: notifications_(NULL),
+ storage_notifications_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
}
@@ -546,6 +547,11 @@ string16 PortableDeviceWatcherWin::GetStoragePathFromStorageId(
return UTF8ToUTF16("\\\\" + storage_unique_id);
}
+void PortableDeviceWatcherWin::SetNotifications(
+ RemovableStorageNotifications::Receiver* notifications) {
+ storage_notifications_ = notifications;
+}
+
void PortableDeviceWatcherWin::EnumerateAttachedDevices() {
DCHECK(media_task_runner_.get());
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
@@ -595,9 +601,6 @@ void PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent(
const string16& name = device_details->name;
const string16& location = device_details->location;
DCHECK(!ContainsKey(device_map_, location));
- RemovableStorageNotifications* notifications =
- RemovableStorageNotifications::GetInstance();
- DCHECK(notifications);
for (StorageObjects::const_iterator storage_iter = storage_objects.begin();
storage_iter != storage_objects.end(); ++storage_iter) {
const std::string& storage_id = storage_iter->object_persistent_id;
@@ -615,8 +618,12 @@ void PortableDeviceWatcherWin::OnDidHandleDeviceAttachEvent(
L')');
storage_map_[storage_id] = RemovableStorageNotifications::StorageInfo(
storage_id, storage_name, location);
- notifications->ProcessAttach(
- storage_id, storage_name, GetStoragePathFromStorageId(storage_id));
+ if (storage_notifications_) {
+ storage_notifications_->ProcessAttach(
+ RemovableStorageNotifications::StorageInfo(
+ storage_id, storage_name,
+ GetStoragePathFromStorageId(storage_id)));
+ }
}
device_map_[location] = storage_objects;
}
@@ -628,10 +635,6 @@ void PortableDeviceWatcherWin::HandleDeviceDetachEvent(
if (device_iter == device_map_.end())
return;
- RemovableStorageNotifications* notifications =
- RemovableStorageNotifications::GetInstance();
- DCHECK(notifications);
-
const StorageObjects& storage_objects = device_iter->second;
for (StorageObjects::const_iterator storage_object_iter =
storage_objects.begin(); storage_object_iter != storage_objects.end();
@@ -639,7 +642,8 @@ void PortableDeviceWatcherWin::HandleDeviceDetachEvent(
std::string storage_id = storage_object_iter->object_persistent_id;
MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id);
DCHECK(storage_map_iter != storage_map_.end());
- notifications->ProcessDetach(storage_map_iter->second.device_id);
+ if (storage_notifications_)
+ storage_notifications_->ProcessDetach(storage_map_iter->second.device_id);
storage_map_.erase(storage_map_iter);
}
device_map_.erase(device_iter);

Powered by Google App Engine
This is Rietveld 408576698