Upstream version 5.34.104.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 class PortableDeviceWatcherWin;
18 class TestStorageMonitorWin;
19 class VolumeMountWatcherWin;
20
21 class StorageMonitorWin : public StorageMonitor {
22  public:
23   // Should only be called by browser start up code.
24   // Use StorageMonitor::GetInstance() instead.
25   // To support unit tests, this constructor takes |volume_mount_watcher| and
26   // |portable_device_watcher| objects. These params are either constructed in
27   // unit tests or in StorageMonitorWin CreateInternal() function.
28   StorageMonitorWin(VolumeMountWatcherWin* volume_mount_watcher,
29                     PortableDeviceWatcherWin* portable_device_watcher);
30   virtual ~StorageMonitorWin();
31
32   // Must be called after the file thread is created.
33   virtual void Init() OVERRIDE;
34
35   // StorageMonitor:
36   virtual bool GetStorageInfoForPath(const base::FilePath& path,
37                                      StorageInfo* device_info) const OVERRIDE;
38   virtual bool GetMTPStorageInfoFromDeviceId(
39       const std::string& storage_device_id,
40       base::string16* device_location,
41       base::string16* storage_object_id) const OVERRIDE;
42
43   virtual void EjectDevice(
44       const std::string& device_id,
45       base::Callback<void(EjectStatus)> callback) OVERRIDE;
46
47  private:
48   class PortableDeviceNotifications;
49   friend class TestStorageMonitorWin;
50
51   // Gets the removable storage information given a |device_path|. On success,
52   // returns true and fills in |info|.
53   bool GetDeviceInfo(const base::FilePath& device_path,
54                      StorageInfo* info) const;
55
56   static LRESULT CALLBACK WndProcThunk(HWND hwnd, UINT message, WPARAM wparam,
57                                        LPARAM lparam);
58
59   LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam,
60                            LPARAM lparam);
61
62   void OnDeviceChange(UINT event_type, LPARAM data);
63
64   // The window class of |window_|.
65   ATOM window_class_;
66
67   // The handle of the module that contains the window procedure of |window_|.
68   HMODULE instance_;
69   HWND window_;
70
71   // The volume mount point watcher, used to manage the mounted devices.
72   scoped_ptr<VolumeMountWatcherWin> volume_mount_watcher_;
73
74   // The portable device watcher, used to manage media transfer protocol
75   // devices.
76   scoped_ptr<PortableDeviceWatcherWin> portable_device_watcher_;
77
78   DISALLOW_COPY_AND_ASSIGN(StorageMonitorWin);
79 };
80
81 #endif  // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_WIN_H_