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..30f8190a7268d2e4935e2cf4a99ef40c6e0d5c50 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,26 +25,68 @@ RemovableDeviceNotificationsWindowWin* |
} // namespace |
+// RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications --------- |
Peter Kasting
2012/10/29 21:57:19
Why make this a separate class instead of simply p
kmadhusu
2012/10/30 01:29:24
Done. Removed this helper class. Made code changes
|
+class RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications { |
Peter Kasting
2012/10/29 21:57:19
Nit: Add blank line. Consider also adding a blank
kmadhusu
2012/10/30 01:29:24
-NA-
|
+ public: |
+ // Register window handle to receive portable device notifications details. |
Peter Kasting
2012/10/29 21:57:19
Nit: Register window handle -> Registers |hwnd|
kmadhusu
2012/10/30 01:29:24
Done.
|
+ explicit PortableDeviceNotifications(HWND hwnd); |
+ |
+ // Unregisters device notifications. |
+ ~PortableDeviceNotifications(); |
+ |
+ private: |
+ HDEVNOTIFY notifications_; |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(PortableDeviceNotifications); |
+}; |
+ |
+RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications:: |
+ PortableDeviceNotifications(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); |
+} |
+ |
+RemovableDeviceNotificationsWindowWin::PortableDeviceNotifications:: |
+ ~PortableDeviceNotifications() { |
+ UnregisterDeviceNotification(notifications_); |
+} |
+ |
+// RemovableDeviceNotificationsWindowWin implementaion ----------------------- |
Peter Kasting
2012/10/29 21:57:19
Nit: remove "implementation"
kmadhusu
2012/10/30 01:29:24
Done.
|
+ |
// static |
RemovableDeviceNotificationsWindowWin* |
-RemovableDeviceNotificationsWindowWin::Create() { |
- return new RemovableDeviceNotificationsWindowWin(new VolumeMountWatcherWin()); |
+ RemovableDeviceNotificationsWindowWin::Create() { |
+ return new RemovableDeviceNotificationsWindowWin( |
+ new VolumeMountWatcherWin(), new PortableDeviceWatcherWin()); |
} |
RemovableDeviceNotificationsWindowWin:: |
-RemovableDeviceNotificationsWindowWin( |
- VolumeMountWatcherWin* volume_mount_watcher) |
+ RemovableDeviceNotificationsWindowWin( |
+ 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; |
} |
RemovableDeviceNotificationsWindowWin:: |
-~RemovableDeviceNotificationsWindowWin() { |
+ ~RemovableDeviceNotificationsWindowWin() { |
if (window_) |
DestroyWindow(window_); |
@@ -58,18 +99,20 @@ RemovableDeviceNotificationsWindowWin:: |
// static |
RemovableDeviceNotificationsWindowWin* |
-RemovableDeviceNotificationsWindowWin::GetInstance() { |
+ RemovableDeviceNotificationsWindowWin::GetInstance() { |
DCHECK(g_removable_device_notifications_window_win); |
return g_removable_device_notifications_window_win; |
} |
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 +122,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 +139,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; |
@@ -153,6 +198,9 @@ LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProc( |
bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo( |
const FilePath& device_path, string16* device_location, |
std::string* unique_id, string16* name, bool* removable) { |
+ // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo() |
+ // function when we have the functionality to add a sub directory of |
+ // portable device as a media gallery. |
return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, |
unique_id, name, removable); |
} |
@@ -160,6 +208,7 @@ bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo( |
void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, |
LPARAM data) { |
volume_mount_watcher_->OnWindowMessage(event_type, data); |
+ portable_device_watcher_->OnWindowMessage(event_type, data); |
} |
} // namespace chrome |