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