Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / storage_monitor / storage_monitor_win.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_WIN_H_
6 #define COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_WIN_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "components/storage_monitor/storage_monitor.h"
12
13 namespace base {
14 class FilePath;
15 }
16
17 namespace storage_monitor {
18
19 class PortableDeviceWatcherWin;
20 class TestStorageMonitorWin;
21 class VolumeMountWatcherWin;
22
23 class StorageMonitorWin : public StorageMonitor {
24  public:
25   // Should only be called by browser start up code.
26   // Use StorageMonitor::GetInstance() instead.
27   // To support unit tests, this constructor takes |volume_mount_watcher| and
28   // |portable_device_watcher| objects. These params are either constructed in
29   // unit tests or in StorageMonitorWin CreateInternal() function.
30   StorageMonitorWin(VolumeMountWatcherWin* volume_mount_watcher,
31                     PortableDeviceWatcherWin* portable_device_watcher);
32   virtual ~StorageMonitorWin();
33
34   // Must be called after the file thread is created.
35   virtual void Init() override;
36
37   // StorageMonitor:
38   virtual bool GetStorageInfoForPath(const base::FilePath& path,
39                                      StorageInfo* device_info) const override;
40   virtual bool GetMTPStorageInfoFromDeviceId(
41       const std::string& storage_device_id,
42       base::string16* device_location,
43       base::string16* storage_object_id) const override;
44
45   virtual void EjectDevice(
46       const std::string& device_id,
47       base::Callback<void(EjectStatus)> callback) override;
48
49  private:
50   class PortableDeviceNotifications;
51   friend class TestStorageMonitorWin;
52
53   void MediaChangeNotificationRegister();
54
55   // Gets the removable storage information given a |device_path|. On success,
56   // returns true and fills in |info|.
57   bool GetDeviceInfo(const base::FilePath& device_path,
58                      StorageInfo* info) const;
59
60   static LRESULT CALLBACK WndProcThunk(HWND hwnd, UINT message, WPARAM wparam,
61                                        LPARAM lparam);
62
63   LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam,
64                            LPARAM lparam);
65
66   void OnDeviceChange(UINT event_type, LPARAM data);
67   void OnMediaChange(WPARAM wparam, LPARAM lparam);
68
69   // The window class of |window_|.
70   ATOM window_class_;
71
72   // The handle of the module that contains the window procedure of |window_|.
73   HMODULE instance_;
74   HWND window_;
75
76   // The handle of a registration for shell notifications.
77   ULONG shell_change_notify_id_;
78
79   // The volume mount point watcher, used to manage the mounted devices.
80   scoped_ptr<VolumeMountWatcherWin> volume_mount_watcher_;
81
82   // The portable device watcher, used to manage media transfer protocol
83   // devices.
84   scoped_ptr<PortableDeviceWatcherWin> portable_device_watcher_;
85
86   DISALLOW_COPY_AND_ASSIGN(StorageMonitorWin);
87 };
88
89 }  // namespace storage_monitor
90
91 #endif  // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_WIN_H_