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

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: Merging 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 #include "chrome/browser/system_monitor/removable_storage_notifications.h"
19 20
20 namespace chrome { 21 namespace chrome {
21 22
22 // This class watches the volume mount points and sends notifications to 23 // This class watches the volume mount points and sends notifications to
23 // base::SystemMonitor about the device attach/detach events. This is a 24 // RemovableStorageNotifications about the device attach/detach events.
24 // singleton class instantiated by RemovableDeviceNotificationsWindowWin. 25 // This is a singleton class instantiated by
26 // RemovableDeviceNotificationsWindowWin.
25 class VolumeMountWatcherWin { 27 class VolumeMountWatcherWin {
26 public: 28 public:
27 // TODO(gbillock): Take the RemovableStorageNotifications as an argument.
28 VolumeMountWatcherWin(); 29 VolumeMountWatcherWin();
29 virtual ~VolumeMountWatcherWin(); 30 virtual ~VolumeMountWatcherWin();
30 31
31 // Returns the volume file path of the drive specified by the |drive_number|. 32 // 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 33 // |drive_number| inputs of 0 - 25 are valid. Returns an empty file path if
33 // the |drive_number| is invalid. 34 // the |drive_number| is invalid.
34 static base::FilePath DriveNumberToFilePath(int drive_number); 35 static base::FilePath DriveNumberToFilePath(int drive_number);
35 36
36 void Init(); 37 void Init();
37 38
38 // Gets the information about the device mounted at |device_path|. On success, 39 // Gets the information about the device mounted at |device_path|. On success,
39 // returns true and fills in |location|, |unique_id|, |name|, and |removable|. 40 // returns true and fills in |location|, |unique_id|, |name|, and |removable|.
40 // Can block during startup while device info is still loading. 41 // Can block during startup while device info is still loading.
41 virtual bool GetDeviceInfo(const base::FilePath& device_path, 42 virtual bool GetDeviceInfo(const base::FilePath& device_path,
42 string16* location, 43 string16* location,
43 std::string* unique_id, 44 std::string* unique_id,
44 string16* name, 45 string16* name,
45 bool* removable) const; 46 bool* removable) const;
46 47
47 // Processes DEV_BROADCAST_VOLUME messages and triggers a 48 // Processes DEV_BROADCAST_VOLUME messages and triggers a
48 // notification if appropriate. 49 // notification if appropriate.
49 void OnWindowMessage(UINT event_type, LPARAM data); 50 void OnWindowMessage(UINT event_type, LPARAM data);
50 51
52 // Set the volume notifications object to be used when new
53 // removable volumes are found.
54 void SetNotifications(RemovableStorageNotifications::Receiver* notifications);
55
51 protected: 56 protected:
52 struct MountPointInfo { 57 struct MountPointInfo {
53 std::string device_id; 58 std::string device_id;
54 string16 location; 59 string16 location;
55 std::string unique_id; 60 std::string unique_id;
56 string16 name; 61 string16 name;
57 bool removable; 62 bool removable;
58 }; 63 };
59 64
60 // Handles mass storage device attach event on UI thread. 65 // Handles mass storage device attach event on UI thread.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // on the UI thread. This is to try and prevent the same device from 108 // on the UI thread. This is to try and prevent the same device from
104 // occupying our worker pool in case of windows API call hangs. 109 // occupying our worker pool in case of windows API call hangs.
105 std::set<base::FilePath> pending_device_checks_; 110 std::set<base::FilePath> pending_device_checks_;
106 111
107 // A map from device mount point to device metadata. Only accessed on the UI 112 // A map from device mount point to device metadata. Only accessed on the UI
108 // thread. 113 // thread.
109 MountPointDeviceMetadataMap device_metadata_; 114 MountPointDeviceMetadataMap device_metadata_;
110 115
111 base::WeakPtrFactory<VolumeMountWatcherWin> weak_factory_; 116 base::WeakPtrFactory<VolumeMountWatcherWin> weak_factory_;
112 117
118 // The notifications object to use to signal newly attached volumes. Only
119 // removable devices will be notified.
120 RemovableStorageNotifications::Receiver* notifications_;
121
113 DISALLOW_COPY_AND_ASSIGN(VolumeMountWatcherWin); 122 DISALLOW_COPY_AND_ASSIGN(VolumeMountWatcherWin);
114 }; 123 };
115 124
116 } // namespace chrome 125 } // namespace chrome
117 126
118 #endif // CHROME_BROWSER_SYSTEM_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_ 127 #endif // CHROME_BROWSER_SYSTEM_MONITOR_VOLUME_MOUNT_WATCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698