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

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: 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_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
19 class MediaFileSystemRegistryTest;
17 class RemovableStorageObserver; 20 class RemovableStorageObserver;
18 21
19 // Base class for platform-specific instances watching for removable storage 22 // Base class for platform-specific instances watching for removable storage
20 // attachments/detachments. 23 // attachments/detachments.
21 class RemovableStorageNotifications { 24 class RemovableStorageNotifications {
22 public: 25 public:
23 struct StorageInfo { 26 struct StorageInfo {
24 StorageInfo(); 27 StorageInfo();
25 StorageInfo(const std::string& id, 28 StorageInfo(const std::string& id,
26 const string16& device_name, 29 const string16& device_name,
27 const base::FilePath::StringType& device_location); 30 const base::FilePath::StringType& device_location);
28 31
29 // Unique device id - persists between device attachments. 32 // Unique device id - persists between device attachments.
30 std::string device_id; 33 std::string device_id;
31 34
32 // Human readable removable storage device name. 35 // Human readable removable storage device name.
33 string16 name; 36 string16 name;
34 37
35 // Current attached removable storage device location. 38 // Current attached removable storage device location.
36 base::FilePath::StringType location; 39 base::FilePath::StringType location;
37 }; 40 };
38 41
39 virtual ~RemovableStorageNotifications(); 42 // This interface is provided to generators of storage notifications.
43 class Receiver {
44 public:
45 virtual ~Receiver();
46
47 virtual void ProcessAttach(const std::string& id,
48 const string16& name,
49 const base::FilePath::StringType& location) = 0;
50 virtual void ProcessDetach(const std::string& id) = 0;
51 };
40 52
41 // Returns a pointer to an object owned by the BrowserMainParts, with lifetime 53 // Returns a pointer to an object owned by the BrowserMainParts, with lifetime
42 // somewhat shorter than a process Singleton. 54 // somewhat shorter than a process Singleton.
43 static RemovableStorageNotifications* GetInstance(); 55 static RemovableStorageNotifications* GetInstance();
44 56
45 // Finds the device that contains |path| and populates |device_info|. 57 // 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 58 // Should be able to handle any path on the local system, not just removable
47 // storage. Returns false if unable to find the device. 59 // storage. Returns false if unable to find the device.
48 virtual bool GetDeviceInfoForPath( 60 virtual bool GetDeviceInfoForPath(
49 const base::FilePath& path, 61 const base::FilePath& path,
(...skipping 16 matching lines...) Expand all
66 #endif 78 #endif
67 79
68 // Returns information for attached removable storage. 80 // Returns information for attached removable storage.
69 std::vector<StorageInfo> GetAttachedStorage() const; 81 std::vector<StorageInfo> GetAttachedStorage() const;
70 82
71 void AddObserver(RemovableStorageObserver* obs); 83 void AddObserver(RemovableStorageObserver* obs);
72 void RemoveObserver(RemovableStorageObserver* obs); 84 void RemoveObserver(RemovableStorageObserver* obs);
73 85
74 protected: 86 protected:
75 RemovableStorageNotifications(); 87 RemovableStorageNotifications();
88 virtual ~RemovableStorageNotifications();
76 89
90 // TODO(gbillock): Clean up ownerships and get rid of these friends.
91 friend class ::ChromeBrowserMainPartsLinux;
92 friend class ::ChromeBrowserMainPartsMac;
93 friend class ::MediaGalleriesPrivateApiTest;
77 friend class MediaFileSystemRegistryTest; 94 friend class MediaFileSystemRegistryTest;
78 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 95
86 void ProcessAttach(const std::string& id, 96 virtual Receiver* receiver() const;
87 const string16& name, 97
88 const base::FilePath::StringType& location); 98 private:
99 class ReceiverImpl;
100 friend class ReceiverImpl;
101
102 typedef std::map<std::string, StorageInfo> RemovableStorageMap;
103
104 void ProcessAttach(const StorageInfo& storage);
89 void ProcessDetach(const std::string& id); 105 void ProcessDetach(const std::string& id);
90 106
91 private: 107 scoped_ptr<Receiver> receiver_;
92 typedef std::map<std::string, StorageInfo> RemovableStorageMap;
93 108
94 scoped_refptr<ObserverListThreadSafe<RemovableStorageObserver> > 109 scoped_refptr<ObserverListThreadSafe<RemovableStorageObserver> >
95 observer_list_; 110 observer_list_;
96 111
97 // For manipulating removable_storage_map_ structure. 112 // For manipulating removable_storage_map_ structure.
98 mutable base::Lock storage_lock_; 113 mutable base::Lock storage_lock_;
99 114
100 // Map of all the attached removable storage devices. 115 // Map of all the attached removable storage devices.
101 RemovableStorageMap storage_map_; 116 RemovableStorageMap storage_map_;
102 }; 117 };
103 118
104 } // namespace chrome 119 } // namespace chrome
105 120
106 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_ 121 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698