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 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_WINDOW_WIN_ H_ | 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_WINDOW_WIN_ H_ |
6 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_WINDOW_WIN_ H_ | 6 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_WINDOW_WIN_ H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <map> | |
10 #include <string> | 11 #include <string> |
12 #include <vector> | |
11 | 13 |
12 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
13 #include "base/file_path.h" | 15 #include "base/file_path.h" |
14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/system_monitor/system_monitor.h" | |
15 | 18 |
16 typedef LRESULT (*VolumeNameFunc)(LPCWSTR drive, | |
17 LPWSTR volume_name, | |
18 unsigned int volume_name_len); | |
19 namespace chrome { | 19 namespace chrome { |
20 | 20 |
21 // Gets device information given a |device_path|. On success, returns true and | |
22 // fills in |unique_id|, |name|, and |removable|. | |
23 typedef bool (*GetDeviceInfoFunc)(const FilePath& device, | |
24 std::wstring* location, | |
25 std::string* unique_id, | |
26 string16* name, | |
27 bool* removable); | |
28 | |
29 // Returns a vector of all the removable devices that are connected. | |
30 typedef std::vector<FilePath> (*GetAttachedDevicesFunc)(); | |
31 | |
21 class RemovableDeviceNotificationsWindowWin | 32 class RemovableDeviceNotificationsWindowWin |
rvargas (doing something else)
2012/09/15 02:33:55
even if the implementation uses a window (looks li
vandebo (ex-Chrome)
2012/09/15 19:45:10
I'll put it on my post 23 todo list.
| |
22 : public base::RefCountedThreadSafe<RemovableDeviceNotificationsWindowWin> { | 33 : public base::RefCountedThreadSafe<RemovableDeviceNotificationsWindowWin> { |
23 public: | 34 public: |
24 RemovableDeviceNotificationsWindowWin(); | 35 RemovableDeviceNotificationsWindowWin(); |
36 | |
37 static RemovableDeviceNotificationsWindowWin* GetInstance(); | |
38 | |
39 // Must be called after the file thread is created. | |
40 void Init(); | |
41 | |
42 // Finds the device that contains |path| and populates |device_info|. | |
43 // Returns false if unable to find the device. | |
44 bool GetDeviceInfoForPath( | |
45 const FilePath& path, | |
46 base::SystemMonitor::RemovableStorageInfo* device_info); | |
47 | |
48 protected: | |
25 // Only for use in unit tests. | 49 // Only for use in unit tests. |
26 explicit RemovableDeviceNotificationsWindowWin(VolumeNameFunc volumeNameFunc); | 50 void Init(GetDeviceInfoFunc getDeviceInfo, |
rvargas (doing something else)
2012/09/15 02:33:55
InitForTest
vandebo (ex-Chrome)
2012/09/15 19:45:10
Done.
| |
51 GetAttachedDevicesFunc getAttachedDevices); | |
27 | 52 |
28 LRESULT OnDeviceChange(UINT event_type, DWORD data); | 53 void OnDeviceChange(UINT event_type, DWORD data); |
29 | 54 |
30 private: | 55 private: |
31 friend class | 56 friend class |
32 base::RefCountedThreadSafe<RemovableDeviceNotificationsWindowWin>; | 57 base::RefCountedThreadSafe<RemovableDeviceNotificationsWindowWin>; |
58 friend class TestRemovableDeviceNotificationsWindowWin; | |
59 | |
60 typedef std::map<FilePath, std::string> MountPointDeviceIdMap; | |
33 | 61 |
34 virtual ~RemovableDeviceNotificationsWindowWin(); | 62 virtual ~RemovableDeviceNotificationsWindowWin(); |
35 | 63 |
36 void Init(); | 64 static LRESULT CALLBACK WndProcThunk(HWND hwnd, UINT message, WPARAM wparam, |
65 LPARAM lparam); | |
37 | 66 |
38 LRESULT CALLBACK WndProc(HWND hwnd, | 67 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, |
39 UINT message, | |
40 WPARAM wparam, | |
41 LPARAM lparam); | 68 LPARAM lparam); |
42 | 69 |
43 static LRESULT CALLBACK WndProcThunk(HWND hwnd, | 70 void DoInit(GetAttachedDevicesFunc get_attached_devices_func); |
44 UINT message, | |
45 WPARAM wparam, | |
46 LPARAM lparam); | |
47 | 71 |
48 void CheckDeviceTypeOnFileThread(const std::string& id, | 72 void AddNewDevice(const FilePath& device_path); |
73 | |
74 void CheckDeviceTypeOnFileThread(const std::string& unique_id, | |
49 const FilePath::StringType& device_name, | 75 const FilePath::StringType& device_name, |
50 const FilePath& path); | 76 const FilePath& device); |
51 | 77 |
52 void ProcessRemovableDeviceAttachedOnUIThread( | 78 void ProcessDeviceAttachedOnUIThread( |
53 const std::string& id, | 79 const std::string& device_id, |
54 const FilePath::StringType& device_name, | 80 const FilePath::StringType& device_name, |
55 const FilePath& path); | 81 const FilePath& device); |
56 | 82 |
57 // The window class of |window_|. | 83 // The window class of |window_|. |
58 ATOM atom_; | 84 ATOM window_class_; |
59 | |
60 // The handle of the module that contains the window procedure of |window_|. | 85 // The handle of the module that contains the window procedure of |window_|. |
61 HMODULE instance_; | 86 HMODULE instance_; |
87 HWND window_; | |
62 | 88 |
63 HWND window_; | 89 GetDeviceInfoFunc get_device_info_func_; |
64 VolumeNameFunc volume_name_func_; | 90 |
91 // A map from device mount point to device id. Only accessed on the UI Thread. | |
92 MountPointDeviceIdMap device_ids_; | |
65 | 93 |
66 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsWindowWin); | 94 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsWindowWin); |
67 }; | 95 }; |
68 | 96 |
69 } // namespace chrome | 97 } // namespace chrome |
70 | 98 |
71 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_WINDOW_W IN_H_ | 99 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_WINDOW_W IN_H_ |
OLD | NEW |