1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_WIN_H_
6 #define COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_WIN_H_
12 #include "components/storage_monitor/storage_monitor.h"
18 namespace storage_monitor {
20 class PortableDeviceWatcherWin;
21 class TestStorageMonitorWin;
22 class VolumeMountWatcherWin;
24 class StorageMonitorWin : public StorageMonitor {
26 // Should only be called by browser start up code.
27 // Use StorageMonitor::GetInstance() instead.
28 // To support unit tests, this constructor takes |volume_mount_watcher| and
29 // |portable_device_watcher| objects. These params are either constructed in
30 // unit tests or in StorageMonitorWin CreateInternal() function.
32 std::unique_ptr<VolumeMountWatcherWin> volume_mount_watcher,
33 std::unique_ptr<PortableDeviceWatcherWin> portable_device_watcher);
35 StorageMonitorWin(const StorageMonitorWin&) = delete;
36 StorageMonitorWin& operator=(const StorageMonitorWin&) = delete;
38 ~StorageMonitorWin() override;
40 // Must be called after the file thread is created.
44 bool GetStorageInfoForPath(const base::FilePath& path,
45 StorageInfo* device_info) const override;
46 bool GetMTPStorageInfoFromDeviceId(
47 const std::string& storage_device_id,
48 std::wstring* device_location,
49 std::wstring* storage_object_id) const override;
50 void EjectDevice(const std::string& device_id,
51 base::OnceCallback<void(EjectStatus)> callback) override;
54 class PortableDeviceNotifications;
55 friend class TestStorageMonitorWin;
57 void MediaChangeNotificationRegister();
59 // Gets the removable storage information given a |device_path|. On success,
60 // returns true and fills in |info|.
61 bool GetDeviceInfo(const base::FilePath& device_path,
62 StorageInfo* info) const;
64 static LRESULT CALLBACK WndProcThunk(HWND hwnd, UINT message, WPARAM wparam,
67 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam,
70 void OnDeviceChange(UINT event_type, LPARAM data);
71 void OnMediaChange(WPARAM wparam, LPARAM lparam);
73 // The window class of |window_|.
74 ATOM window_class_ = 0;
76 // The handle of the module that contains the window procedure of |window_|.
77 HMODULE instance_ = nullptr;
78 HWND window_ = nullptr;
80 // The handle of a registration for shell notifications.
81 ULONG shell_change_notify_id_ = 0;
83 // The volume mount point watcher, used to manage the mounted devices.
84 const std::unique_ptr<VolumeMountWatcherWin> volume_mount_watcher_;
86 // The portable device watcher, used to manage media transfer protocol
88 const std::unique_ptr<PortableDeviceWatcherWin> portable_device_watcher_;
91 } // namespace storage_monitor
93 #endif // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_WIN_H_