Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: chrome/browser/system_monitor/volume_mount_watcher_win.h

Issue 12147002: Add a receiver interface to RemovableStorageNotifications. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_VOLUME_MOUNT_WATCHER_WIN_H_ 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_
6 #define CHROME_BROWSER_SYSTEM_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ 6 #define CHROME_BROWSER_SYSTEM_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/string16.h" 17 #include "base/string16.h"
18 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
19 19
20 namespace chrome { 20 namespace chrome {
21 21
22 // This class watches the volume mount points and sends notifications to 22 // This class watches the volume mount points and sends notifications to
23 // base::SystemMonitor about the device attach/detach events. This is a 23 // RemovableStorageNotifications about the device attach/detach events.
24 // singleton class instantiated by RemovableDeviceNotificationsWindowWin. 24 // This is a singleton class instantiated by
25 // RemovableDeviceNotificationsWindowWin.
25 class VolumeMountWatcherWin { 26 class VolumeMountWatcherWin {
26 public: 27 public:
27 // TODO(gbillock): Take the RemovableStorageNotifications as an argument.
28 VolumeMountWatcherWin(); 28 VolumeMountWatcherWin();
29 virtual ~VolumeMountWatcherWin(); 29 virtual ~VolumeMountWatcherWin();
30 30
31 // Returns the volume file path of the drive specified by the |drive_number|. 31 // Returns the volume file path of the drive specified by the |drive_number|.
32 // |drive_number| inputs of 0 - 25 are valid. Returns an empty file path if 32 // |drive_number| inputs of 0 - 25 are valid. Returns an empty file path if
33 // the |drive_number| is invalid. 33 // the |drive_number| is invalid.
34 static FilePath DriveNumberToFilePath(int drive_number); 34 static FilePath DriveNumberToFilePath(int drive_number);
35 35
36 void Init(); 36 void Init();
37 37
38 // Gets the information about the device mounted at |device_path|. On success, 38 // Gets the information about the device mounted at |device_path|. On success,
39 // returns true and fills in |location|, |unique_id|, |name|, and |removable|. 39 // returns true and fills in |location|, |unique_id|, |name|, and |removable|.
40 // Can block during startup while device info is still loading. 40 // Can block during startup while device info is still loading.
41 virtual bool GetDeviceInfo(const FilePath& device_path, 41 virtual bool GetDeviceInfo(const FilePath& device_path,
42 string16* location, 42 string16* location,
43 std::string* unique_id, 43 std::string* unique_id,
44 string16* name, 44 string16* name,
45 bool* removable) const; 45 bool* removable) const;
46 46
47 // Processes DEV_BROADCAST_VOLUME messages and triggers a 47 // Processes DEV_BROADCAST_VOLUME messages and triggers a
48 // notification if appropriate. 48 // notification if appropriate.
49 void OnWindowMessage(UINT event_type, LPARAM data); 49 void OnWindowMessage(UINT event_type, LPARAM data);
50 50
51 // Set the volume notifications object to be used when new
52 // removable volumes are found.
53 void SetNotifications(RemovableStorageNotifications::Receiver* notifications);
54
51 protected: 55 protected:
52 struct MountPointInfo { 56 struct MountPointInfo {
53 std::string device_id; 57 std::string device_id;
54 string16 location; 58 string16 location;
55 std::string unique_id; 59 std::string unique_id;
56 string16 name; 60 string16 name;
57 bool removable; 61 bool removable;
58 }; 62 };
59 63
60 // Handles mass storage device attach event on UI thread. 64 // Handles mass storage device attach event on UI thread.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // on the UI thread. This is to try and prevent the same device from 106 // on the UI thread. This is to try and prevent the same device from
103 // occupying our worker pool in case of windows API call hangs. 107 // occupying our worker pool in case of windows API call hangs.
104 std::set<FilePath> pending_device_checks_; 108 std::set<FilePath> pending_device_checks_;
105 109
106 // A map from device mount point to device metadata. Only accessed on the UI 110 // A map from device mount point to device metadata. Only accessed on the UI
107 // thread. 111 // thread.
108 MountPointDeviceMetadataMap device_metadata_; 112 MountPointDeviceMetadataMap device_metadata_;
109 113
110 base::WeakPtrFactory<VolumeMountWatcherWin> weak_factory_; 114 base::WeakPtrFactory<VolumeMountWatcherWin> weak_factory_;
111 115
116 // The notifications object to use to signal newly attached volumes. Only
117 // removable devices will be notified.
118 RemovableStorageNotifications::Receiver* notifications_;
119
112 DISALLOW_COPY_AND_ASSIGN(VolumeMountWatcherWin); 120 DISALLOW_COPY_AND_ASSIGN(VolumeMountWatcherWin);
113 }; 121 };
114 122
115 } // namespace chrome 123 } // namespace chrome
116 124
117 #endif // CHROME_BROWSER_SYSTEM_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ 125 #endif // CHROME_BROWSER_SYSTEM_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698