Index: chrome/browser/system_monitor/removable_device_notifications_window_win.h |
diff --git a/chrome/browser/system_monitor/removable_device_notifications_window_win.h b/chrome/browser/system_monitor/removable_device_notifications_window_win.h |
index 9251fad6dee1ed581fb5eb577a32c5d4e07a76d6..50f7bdb19c14333fee36fa37f60bd9be13dde8bc 100644 |
--- a/chrome/browser/system_monitor/removable_device_notifications_window_win.h |
+++ b/chrome/browser/system_monitor/removable_device_notifications_window_win.h |
@@ -7,64 +7,96 @@ |
#include <windows.h> |
+#include <map> |
#include <string> |
+#include <vector> |
#include "base/basictypes.h" |
#include "base/file_path.h" |
#include "base/memory/ref_counted.h" |
+#include "base/string16.h" |
+#include "base/system_monitor/system_monitor.h" |
-typedef LRESULT (*VolumeNameFunc)(LPCWSTR drive, |
- LPWSTR volume_name, |
- unsigned int volume_name_len); |
namespace chrome { |
+// Gets device information given a |device_path|. On success, returns true and |
+// fills in |unique_id|, |name|, and |removable|. |
+typedef bool (*GetDeviceInfoFunc)(const FilePath& device, |
+ string16* location, |
+ std::string* unique_id, |
+ string16* name, |
+ bool* removable); |
+ |
+// Returns a vector of all the removable devices that are connected. |
+typedef std::vector<FilePath> (*GetAttachedDevicesFunc)(); |
+ |
class RemovableDeviceNotificationsWindowWin; |
typedef RemovableDeviceNotificationsWindowWin RemovableDeviceNotifications; |
class RemovableDeviceNotificationsWindowWin |
: public base::RefCountedThreadSafe<RemovableDeviceNotificationsWindowWin> { |
public: |
+ // Should only be called by browser start up code. Use GetInstance() instead. |
RemovableDeviceNotificationsWindowWin(); |
+ |
+ // base::SystemMonitor has a lifetime somewhat shorter than a Singleton and |
+ // |this| is constructed/destroyed just after/before SystemMonitor. |
+ static RemovableDeviceNotificationsWindowWin* GetInstance(); |
+ |
+ // Must be called after the file thread is created. |
+ void Init(); |
+ |
+ // Finds the device that contains |path| and populates |device_info|. |
+ // Returns false if unable to find the device. |
+ bool GetDeviceInfoForPath( |
+ const FilePath& path, |
+ base::SystemMonitor::RemovableStorageInfo* device_info); |
+ |
+ protected: |
// Only for use in unit tests. |
- explicit RemovableDeviceNotificationsWindowWin(VolumeNameFunc volumeNameFunc); |
+ void InitForTest(GetDeviceInfoFunc getDeviceInfo, |
+ GetAttachedDevicesFunc getAttachedDevices); |
- LRESULT OnDeviceChange(UINT event_type, DWORD data); |
+ void OnDeviceChange(UINT event_type, LPARAM data); |
private: |
friend class |
base::RefCountedThreadSafe<RemovableDeviceNotificationsWindowWin>; |
+ friend class TestRemovableDeviceNotificationsWindowWin; |
+ |
+ typedef std::map<FilePath, std::string> MountPointDeviceIdMap; |
virtual ~RemovableDeviceNotificationsWindowWin(); |
- void Init(); |
+ static LRESULT CALLBACK WndProcThunk(HWND hwnd, UINT message, WPARAM wparam, |
+ LPARAM lparam); |
- LRESULT CALLBACK WndProc(HWND hwnd, |
- UINT message, |
- WPARAM wparam, |
+ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, |
LPARAM lparam); |
- static LRESULT CALLBACK WndProcThunk(HWND hwnd, |
- UINT message, |
- WPARAM wparam, |
- LPARAM lparam); |
+ void DoInit(GetAttachedDevicesFunc get_attached_devices_func); |
+ |
+ void AddNewDevice(const FilePath& device_path); |
- void CheckDeviceTypeOnFileThread(const std::string& id, |
+ void CheckDeviceTypeOnFileThread(const std::string& unique_id, |
const FilePath::StringType& device_name, |
- const FilePath& path); |
+ const FilePath& device); |
- void ProcessRemovableDeviceAttachedOnUIThread( |
- const std::string& id, |
+ void ProcessDeviceAttachedOnUIThread( |
+ const std::string& device_id, |
const FilePath::StringType& device_name, |
- const FilePath& path); |
+ const FilePath& device); |
// The window class of |window_|. |
- ATOM atom_; |
- |
+ ATOM window_class_; |
// The handle of the module that contains the window procedure of |window_|. |
HMODULE instance_; |
- |
HWND window_; |
- VolumeNameFunc volume_name_func_; |
+ |
+ GetDeviceInfoFunc get_device_info_func_; |
+ |
+ // A map from device mount point to device id. Only accessed on the UI Thread. |
+ MountPointDeviceIdMap device_ids_; |
DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsWindowWin); |
}; |