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

Unified Diff: chrome/browser/system_monitor/removable_device_notifications_window_win.cc

Issue 11088012: [Win, MediaGallery] Enumerate and handle mtp device attach/detach events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 8 years, 2 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/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..8c6f2d0d649ada053bf41334c395ab254294211c 100644
--- a/chrome/browser/system_monitor/removable_device_notifications_window_win.cc
+++ b/chrome/browser/system_monitor/removable_device_notifications_window_win.cc
@@ -11,6 +11,7 @@
#include "base/file_path.h"
#include "base/win/wrapped_window_proc.h"
#include "chrome/browser/system_monitor/media_storage_util.h"
+#include "chrome/browser/system_monitor/removable_device_constants.h"
using base::SystemMonitor;
using base::win::WrappedWindowProc;
@@ -29,17 +30,21 @@ RemovableDeviceNotificationsWindowWin*
// 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,6 +70,7 @@ RemovableDeviceNotificationsWindowWin::GetInstance() {
void RemovableDeviceNotificationsWindowWin::Init() {
volume_mount_watcher_->Init();
+ portable_device_watcher_->Init();
WNDCLASSEX window_class;
base::win::InitializeWindowClass(
@@ -129,6 +135,21 @@ bool RemovableDeviceNotificationsWindowWin::GetDeviceInfoForPath(
// static
LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProcThunk(
HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
+ static HDEVNOTIFY hDeviceNotify;
Peter Kasting 2012/10/19 21:31:12 Overriding the WndProc and then looking for specif
kmadhusu 2012/10/23 23:44:17 Done. I used SystemMessageWindowWin::DeviceNotific
+ if (message == WM_CREATE) {
+ GUID guidDevInterface = GUID_NULL;
+ HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface);
+ if (SUCCEEDED(hr)) {
+ DEV_BROADCAST_DEVICEINTERFACE db = {0};
Peter Kasting 2012/10/19 21:31:12 Nit: Or just: DEV_BROADCAST_DEVICEINTERFACE
kmadhusu 2012/10/23 23:44:17 Done.
+ db.dbcc_size = sizeof(db);
+ db.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
+ db.dbcc_classguid = guidDevInterface;
+ hDeviceNotify = RegisterDeviceNotification(hwnd, &db,
+ DEVICE_NOTIFY_WINDOW_HANDLE);
+ }
+ } else if (message == WM_CLOSE) {
+ UnregisterDeviceNotification(hDeviceNotify);
+ }
RemovableDeviceNotificationsWindowWin* msg_wnd =
reinterpret_cast<RemovableDeviceNotificationsWindowWin*>(
GetWindowLongPtr(hwnd, GWLP_USERDATA));
@@ -153,13 +174,21 @@ LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProc(
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);
+ bool result = volume_mount_watcher_->GetDeviceInfo(device_path,
Peter Kasting 2012/10/19 21:31:12 Nit: Shorter: return volume_mount_watcher_->Get
kmadhusu 2012/10/23 23:44:17 Done.
+ device_location, unique_id,
+ name, removable);
+ if (!result) {
+ result = portable_device_watcher_->GetDeviceInfo(device_path,
+ device_location, unique_id,
+ name, removable);
+ }
+ return result;
}
void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type,
LPARAM data) {
volume_mount_watcher_->OnWindowMessage(event_type, data);
+ portable_device_watcher_->OnWindowMessage(event_type, data);
}
} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698