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/file_path.h" | |
Lei Zhang
2012/10/30 22:46:03
FilePath is used here though. Undelete?
kmadhusu
2012/10/30 23:00:16
I am just forwarding the file path reference param
| |
12 #include "base/win/wrapped_window_proc.h" | 11 #include "base/win/wrapped_window_proc.h" |
13 #include "chrome/browser/system_monitor/media_storage_util.h" | 12 #include "chrome/browser/system_monitor/media_storage_util.h" |
14 | 13 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" |
15 using base::SystemMonitor; | 14 #include "chrome/browser/system_monitor/removable_device_constants.h" |
16 using base::win::WrappedWindowProc; | 15 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" |
17 | 16 |
18 namespace chrome { | 17 namespace chrome { |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 const char16 kWindowClassName[] = L"Chrome_RemovableDeviceNotificationWindow"; | 21 const char16 kWindowClassName[] = L"Chrome_RemovableDeviceNotificationWindow"; |
23 | 22 |
24 RemovableDeviceNotificationsWindowWin* | 23 RemovableDeviceNotificationsWindowWin* |
25 g_removable_device_notifications_window_win = NULL; | 24 g_removable_device_notifications_window_win = NULL; |
26 | 25 |
27 } // namespace | 26 } // namespace |
28 | 27 |
28 | |
29 // RemovableDeviceNotificationsWindowWin -------------------------------------- | |
30 | |
29 // static | 31 // static |
30 RemovableDeviceNotificationsWindowWin* | 32 RemovableDeviceNotificationsWindowWin* |
31 RemovableDeviceNotificationsWindowWin::Create() { | 33 RemovableDeviceNotificationsWindowWin::Create() { |
32 return new RemovableDeviceNotificationsWindowWin(new VolumeMountWatcherWin()); | 34 return new RemovableDeviceNotificationsWindowWin( |
35 new VolumeMountWatcherWin(), new PortableDeviceWatcherWin()); | |
33 } | 36 } |
34 | 37 |
35 RemovableDeviceNotificationsWindowWin:: | 38 RemovableDeviceNotificationsWindowWin:: |
36 RemovableDeviceNotificationsWindowWin( | 39 RemovableDeviceNotificationsWindowWin( |
37 VolumeMountWatcherWin* volume_mount_watcher) | 40 VolumeMountWatcherWin* volume_mount_watcher, |
41 PortableDeviceWatcherWin* portable_device_watcher) | |
38 : window_class_(0), | 42 : window_class_(0), |
39 instance_(NULL), | 43 instance_(NULL), |
40 window_(NULL), | 44 window_(NULL), |
41 volume_mount_watcher_(volume_mount_watcher) { | 45 volume_mount_watcher_(volume_mount_watcher), |
46 portable_device_watcher_(portable_device_watcher) { | |
42 DCHECK(volume_mount_watcher_); | 47 DCHECK(volume_mount_watcher_); |
48 DCHECK(portable_device_watcher_); | |
43 DCHECK(!g_removable_device_notifications_window_win); | 49 DCHECK(!g_removable_device_notifications_window_win); |
44 g_removable_device_notifications_window_win = this; | 50 g_removable_device_notifications_window_win = this; |
45 } | 51 } |
46 | 52 |
47 RemovableDeviceNotificationsWindowWin:: | 53 RemovableDeviceNotificationsWindowWin:: |
48 ~RemovableDeviceNotificationsWindowWin() { | 54 ~RemovableDeviceNotificationsWindowWin() { |
49 if (window_) | 55 if (window_) |
50 DestroyWindow(window_); | 56 DestroyWindow(window_); |
51 | 57 |
52 if (window_class_) | 58 if (window_class_) |
53 UnregisterClass(MAKEINTATOM(window_class_), instance_); | 59 UnregisterClass(MAKEINTATOM(window_class_), instance_); |
54 | 60 |
55 DCHECK_EQ(this, g_removable_device_notifications_window_win); | 61 DCHECK_EQ(this, g_removable_device_notifications_window_win); |
56 g_removable_device_notifications_window_win = NULL; | 62 g_removable_device_notifications_window_win = NULL; |
57 } | 63 } |
58 | 64 |
59 // static | 65 // static |
60 RemovableDeviceNotificationsWindowWin* | 66 RemovableDeviceNotificationsWindowWin* |
61 RemovableDeviceNotificationsWindowWin::GetInstance() { | 67 RemovableDeviceNotificationsWindowWin::GetInstance() { |
62 DCHECK(g_removable_device_notifications_window_win); | 68 DCHECK(g_removable_device_notifications_window_win); |
63 return g_removable_device_notifications_window_win; | 69 return g_removable_device_notifications_window_win; |
64 } | 70 } |
65 | 71 |
66 void RemovableDeviceNotificationsWindowWin::Init() { | 72 void RemovableDeviceNotificationsWindowWin::Init() { |
67 volume_mount_watcher_->Init(); | |
68 | |
69 WNDCLASSEX window_class; | 73 WNDCLASSEX window_class; |
70 base::win::InitializeWindowClass( | 74 base::win::InitializeWindowClass( |
71 kWindowClassName, | 75 kWindowClassName, |
72 &WrappedWindowProc<RemovableDeviceNotificationsWindowWin::WndProcThunk>, | 76 &base::win::WrappedWindowProc< |
77 RemovableDeviceNotificationsWindowWin::WndProcThunk>, | |
73 0, 0, 0, NULL, NULL, NULL, NULL, NULL, | 78 0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
74 &window_class); | 79 &window_class); |
75 instance_ = window_class.hInstance; | 80 instance_ = window_class.hInstance; |
76 window_class_ = RegisterClassEx(&window_class); | 81 window_class_ = RegisterClassEx(&window_class); |
77 DCHECK(window_class_); | 82 DCHECK(window_class_); |
78 | 83 |
79 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, | 84 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, |
80 instance_, 0); | 85 instance_, 0); |
81 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); | 86 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); |
87 volume_mount_watcher_->Init(); | |
88 portable_device_watcher_->Init(window_); | |
82 } | 89 } |
83 | 90 |
84 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfoForPath( | 91 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfoForPath( |
85 const FilePath& path, | 92 const FilePath& path, |
86 base::SystemMonitor::RemovableStorageInfo* device_info) { | 93 base::SystemMonitor::RemovableStorageInfo* device_info) { |
87 string16 location; | 94 string16 location; |
88 std::string unique_id; | 95 std::string unique_id; |
89 string16 name; | 96 string16 name; |
90 bool removable; | 97 bool removable; |
91 if (!GetDeviceInfo(path, &location, &unique_id, &name, &removable)) | 98 if (!GetDeviceInfo(path, &location, &unique_id, &name, &removable)) |
92 return false; | 99 return false; |
93 | 100 |
94 // To compute the device id, the device type is needed. For removable | 101 // 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 | 102 // devices, that requires knowing if there's a DCIM directory, which would |
96 // require bouncing over to the file thread. Instead, just iterate the | 103 // require bouncing over to the file thread. Instead, just iterate the |
97 // devices in SystemMonitor. | 104 // devices in base::SystemMonitor. |
98 std::string device_id; | 105 std::string device_id; |
99 if (removable) { | 106 if (removable) { |
100 std::vector<SystemMonitor::RemovableStorageInfo> attached_devices = | 107 std::vector<base::SystemMonitor::RemovableStorageInfo> attached_devices = |
101 SystemMonitor::Get()->GetAttachedRemovableStorage(); | 108 base::SystemMonitor::Get()->GetAttachedRemovableStorage(); |
102 bool found = false; | 109 bool found = false; |
103 for (size_t i = 0; i < attached_devices.size(); i++) { | 110 for (size_t i = 0; i < attached_devices.size(); i++) { |
104 MediaStorageUtil::Type type; | 111 MediaStorageUtil::Type type; |
105 std::string id; | 112 std::string id; |
106 MediaStorageUtil::CrackDeviceId(attached_devices[i].device_id, &type, | 113 MediaStorageUtil::CrackDeviceId(attached_devices[i].device_id, &type, |
107 &id); | 114 &id); |
108 if (id == unique_id) { | 115 if (id == unique_id) { |
109 found = true; | 116 found = true; |
110 device_id = attached_devices[i].device_id; | 117 device_id = attached_devices[i].device_id; |
111 break; | 118 break; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 default: | 153 default: |
147 break; | 154 break; |
148 } | 155 } |
149 | 156 |
150 return ::DefWindowProc(hwnd, message, wparam, lparam); | 157 return ::DefWindowProc(hwnd, message, wparam, lparam); |
151 } | 158 } |
152 | 159 |
153 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo( | 160 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo( |
154 const FilePath& device_path, string16* device_location, | 161 const FilePath& device_path, string16* device_location, |
155 std::string* unique_id, string16* name, bool* removable) { | 162 std::string* unique_id, string16* name, bool* removable) { |
163 // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo() | |
164 // function when we have the functionality to add a sub directory of | |
165 // portable device as a media gallery. | |
156 return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, | 166 return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, |
157 unique_id, name, removable); | 167 unique_id, name, removable); |
158 } | 168 } |
159 | 169 |
160 void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, | 170 void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, |
161 LPARAM data) { | 171 LPARAM data) { |
162 volume_mount_watcher_->OnWindowMessage(event_type, data); | 172 volume_mount_watcher_->OnWindowMessage(event_type, data); |
173 portable_device_watcher_->OnWindowMessage(event_type, data); | |
163 } | 174 } |
164 | 175 |
165 } // namespace chrome | 176 } // namespace chrome |
OLD | NEW |