Index: chrome/browser/system_monitor/removable_device_notifications_window_win.cc |
diff --git a/chrome/browser/system_monitor/removable_device_notifications_window_win.cc b/chrome/browser/system_monitor/removable_device_notifications_window_win.cc |
index 74250b9ba9b7fcdbd60b32d7ce2615fcc7342c4d..aead0254717ff5eaa15012d2ebc3fc8801a6ef51 100644 |
--- a/chrome/browser/system_monitor/removable_device_notifications_window_win.cc |
+++ b/chrome/browser/system_monitor/removable_device_notifications_window_win.cc |
@@ -8,12 +8,11 @@ |
#include <dbt.h> |
#include <fileapi.h> |
-#include "base/file_path.h" |
#include "base/win/wrapped_window_proc.h" |
#include "chrome/browser/system_monitor/media_storage_util.h" |
- |
-using base::SystemMonitor; |
-using base::win::WrappedWindowProc; |
+#include "chrome/browser/system_monitor/portable_device_watcher_win.h" |
+#include "chrome/browser/system_monitor/removable_device_constants.h" |
+#include "chrome/browser/system_monitor/volume_mount_watcher_win.h" |
namespace chrome { |
@@ -26,20 +25,71 @@ RemovableDeviceNotificationsWindowWin* |
} // namespace |
+// Manages portable device notification handle for |
+// RemovableDeviceNotificationsWindowWin. |
+class RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications { |
+ public: |
+ explicit PortableDeviceNotifications(HWND hwnd); |
+ ~PortableDeviceNotifications(); |
+ |
+ private: |
+ // Register window handle to receive portable device notifications details. |
vandebo (ex-Chrome)
2012/10/25 19:24:47
These helper routines make the class more complica
kmadhusu
2012/10/26 02:01:24
Done.
|
+ void Register(HWND hwnd); |
+ |
+ // Unregisters device notifications. |
+ void Unregister(); |
+ |
+ HDEVNOTIFY notifications_; |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(PortableDeviceNotifications); |
+}; |
+ |
+RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications:: |
+PortableDeviceNotifications(HWND hwnd) { |
+ Register(hwnd); |
+} |
+ |
+RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications:: |
+~PortableDeviceNotifications() { |
+ Unregister(); |
+} |
+ |
+void RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications:: |
+Register(HWND hwnd) { |
+ GUID dev_interface_guid = GUID_NULL; |
+ HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &dev_interface_guid); |
+ if (FAILED(hr)) |
+ return; |
+ DEV_BROADCAST_DEVICEINTERFACE db = {sizeof(DEV_BROADCAST_DEVICEINTERFACE), |
+ DBT_DEVTYP_DEVICEINTERFACE, 0, |
+ dev_interface_guid}; |
+ notifications_ = RegisterDeviceNotification(hwnd, &db, |
+ DEVICE_NOTIFY_WINDOW_HANDLE); |
+} |
+ |
+void RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications:: |
+Unregister() { |
+ UnregisterDeviceNotification(notifications_); |
+} |
+ |
// static |
RemovableDeviceNotificationsWindowWin* |
RemovableDeviceNotificationsWindowWin::Create() { |
- return new RemovableDeviceNotificationsWindowWin(new VolumeMountWatcherWin()); |
+ return new RemovableDeviceNotificationsWindowWin( |
+ new VolumeMountWatcherWin(), new PortableDeviceWatcherWin()); |
} |
RemovableDeviceNotificationsWindowWin:: |
RemovableDeviceNotificationsWindowWin( |
- VolumeMountWatcherWin* volume_mount_watcher) |
+ VolumeMountWatcherWin* volume_mount_watcher, |
+ PortableDeviceWatcherWin* portable_device_watcher) |
: window_class_(0), |
instance_(NULL), |
window_(NULL), |
- volume_mount_watcher_(volume_mount_watcher) { |
+ volume_mount_watcher_(volume_mount_watcher), |
+ portable_device_watcher_(portable_device_watcher) { |
DCHECK(volume_mount_watcher_); |
+ DCHECK(portable_device_watcher_); |
DCHECK(!g_removable_device_notifications_window_win); |
g_removable_device_notifications_window_win = this; |
} |
@@ -65,11 +115,13 @@ RemovableDeviceNotificationsWindowWin::GetInstance() { |
void RemovableDeviceNotificationsWindowWin::Init() { |
volume_mount_watcher_->Init(); |
+ portable_device_watcher_->Init(); |
WNDCLASSEX window_class; |
base::win::InitializeWindowClass( |
kWindowClassName, |
- &WrappedWindowProc<RemovableDeviceNotificationsWindowWin::WndProcThunk>, |
+ &base::win::WrappedWindowProc< |
+ RemovableDeviceNotificationsWindowWin::WndProcThunk>, |
0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
&window_class); |
instance_ = window_class.hInstance; |
@@ -79,6 +131,8 @@ void RemovableDeviceNotificationsWindowWin::Init() { |
window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, |
instance_, 0); |
SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); |
+ portable_device_notifications_.reset( |
+ new PortableDeviceNotifications(window_)); |
} |
bool RemovableDeviceNotificationsWindowWin::GetDeviceInfoForPath( |
@@ -94,11 +148,11 @@ bool RemovableDeviceNotificationsWindowWin::GetDeviceInfoForPath( |
// To compute the device id, the device type is needed. For removable |
// devices, that requires knowing if there's a DCIM directory, which would |
// require bouncing over to the file thread. Instead, just iterate the |
- // devices in SystemMonitor. |
+ // devices in base::SystemMonitor. |
std::string device_id; |
if (removable) { |
- std::vector<SystemMonitor::RemovableStorageInfo> attached_devices = |
- SystemMonitor::Get()->GetAttachedRemovableStorage(); |
+ std::vector<base::SystemMonitor::RemovableStorageInfo> attached_devices = |
+ base::SystemMonitor::Get()->GetAttachedRemovableStorage(); |
bool found = false; |
for (size_t i = 0; i < attached_devices.size(); i++) { |
MediaStorageUtil::Type type; |
@@ -154,12 +208,15 @@ bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo( |
const FilePath& device_path, string16* device_location, |
std::string* unique_id, string16* name, bool* removable) { |
return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, |
- unique_id, name, removable); |
+ unique_id, name, removable) || |
+ portable_device_watcher_->GetDeviceInfo(device_path, device_location, |
+ unique_id, name, removable); |
} |
void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, |
LPARAM data) { |
volume_mount_watcher_->OnWindowMessage(event_type, data); |
+ portable_device_watcher_->OnWindowMessage(event_type, data); |
} |
} // namespace chrome |