OLD | NEW |
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_MANAGER_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | |
11 | 10 |
12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
14 #include "base/files/file_path_watcher.h" | 13 #include "base/files/file_path_watcher.h" |
15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
16 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 15 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
17 #include "chrome/browser/chromeos/drive/file_system_observer.h" | 16 #include "chrome/browser/chromeos/drive/file_system_observer.h" |
18 #include "chrome/browser/chromeos/drive/job_list.h" | 17 #include "chrome/browser/chromeos/drive/job_list.h" |
19 #include "chrome/browser/chromeos/drive/sync_client.h" | 18 #include "chrome/browser/chromeos/drive/sync_client.h" |
20 #include "chrome/browser/chromeos/file_manager/file_watcher.h" | 19 #include "chrome/browser/chromeos/file_manager/file_watcher.h" |
(...skipping 30 matching lines...) Expand all Loading... |
51 // Monitors changes in disk mounts, network connection state and preferences | 50 // Monitors changes in disk mounts, network connection state and preferences |
52 // affecting File Manager. Dispatches appropriate File Browser events. | 51 // affecting File Manager. Dispatches appropriate File Browser events. |
53 class EventRouter : public KeyedService, | 52 class EventRouter : public KeyedService, |
54 public chromeos::NetworkStateHandlerObserver, | 53 public chromeos::NetworkStateHandlerObserver, |
55 public drive::FileSystemObserver, | 54 public drive::FileSystemObserver, |
56 public drive::JobListObserver, | 55 public drive::JobListObserver, |
57 public drive::DriveServiceObserver, | 56 public drive::DriveServiceObserver, |
58 public VolumeManagerObserver, | 57 public VolumeManagerObserver, |
59 public content::NotificationObserver { | 58 public content::NotificationObserver { |
60 public: | 59 public: |
61 typedef base::Callback<void(const base::FilePath& virtual_path, | |
62 const drive::FileChange* list, | |
63 bool got_error, | |
64 const std::vector<std::string>& extension_ids)> | |
65 DispatchDirectoryChangeEventImplCallback; | |
66 | |
67 explicit EventRouter(Profile* profile); | 60 explicit EventRouter(Profile* profile); |
68 virtual ~EventRouter(); | 61 virtual ~EventRouter(); |
69 | 62 |
70 // KeyedService overrides. | 63 // KeyedService overrides. |
71 virtual void Shutdown() override; | 64 virtual void Shutdown() override; |
72 | 65 |
73 typedef base::Callback<void(bool success)> BoolCallback; | 66 typedef base::Callback<void(bool success)> BoolCallback; |
74 | 67 |
75 // Adds a file watch at |local_path|, associated with |virtual_path|, for | 68 // Adds a file watch at |local_path|, associated with |virtual_path|, for |
76 // an extension with |extension_id|. | 69 // an extension with |extension_id|. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 virtual void OnFormatStarted( | 125 virtual void OnFormatStarted( |
133 const std::string& device_path, bool success) override; | 126 const std::string& device_path, bool success) override; |
134 virtual void OnFormatCompleted( | 127 virtual void OnFormatCompleted( |
135 const std::string& device_path, bool success) override; | 128 const std::string& device_path, bool success) override; |
136 | 129 |
137 // content::NotificationObserver overrides. | 130 // content::NotificationObserver overrides. |
138 virtual void Observe(int type, | 131 virtual void Observe(int type, |
139 const content::NotificationSource& source, | 132 const content::NotificationSource& source, |
140 const content::NotificationDetails& details) override; | 133 const content::NotificationDetails& details) override; |
141 | 134 |
142 // Set custom dispatch directory change event implementation for testing. | |
143 void SetDispatchDirectoryChangeEventImplForTesting( | |
144 const DispatchDirectoryChangeEventImplCallback& callback); | |
145 | |
146 private: | 135 private: |
147 typedef std::map<base::FilePath, FileWatcher*> WatcherMap; | 136 typedef std::map<base::FilePath, FileWatcher*> WatcherMap; |
148 | 137 |
149 // Starts observing file system change events. | 138 // Starts observing file system change events. |
150 void ObserveEvents(); | 139 void ObserveEvents(); |
151 | 140 |
152 // Called when prefs related to file manager change. | 141 // Called when prefs related to file manager change. |
153 void OnFileManagerPrefsChanged(); | 142 void OnFileManagerPrefsChanged(); |
154 | 143 |
155 // Process file watch notifications. | 144 // Process file watch notifications. |
156 void HandleFileWatchNotification(const drive::FileChange* list, | 145 void HandleFileWatchNotification(const drive::FileChange* list, |
157 const base::FilePath& path, | 146 const base::FilePath& path, |
158 bool got_error); | 147 bool got_error); |
159 | 148 |
160 // Sends directory change event. | 149 // Sends directory change event. |
161 void DispatchDirectoryChangeEvent( | 150 void DispatchDirectoryChangeEvent( |
162 const base::FilePath& path, | 151 const base::FilePath& path, |
163 const drive::FileChange* list, | 152 const drive::FileChange* list, |
164 bool got_error, | 153 bool got_error, |
165 const std::vector<std::string>& extension_ids); | |
166 | |
167 // Default implementation of DispatchDirectoryChangeEvent. | |
168 void DispatchDirectoryChangeEventImpl( | |
169 const base::FilePath& path, | |
170 const drive::FileChange* list, | |
171 bool got_error, | |
172 const std::vector<std::string>& extension_ids); | 154 const std::vector<std::string>& extension_ids); |
173 | 155 |
174 // Sends directory change event, after converting the file definition to entry | 156 // Sends directory change event, after converting the file definition to entry |
175 // definition. | 157 // definition. |
176 void DispatchDirectoryChangeEventWithEntryDefinition( | 158 void DispatchDirectoryChangeEventWithEntryDefinition( |
177 const linked_ptr<drive::FileChange> list, | 159 const linked_ptr<drive::FileChange> list, |
178 const std::string* extension_id, | 160 const std::string* extension_id, |
179 bool watcher_error, | 161 bool watcher_error, |
180 const EntryDefinition& entry_definition); | 162 const EntryDefinition& entry_definition); |
181 | 163 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 base::Time next_send_file_transfer_event_; | 203 base::Time next_send_file_transfer_event_; |
222 | 204 |
223 WatcherMap file_watchers_; | 205 WatcherMap file_watchers_; |
224 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | 206 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; |
225 Profile* profile_; | 207 Profile* profile_; |
226 | 208 |
227 content::NotificationRegistrar notification_registrar_; | 209 content::NotificationRegistrar notification_registrar_; |
228 | 210 |
229 scoped_ptr<DeviceEventRouter> device_event_router_; | 211 scoped_ptr<DeviceEventRouter> device_event_router_; |
230 | 212 |
231 DispatchDirectoryChangeEventImplCallback | |
232 dispatch_directory_change_event_impl_; | |
233 | |
234 // Note: This should remain the last member so it'll be destroyed and | 213 // Note: This should remain the last member so it'll be destroyed and |
235 // invalidate the weak pointers before any other members are destroyed. | 214 // invalidate the weak pointers before any other members are destroyed. |
236 base::WeakPtrFactory<EventRouter> weak_factory_; | 215 base::WeakPtrFactory<EventRouter> weak_factory_; |
237 | |
238 DISALLOW_COPY_AND_ASSIGN(EventRouter); | 216 DISALLOW_COPY_AND_ASSIGN(EventRouter); |
239 }; | 217 }; |
240 | 218 |
241 } // namespace file_manager | 219 } // namespace file_manager |
242 | 220 |
243 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ | 221 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_H_ |
OLD | NEW |