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 | |
62 (const base::FilePath& virtual_path, | |
63 const drive::FileChange* list, | |
64 bool got_error, | |
65 const std::vector<std::string>& extension_ids)> | |
66 DispatchDirectoryChangeEventImplCallback; | |
67 | |
60 explicit EventRouter(Profile* profile); | 68 explicit EventRouter(Profile* profile); |
61 virtual ~EventRouter(); | 69 virtual ~EventRouter(); |
62 | 70 |
63 // KeyedService overrides. | 71 // KeyedService overrides. |
64 virtual void Shutdown() override; | 72 virtual void Shutdown() override; |
65 | 73 |
66 typedef base::Callback<void(bool success)> BoolCallback; | 74 typedef base::Callback<void(bool success)> BoolCallback; |
67 | 75 |
68 // Adds a file watch at |local_path|, associated with |virtual_path|, for | 76 // Adds a file watch at |local_path|, associated with |virtual_path|, for |
69 // an extension with |extension_id|. | 77 // an extension with |extension_id|. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 virtual void OnFormatStarted( | 133 virtual void OnFormatStarted( |
126 const std::string& device_path, bool success) override; | 134 const std::string& device_path, bool success) override; |
127 virtual void OnFormatCompleted( | 135 virtual void OnFormatCompleted( |
128 const std::string& device_path, bool success) override; | 136 const std::string& device_path, bool success) override; |
129 | 137 |
130 // content::NotificationObserver overrides. | 138 // content::NotificationObserver overrides. |
131 virtual void Observe(int type, | 139 virtual void Observe(int type, |
132 const content::NotificationSource& source, | 140 const content::NotificationSource& source, |
133 const content::NotificationDetails& details) override; | 141 const content::NotificationDetails& details) override; |
134 | 142 |
143 // Set custom dispatch directory change event implementation for testing. | |
144 void SetDispatchDirectoryChangeEventImplForTesting( | |
145 const DispatchDirectoryChangeEventImplCallback& callback); | |
146 | |
135 private: | 147 private: |
136 typedef std::map<base::FilePath, FileWatcher*> WatcherMap; | 148 typedef std::map<base::FilePath, FileWatcher*> WatcherMap; |
137 | 149 |
138 // Starts observing file system change events. | 150 // Starts observing file system change events. |
139 void ObserveEvents(); | 151 void ObserveEvents(); |
140 | 152 |
141 // Called when prefs related to file manager change. | 153 // Called when prefs related to file manager change. |
142 void OnFileManagerPrefsChanged(); | 154 void OnFileManagerPrefsChanged(); |
143 | 155 |
144 // Process file watch notifications. | 156 // Process file watch notifications. |
145 void HandleFileWatchNotification(const drive::FileChange* list, | 157 void HandleFileWatchNotification(const drive::FileChange* list, |
146 const base::FilePath& path, | 158 const base::FilePath& path, |
147 bool got_error); | 159 bool got_error); |
148 | 160 |
149 // Sends directory change event. | 161 // Sends directory change event. |
150 void DispatchDirectoryChangeEvent( | 162 void DispatchDirectoryChangeEvent( |
151 const base::FilePath& path, | 163 const base::FilePath& path, |
152 const drive::FileChange* list, | 164 const drive::FileChange* list, |
153 bool got_error, | 165 bool got_error, |
154 const std::vector<std::string>& extension_ids); | 166 const std::vector<std::string>& extension_ids); |
155 | 167 |
168 void DispatchDirectoryChangeEventImpl( | |
mtomasz
2014/10/17 05:26:56
nit: Comment is missing.
yawano
2014/10/20 00:49:48
Done.
| |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
213 // Note: This should remain the last member so it'll be destroyed and | 231 // Note: This should remain the last member so it'll be destroyed and |
214 // invalidate the weak pointers before any other members are destroyed. | 232 // invalidate the weak pointers before any other members are destroyed. |
215 base::WeakPtrFactory<EventRouter> weak_factory_; | 233 base::WeakPtrFactory<EventRouter> weak_factory_; |
mtomasz
2014/10/17 05:26:56
Please keep weak_factory_ as the last member. See
yawano
2014/10/20 00:49:48
Done.
| |
234 | |
235 DispatchDirectoryChangeEventImplCallback | |
mtomasz
2014/10/17 05:26:56
(No need for a comment for trivial members).
yawano
2014/10/20 00:49:48
Acknowledged.
| |
236 dispatch_directory_change_event_impl_; | |
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 |