| OLD | NEW |
| 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/removable_device_notifications_window_wi
n.h" | 5 #include "chrome/browser/system_monitor/removable_device_notifications_window_wi
n.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <dbt.h> | 8 #include <dbt.h> |
| 9 #include <fileapi.h> | 9 #include <fileapi.h> |
| 10 | 10 |
| 11 #include "base/win/wrapped_window_proc.h" | 11 #include "base/win/wrapped_window_proc.h" |
| 12 #include "chrome/browser/system_monitor/media_storage_util.h" | 12 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 13 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" | 13 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" |
| 14 #include "chrome/browser/system_monitor/removable_device_constants.h" | 14 #include "chrome/browser/system_monitor/removable_device_constants.h" |
| 15 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" | 15 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" |
| 16 | 16 |
| 17 namespace chrome { | 17 namespace chrome { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const char16 kWindowClassName[] = L"Chrome_RemovableDeviceNotificationWindow"; | 21 const char16 kWindowClassName[] = L"Chrome_RemovableDeviceNotificationWindow"; |
| 22 | 22 |
| 23 RemovableDeviceNotificationsWindowWin* | |
| 24 g_removable_device_notifications_window_win = NULL; | |
| 25 | |
| 26 } // namespace | 23 } // namespace |
| 27 | 24 |
| 28 | 25 |
| 29 // RemovableDeviceNotificationsWindowWin -------------------------------------- | 26 // RemovableDeviceNotificationsWindowWin -------------------------------------- |
| 30 | 27 |
| 31 // static | 28 // static |
| 32 RemovableDeviceNotificationsWindowWin* | 29 RemovableDeviceNotificationsWindowWin* |
| 33 RemovableDeviceNotificationsWindowWin::Create() { | 30 RemovableDeviceNotificationsWindowWin::Create() { |
| 34 return new RemovableDeviceNotificationsWindowWin( | 31 return new RemovableDeviceNotificationsWindowWin( |
| 35 new VolumeMountWatcherWin(), new PortableDeviceWatcherWin()); | 32 new VolumeMountWatcherWin(), new PortableDeviceWatcherWin()); |
| 36 } | 33 } |
| 37 | 34 |
| 38 RemovableDeviceNotificationsWindowWin:: | 35 RemovableDeviceNotificationsWindowWin:: |
| 39 RemovableDeviceNotificationsWindowWin( | 36 RemovableDeviceNotificationsWindowWin( |
| 40 VolumeMountWatcherWin* volume_mount_watcher, | 37 VolumeMountWatcherWin* volume_mount_watcher, |
| 41 PortableDeviceWatcherWin* portable_device_watcher) | 38 PortableDeviceWatcherWin* portable_device_watcher) |
| 42 : window_class_(0), | 39 : window_class_(0), |
| 43 instance_(NULL), | 40 instance_(NULL), |
| 44 window_(NULL), | 41 window_(NULL), |
| 45 volume_mount_watcher_(volume_mount_watcher), | 42 volume_mount_watcher_(volume_mount_watcher), |
| 46 portable_device_watcher_(portable_device_watcher) { | 43 portable_device_watcher_(portable_device_watcher) { |
| 47 DCHECK(volume_mount_watcher_); | 44 DCHECK(volume_mount_watcher_); |
| 48 DCHECK(portable_device_watcher_); | 45 DCHECK(portable_device_watcher_); |
| 49 DCHECK(!g_removable_device_notifications_window_win); | |
| 50 g_removable_device_notifications_window_win = this; | |
| 51 } | 46 } |
| 52 | 47 |
| 53 RemovableDeviceNotificationsWindowWin:: | 48 RemovableDeviceNotificationsWindowWin:: |
| 54 ~RemovableDeviceNotificationsWindowWin() { | 49 ~RemovableDeviceNotificationsWindowWin() { |
| 55 if (window_) | 50 if (window_) |
| 56 DestroyWindow(window_); | 51 DestroyWindow(window_); |
| 57 | 52 |
| 58 if (window_class_) | 53 if (window_class_) |
| 59 UnregisterClass(MAKEINTATOM(window_class_), instance_); | 54 UnregisterClass(MAKEINTATOM(window_class_), instance_); |
| 60 | |
| 61 DCHECK_EQ(this, g_removable_device_notifications_window_win); | |
| 62 g_removable_device_notifications_window_win = NULL; | |
| 63 } | 55 } |
| 64 | 56 |
| 65 void RemovableDeviceNotificationsWindowWin::Init() { | 57 void RemovableDeviceNotificationsWindowWin::Init() { |
| 66 WNDCLASSEX window_class; | 58 WNDCLASSEX window_class; |
| 67 base::win::InitializeWindowClass( | 59 base::win::InitializeWindowClass( |
| 68 kWindowClassName, | 60 kWindowClassName, |
| 69 &base::win::WrappedWindowProc< | 61 &base::win::WrappedWindowProc< |
| 70 RemovableDeviceNotificationsWindowWin::WndProcThunk>, | 62 RemovableDeviceNotificationsWindowWin::WndProcThunk>, |
| 71 0, 0, 0, NULL, NULL, NULL, NULL, NULL, | 63 0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
| 72 &window_class); | 64 &window_class); |
| 73 instance_ = window_class.hInstance; | 65 instance_ = window_class.hInstance; |
| 74 window_class_ = RegisterClassEx(&window_class); | 66 window_class_ = RegisterClassEx(&window_class); |
| 75 DCHECK(window_class_); | 67 DCHECK(window_class_); |
| 76 | 68 |
| 77 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, | 69 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, |
| 78 instance_, 0); | 70 instance_, 0); |
| 79 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); | 71 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); |
| 80 volume_mount_watcher_->Init(); | 72 volume_mount_watcher_->Init(); |
| 81 portable_device_watcher_->Init(window_); | 73 portable_device_watcher_->Init(window_); |
| 82 } | 74 } |
| 83 | 75 |
| 84 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfoForPath( | 76 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfoForPath( |
| 85 const FilePath& path, | 77 const FilePath& path, |
| 86 base::SystemMonitor::RemovableStorageInfo* device_info) const { | 78 StorageInfo* device_info) const { |
| 87 string16 location; | 79 string16 location; |
| 88 std::string unique_id; | 80 std::string unique_id; |
| 89 string16 name; | 81 string16 name; |
| 90 bool removable; | 82 bool removable; |
| 91 if (!GetDeviceInfo(path, &location, &unique_id, &name, &removable)) | 83 if (!GetDeviceInfo(path, &location, &unique_id, &name, &removable)) |
| 92 return false; | 84 return false; |
| 93 | 85 |
| 94 // To compute the device id, the device type is needed. For removable | 86 // To compute the device id, the device type is needed. For removable |
| 95 // devices, that requires knowing if there's a DCIM directory, which would | 87 // devices, that requires knowing if there's a DCIM directory, which would |
| 96 // require bouncing over to the file thread. Instead, just iterate the | 88 // require bouncing over to the file thread. Instead, just iterate the |
| 97 // devices in base::SystemMonitor. | 89 // devices. |
| 98 std::string device_id; | 90 std::string device_id; |
| 99 if (removable) { | 91 if (removable) { |
| 100 std::vector<base::SystemMonitor::RemovableStorageInfo> attached_devices = | 92 std::vector<StorageInfo> attached_devices = GetAttachedStorage(); |
| 101 base::SystemMonitor::Get()->GetAttachedRemovableStorage(); | |
| 102 bool found = false; | 93 bool found = false; |
| 103 for (size_t i = 0; i < attached_devices.size(); i++) { | 94 for (size_t i = 0; i < attached_devices.size(); i++) { |
| 104 MediaStorageUtil::Type type; | 95 MediaStorageUtil::Type type; |
| 105 std::string id; | 96 std::string id; |
| 106 MediaStorageUtil::CrackDeviceId(attached_devices[i].device_id, &type, | 97 MediaStorageUtil::CrackDeviceId(attached_devices[i].device_id, &type, |
| 107 &id); | 98 &id); |
| 108 if (id == unique_id) { | 99 if (id == unique_id) { |
| 109 found = true; | 100 found = true; |
| 110 device_id = attached_devices[i].device_id; | 101 device_id = attached_devices[i].device_id; |
| 111 break; | 102 break; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, | 167 return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, |
| 177 unique_id, name, removable); | 168 unique_id, name, removable); |
| 178 } | 169 } |
| 179 | 170 |
| 180 void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, | 171 void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, |
| 181 LPARAM data) { | 172 LPARAM data) { |
| 182 volume_mount_watcher_->OnWindowMessage(event_type, data); | 173 volume_mount_watcher_->OnWindowMessage(event_type, data); |
| 183 portable_device_watcher_->OnWindowMessage(event_type, data); | 174 portable_device_watcher_->OnWindowMessage(event_type, data); |
| 184 } | 175 } |
| 185 | 176 |
| 186 // static | |
| 187 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() { | |
| 188 DCHECK(g_removable_device_notifications_window_win); | |
| 189 return g_removable_device_notifications_window_win; | |
| 190 } | |
| 191 | |
| 192 } // namespace chrome | 177 } // namespace chrome |
| OLD | NEW |