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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_event_router.h

Issue 13474015: drive: Fix lifetime model of FileBrowserEventRouter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 8 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 | Annotate | Revision Log
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_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 16 matching lines...) Expand all
27 class Profile; 27 class Profile;
28 28
29 namespace drive { 29 namespace drive {
30 class DriveEntryProto; 30 class DriveEntryProto;
31 class DriveFileSystemInterface; 31 class DriveFileSystemInterface;
32 } 32 }
33 33
34 // Monitors changes in disk mounts, network connection state and preferences 34 // Monitors changes in disk mounts, network connection state and preferences
35 // affecting File Manager. Dispatches appropriate File Browser events. 35 // affecting File Manager. Dispatches appropriate File Browser events.
36 class FileBrowserEventRouter 36 class FileBrowserEventRouter
37 : public base::RefCountedThreadSafe<FileBrowserEventRouter>, 37 : public chromeos::disks::DiskMountManager::Observer,
38 public chromeos::disks::DiskMountManager::Observer,
39 public chromeos::ConnectivityStateHelperObserver, 38 public chromeos::ConnectivityStateHelperObserver,
40 public chromeos::SystemKeyEventListener::ModifiersObserver, 39 public chromeos::SystemKeyEventListener::ModifiersObserver,
41 public drive::DriveFileSystemObserver, 40 public drive::DriveFileSystemObserver,
42 public google_apis::DriveServiceObserver { 41 public google_apis::DriveServiceObserver {
43 public: 42 public:
44 // Interface that should keep track of the system state in regards to system 43 // Interface that should keep track of the system state in regards to system
45 // suspend and resume events. 44 // suspend and resume events.
46 // When the |IsResuming()| returns true, it should be able to check if a 45 // When the |IsResuming()| returns true, it should be able to check if a
47 // removable device was present before the was system suspended. 46 // removable device was present before the was system suspended.
48 class SuspendStateDelegate { 47 class SuspendStateDelegate {
49 public: 48 public:
50 virtual ~SuspendStateDelegate() {} 49 virtual ~SuspendStateDelegate() {}
51 50
52 // Returns true if the system has recently woken up. 51 // Returns true if the system has recently woken up.
53 virtual bool SystemIsResuming() const = 0; 52 virtual bool SystemIsResuming() const = 0;
54 // If system is resuming, returns true if the disk was present before the 53 // If system is resuming, returns true if the disk was present before the
55 // system suspend. Should return false if the system is not resuming. 54 // system suspend. Should return false if the system is not resuming.
56 virtual bool DiskWasPresentBeforeSuspend( 55 virtual bool DiskWasPresentBeforeSuspend(
57 const chromeos::disks::DiskMountManager::Disk& disk) const = 0; 56 const chromeos::disks::DiskMountManager::Disk& disk) const = 0;
58 }; 57 };
59 58
59 explicit FileBrowserEventRouter(Profile* profile);
60 virtual ~FileBrowserEventRouter();
61
60 void Shutdown(); 62 void Shutdown();
61 63
62 // Starts observing file system change events. 64 // Starts observing file system change events.
63 void ObserveFileSystemEvents(); 65 void ObserveFileSystemEvents();
64 66
65 // File watch setup routines. 67 // File watch setup routines.
66 bool AddFileWatch(const base::FilePath& file_path, 68 bool AddFileWatch(const base::FilePath& file_path,
67 const base::FilePath& virtual_path, 69 const base::FilePath& virtual_path,
68 const std::string& extension_id); 70 const std::string& extension_id);
69 void RemoveFileWatch(const base::FilePath& file_path, 71 void RemoveFileWatch(const base::FilePath& file_path,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 virtual void OnDirectoryChanged( 104 virtual void OnDirectoryChanged(
103 const base::FilePath& directory_path) OVERRIDE; 105 const base::FilePath& directory_path) OVERRIDE;
104 virtual void OnResourceListFetched(int num_accumulated_entries) OVERRIDE; 106 virtual void OnResourceListFetched(int num_accumulated_entries) OVERRIDE;
105 virtual void OnFileSystemMounted() OVERRIDE; 107 virtual void OnFileSystemMounted() OVERRIDE;
106 virtual void OnFileSystemBeingUnmounted() OVERRIDE; 108 virtual void OnFileSystemBeingUnmounted() OVERRIDE;
107 109
108 // chromeos::SystemKeyEventListener::ModifiersObserver overrides. 110 // chromeos::SystemKeyEventListener::ModifiersObserver overrides.
109 virtual void OnModifiersChange(int pressed_modifiers) OVERRIDE; 111 virtual void OnModifiersChange(int pressed_modifiers) OVERRIDE;
110 112
111 private: 113 private:
112 friend class FileBrowserPrivateAPI;
113 friend class base::RefCountedThreadSafe<FileBrowserEventRouter>;
114
115 typedef std::map<std::string, int> ExtensionUsageRegistry; 114 typedef std::map<std::string, int> ExtensionUsageRegistry;
116 115
117 class FileWatcherExtensions { 116 class FileWatcherExtensions {
118 public: 117 public:
119 FileWatcherExtensions(const base::FilePath& path, 118 FileWatcherExtensions(const base::FilePath& path,
120 const std::string& extension_id, 119 const std::string& extension_id,
121 bool is_remote_file_system); 120 bool is_remote_file_system);
122 121
123 ~FileWatcherExtensions(); 122 ~FileWatcherExtensions();
124 123
(...skipping 14 matching lines...) Expand all
139 linked_ptr<base::FilePathWatcher> file_watcher_; 138 linked_ptr<base::FilePathWatcher> file_watcher_;
140 base::FilePath local_path_; 139 base::FilePath local_path_;
141 base::FilePath virtual_path_; 140 base::FilePath virtual_path_;
142 ExtensionUsageRegistry extensions_; 141 ExtensionUsageRegistry extensions_;
143 unsigned int ref_count_; 142 unsigned int ref_count_;
144 bool is_remote_file_system_; 143 bool is_remote_file_system_;
145 }; 144 };
146 145
147 typedef std::map<base::FilePath, FileWatcherExtensions*> WatcherMap; 146 typedef std::map<base::FilePath, FileWatcherExtensions*> WatcherMap;
148 147
149 explicit FileBrowserEventRouter(Profile* profile);
150 virtual ~FileBrowserEventRouter();
151
152 // USB mount event handlers. 148 // USB mount event handlers.
153 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk); 149 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk);
154 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk); 150 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk);
155 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk); 151 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk);
156 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk); 152 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk);
157 void OnDeviceAdded(const std::string& device_path); 153 void OnDeviceAdded(const std::string& device_path);
158 void OnDeviceRemoved(const std::string& device_path); 154 void OnDeviceRemoved(const std::string& device_path);
159 void OnDeviceScanned(const std::string& device_path); 155 void OnDeviceScanned(const std::string& device_path);
160 void OnFormatStarted(const std::string& device_path, bool success); 156 void OnFormatStarted(const std::string& device_path, bool success);
161 void OnFormatCompleted(const std::string& device_path, bool success); 157 void OnFormatCompleted(const std::string& device_path, bool success);
(...skipping 27 matching lines...) Expand all
189 // Returns the DriveFileSystem for the current profile. 185 // Returns the DriveFileSystem for the current profile.
190 drive::DriveFileSystemInterface* GetRemoteFileSystem() const; 186 drive::DriveFileSystemInterface* GetRemoteFileSystem() const;
191 187
192 // Handles requests to start and stop periodic updates on remote file system. 188 // Handles requests to start and stop periodic updates on remote file system.
193 // When |start| is set to true, this function starts periodic updates only if 189 // When |start| is set to true, this function starts periodic updates only if
194 // it is not yet started; when |start| is set to false, this function stops 190 // it is not yet started; when |start| is set to false, this function stops
195 // periodic updates only if the number of outstanding update requests reaches 191 // periodic updates only if the number of outstanding update requests reaches
196 // zero. 192 // zero.
197 void HandleRemoteUpdateRequestOnUIThread(bool start); 193 void HandleRemoteUpdateRequestOnUIThread(bool start);
198 194
199 base::WeakPtrFactory<FileBrowserEventRouter> weak_factory_;
200 base::FilePathWatcher::Callback file_watcher_callback_; 195 base::FilePathWatcher::Callback file_watcher_callback_;
201 WatcherMap file_watchers_; 196 WatcherMap file_watchers_;
202 scoped_ptr<FileBrowserNotifications> notifications_; 197 scoped_ptr<FileBrowserNotifications> notifications_;
203 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; 198 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
204 scoped_ptr<SuspendStateDelegate> suspend_state_delegate_; 199 scoped_ptr<SuspendStateDelegate> suspend_state_delegate_;
205 Profile* profile_; 200 Profile* profile_;
206 base::Lock lock_; 201 base::Lock lock_;
207 202
208 // Number of active update requests on the remote file system. 203 // Number of active update requests on the remote file system.
209 int num_remote_update_requests_; 204 int num_remote_update_requests_;
210 205
211 // Event router behavior depends on shift modifier status. This is designed 206 // Event router behavior depends on shift modifier status. This is designed
212 // for power users. 207 // for power users.
213 bool shift_pressed_; 208 bool shift_pressed_;
214 209
210 // Note: This should remain the last member so it'll be destroyed and
211 // invalidate the weak pointers before any other members are destroyed.
212 base::WeakPtrFactory<FileBrowserEventRouter> weak_factory_;
215 DISALLOW_COPY_AND_ASSIGN(FileBrowserEventRouter); 213 DISALLOW_COPY_AND_ASSIGN(FileBrowserEventRouter);
216 }; 214 };
217 215
218 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 216 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698