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

Side by Side Diff: chrome/browser/system_monitor/removable_storage_notifications.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_REMOVABLE_STORAGE_NOTIFICATIONS_H_ 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_
6 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_ 6 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/observer_list_threadsafe.h" 9 #include "base/observer_list_threadsafe.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 12
13 class ChromeBrowserMainPartsLinux;
14 class ChromeBrowserMainPartsMac;
13 class MediaGalleriesPrivateApiTest; 15 class MediaGalleriesPrivateApiTest;
14 16
15 namespace chrome { 17 namespace chrome {
16 18
17 class RemovableStorageObserver; 19 class RemovableStorageObserver;
18 20
19 // Base class for platform-specific instances watching for removable storage 21 // Base class for platform-specific instances watching for removable storage
20 // attachments/detachments. 22 // attachments/detachments.
21 class RemovableStorageNotifications { 23 class RemovableStorageNotifications {
22 public: 24 public:
23 struct StorageInfo { 25 struct StorageInfo {
24 StorageInfo(); 26 StorageInfo();
25 StorageInfo(const std::string& id, 27 StorageInfo(const std::string& id,
26 const string16& device_name, 28 const string16& device_name,
27 const FilePath::StringType& device_location); 29 const FilePath::StringType& device_location);
28 30
29 // Unique device id - persists between device attachments. 31 // Unique device id - persists between device attachments.
30 std::string device_id; 32 std::string device_id;
31 33
32 // Human readable removable storage device name. 34 // Human readable removable storage device name.
33 string16 name; 35 string16 name;
34 36
35 // Current attached removable storage device location. 37 // Current attached removable storage device location.
36 FilePath::StringType location; 38 FilePath::StringType location;
37 }; 39 };
38 40
39 virtual ~RemovableStorageNotifications(); 41 // This interface is provided to generators of storage notifications.
42 class Receiver {
43 public:
44 virtual ~Receiver() {}
vandebo (ex-Chrome) 2013/01/31 23:51:29 Put the implementation in the .cc file.
Greg Billock 2013/02/01 18:28:43 Done.
45
46 virtual void ProcessAttach(const StorageInfo& info) = 0;
vandebo (ex-Chrome) 2013/01/31 23:51:29 nit: Take the components here and make the Storage
Greg Billock 2013/02/01 18:28:43 I think we'll end up with more components -- we ne
vandebo (ex-Chrome) 2013/02/01 18:59:55 We used to have the type as a separate component a
Greg Billock 2013/02/01 23:05:42 OK, I can put it back that way. I've been regardin
47 virtual void ProcessDetach(const std::string& id) = 0;
48 };
40 49
41 // Returns a pointer to an object owned by the BrowserMainParts, with lifetime 50 // Returns a pointer to an object owned by the BrowserMainParts, with lifetime
42 // somewhat shorter than a process Singleton. 51 // somewhat shorter than a process Singleton.
43 static RemovableStorageNotifications* GetInstance(); 52 static RemovableStorageNotifications* GetInstance();
44 53
45 // Finds the device that contains |path| and populates |device_info|. 54 // Finds the device that contains |path| and populates |device_info|.
46 // Should be able to handle any path on the local system, not just removable 55 // Should be able to handle any path on the local system, not just removable
47 // storage. Returns false if unable to find the device. 56 // storage. Returns false if unable to find the device.
48 virtual bool GetDeviceInfoForPath( 57 virtual bool GetDeviceInfoForPath(
49 const FilePath& path, 58 const FilePath& path,
(...skipping 16 matching lines...) Expand all
66 #endif 75 #endif
67 76
68 // Returns information for attached removable storage. 77 // Returns information for attached removable storage.
69 std::vector<StorageInfo> GetAttachedStorage() const; 78 std::vector<StorageInfo> GetAttachedStorage() const;
70 79
71 void AddObserver(RemovableStorageObserver* obs); 80 void AddObserver(RemovableStorageObserver* obs);
72 void RemoveObserver(RemovableStorageObserver* obs); 81 void RemoveObserver(RemovableStorageObserver* obs);
73 82
74 protected: 83 protected:
75 RemovableStorageNotifications(); 84 RemovableStorageNotifications();
85 virtual ~RemovableStorageNotifications();
76 86
77 friend class MediaFileSystemRegistryTest; 87 // TODO(gbillock): Clean up ownerships and get rid of these friends.
88 friend class ::ChromeBrowserMainPartsLinux;
89 friend class ::ChromeBrowserMainPartsMac;
78 friend class ::MediaGalleriesPrivateApiTest; 90 friend class ::MediaGalleriesPrivateApiTest;
79 friend class MediaStorageUtilTest;
80 // TODO(gbillock): remove these friends by making the classes owned by the
81 // platform-specific implementation.
82 friend class MediaTransferProtocolDeviceObserverLinux;
83 friend class PortableDeviceWatcherWin;
84 friend class VolumeMountWatcherWin;
85 91
86 void ProcessAttach(const std::string& id, 92 scoped_ptr<Receiver> receiver_;
vandebo (ex-Chrome) 2013/01/31 23:51:29 Make this private and add a protected getter
Greg Billock 2013/02/01 18:28:43 Done.
87 const string16& name,
88 const FilePath::StringType& location);
89 void ProcessDetach(const std::string& id);
90 93
91 private: 94 private:
95 class ReceiverImpl;
96 friend class ReceiverImpl;
97
92 typedef std::map<std::string, StorageInfo> RemovableStorageMap; 98 typedef std::map<std::string, StorageInfo> RemovableStorageMap;
93 99
100 void ProcessAttach(const StorageInfo& storage);
101 void ProcessDetach(const std::string& id);
102
94 scoped_refptr<ObserverListThreadSafe<RemovableStorageObserver> > 103 scoped_refptr<ObserverListThreadSafe<RemovableStorageObserver> >
95 observer_list_; 104 observer_list_;
96 105
97 // For manipulating removable_storage_map_ structure. 106 // For manipulating removable_storage_map_ structure.
98 mutable base::Lock storage_lock_; 107 mutable base::Lock storage_lock_;
99 108
100 // Map of all the attached removable storage devices. 109 // Map of all the attached removable storage devices.
101 RemovableStorageMap storage_map_; 110 RemovableStorageMap storage_map_;
102 }; 111 };
103 112
104 } // namespace chrome 113 } // namespace chrome
105 114
106 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_ 115 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698