OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "chrome/browser/chromeos/file_system_provider/file_system_plugin/plugin
_operation_router.h" |
11 #include "chrome/browser/chromeos/file_system_provider/notification_manager.h" | 12 #include "chrome/browser/chromeos/file_system_provider/notification_manager.h" |
12 #include "chrome/browser/chromeos/file_system_provider/operations/abort.h" | 13 #include "chrome/browser/chromeos/file_system_provider/operations/abort.h" |
13 #include "chrome/browser/chromeos/file_system_provider/operations/add_watcher.h" | 14 #include "chrome/browser/chromeos/file_system_provider/operations/add_watcher.h" |
14 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" | 15 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" |
15 #include "chrome/browser/chromeos/file_system_provider/operations/configure.h" | 16 #include "chrome/browser/chromeos/file_system_provider/operations/configure.h" |
16 #include "chrome/browser/chromeos/file_system_provider/operations/copy_entry.h" | 17 #include "chrome/browser/chromeos/file_system_provider/operations/copy_entry.h" |
17 #include "chrome/browser/chromeos/file_system_provider/operations/create_directo
ry.h" | 18 #include "chrome/browser/chromeos/file_system_provider/operations/create_directo
ry.h" |
18 #include "chrome/browser/chromeos/file_system_provider/operations/create_file.h" | 19 #include "chrome/browser/chromeos/file_system_provider/operations/create_file.h" |
19 #include "chrome/browser/chromeos/file_system_provider/operations/delete_entry.h
" | 20 #include "chrome/browser/chromeos/file_system_provider/operations/delete_entry.h
" |
20 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" | 21 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" |
21 #include "chrome/browser/chromeos/file_system_provider/operations/move_entry.h" | 22 #include "chrome/browser/chromeos/file_system_provider/operations/move_entry.h" |
22 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h" | 23 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h" |
23 #include "chrome/browser/chromeos/file_system_provider/operations/read_directory
.h" | 24 #include "chrome/browser/chromeos/file_system_provider/operations/read_directory
.h" |
24 #include "chrome/browser/chromeos/file_system_provider/operations/read_file.h" | 25 #include "chrome/browser/chromeos/file_system_provider/operations/read_file.h" |
25 #include "chrome/browser/chromeos/file_system_provider/operations/remove_watcher
.h" | 26 #include "chrome/browser/chromeos/file_system_provider/operations/remove_watcher
.h" |
26 #include "chrome/browser/chromeos/file_system_provider/operations/truncate.h" | 27 #include "chrome/browser/chromeos/file_system_provider/operations/truncate.h" |
27 #include "chrome/browser/chromeos/file_system_provider/operations/unmount.h" | 28 #include "chrome/browser/chromeos/file_system_provider/operations/unmount.h" |
28 #include "chrome/browser/chromeos/file_system_provider/operations/write_file.h" | 29 #include "chrome/browser/chromeos/file_system_provider/operations/write_file.h" |
29 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 30 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/common/extensions/api/file_system_provider.h" | 32 #include "chrome/common/extensions/api/file_system_provider.h" |
32 #include "extensions/browser/event_router.h" | 33 #include "extensions/browser/event_router.h" |
33 | 34 |
34 namespace net { | 35 namespace net { |
35 class IOBuffer; | 36 class IOBuffer; |
36 } // namespace net | 37 } // namespace net |
37 | 38 |
38 namespace chromeos { | 39 namespace chromeos { |
39 namespace file_system_provider { | 40 namespace file_system_provider { |
| 41 |
| 42 |
| 43 typename ExtensionDestination::EventRouterType* |
| 44 ExtensionDestination::Get(Profile *profile) { |
| 45 return extensions::EventRouter::Get(profile); |
| 46 } |
| 47 |
| 48 PluginDestination::EventRouterType* PluginDestination::Get(Profile *) { |
| 49 return chromeos::file_system_provider::PluginOperationRouter::GetInstance(); |
| 50 } |
| 51 |
40 namespace { | 52 namespace { |
41 | 53 |
42 // Discards the result of Abort() when called from the destructor. | 54 // Discards the result of Abort() when called from the destructor. |
43 void EmptyStatusCallback(base::File::Error /* result */) { | 55 void EmptyStatusCallback(base::File::Error /* result */) { |
44 } | 56 } |
45 | 57 |
46 } // namespace | 58 } // namespace |
47 | 59 |
48 AutoUpdater::AutoUpdater(const base::Closure& update_callback) | 60 AutoUpdater::AutoUpdater(const base::Closure& update_callback) |
49 : update_callback_(update_callback), | 61 : update_callback_(update_callback), |
(...skipping 14 matching lines...) Expand all Loading... |
64 } | 76 } |
65 | 77 |
66 AutoUpdater::~AutoUpdater() { | 78 AutoUpdater::~AutoUpdater() { |
67 // If no callbacks are created, then we need to invoke updating in the | 79 // If no callbacks are created, then we need to invoke updating in the |
68 // destructor. | 80 // destructor. |
69 if (!created_callbacks_) | 81 if (!created_callbacks_) |
70 update_callback_.Run(); | 82 update_callback_.Run(); |
71 else if (pending_callbacks_) | 83 else if (pending_callbacks_) |
72 LOG(ERROR) << "Not all callbacks called. This may happen on shutdown."; | 84 LOG(ERROR) << "Not all callbacks called. This may happen on shutdown."; |
73 } | 85 } |
74 | 86 template <class DestinationPolicy> |
75 struct ProvidedFileSystem::AddWatcherInQueueArgs { | 87 struct ProvidedFileSystem<DestinationPolicy>::AddWatcherInQueueArgs { |
76 AddWatcherInQueueArgs(size_t token, | 88 AddWatcherInQueueArgs(size_t token, |
77 const GURL& origin, | 89 const GURL& origin, |
78 const base::FilePath& entry_path, | 90 const base::FilePath& entry_path, |
79 bool recursive, | 91 bool recursive, |
80 bool persistent, | 92 bool persistent, |
81 const storage::AsyncFileUtil::StatusCallback& callback, | 93 const storage::AsyncFileUtil::StatusCallback& callback, |
82 const storage::WatcherManager::NotificationCallback& | 94 const storage::WatcherManager::NotificationCallback& |
83 notification_callback) | 95 notification_callback) |
84 : token(token), | 96 : token(token), |
85 origin(origin), | 97 origin(origin), |
86 entry_path(entry_path), | 98 entry_path(entry_path), |
87 recursive(recursive), | 99 recursive(recursive), |
88 persistent(persistent), | 100 persistent(persistent), |
89 callback(callback), | 101 callback(callback), |
90 notification_callback(notification_callback) {} | 102 notification_callback(notification_callback) {} |
91 ~AddWatcherInQueueArgs() {} | 103 ~AddWatcherInQueueArgs() {} |
92 | 104 |
93 const size_t token; | 105 const size_t token; |
94 const GURL origin; | 106 const GURL origin; |
95 const base::FilePath entry_path; | 107 const base::FilePath entry_path; |
96 const bool recursive; | 108 const bool recursive; |
97 const bool persistent; | 109 const bool persistent; |
98 const storage::AsyncFileUtil::StatusCallback callback; | 110 const storage::AsyncFileUtil::StatusCallback callback; |
99 const storage::WatcherManager::NotificationCallback notification_callback; | 111 const storage::WatcherManager::NotificationCallback notification_callback; |
100 }; | 112 }; |
101 | 113 |
102 struct ProvidedFileSystem::NotifyInQueueArgs { | 114 template <class DestinationPolicy> |
| 115 struct ProvidedFileSystem<DestinationPolicy>::NotifyInQueueArgs { |
103 NotifyInQueueArgs(size_t token, | 116 NotifyInQueueArgs(size_t token, |
104 const base::FilePath& entry_path, | 117 const base::FilePath& entry_path, |
105 bool recursive, | 118 bool recursive, |
106 storage::WatcherManager::ChangeType change_type, | 119 storage::WatcherManager::ChangeType change_type, |
107 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, | 120 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, |
108 const std::string& tag, | 121 const std::string& tag, |
109 const storage::AsyncFileUtil::StatusCallback& callback) | 122 const storage::AsyncFileUtil::StatusCallback& callback) |
110 : token(token), | 123 : token(token), |
111 entry_path(entry_path), | 124 entry_path(entry_path), |
112 recursive(recursive), | 125 recursive(recursive), |
113 change_type(change_type), | 126 change_type(change_type), |
114 changes(changes.Pass()), | 127 changes(changes.Pass()), |
115 tag(tag), | 128 tag(tag), |
116 callback(callback) {} | 129 callback(callback) {} |
117 ~NotifyInQueueArgs() {} | 130 ~NotifyInQueueArgs() {} |
118 | 131 |
119 const size_t token; | 132 const size_t token; |
120 const base::FilePath entry_path; | 133 const base::FilePath entry_path; |
121 const bool recursive; | 134 const bool recursive; |
122 const storage::WatcherManager::ChangeType change_type; | 135 const storage::WatcherManager::ChangeType change_type; |
123 const scoped_ptr<ProvidedFileSystemObserver::Changes> changes; | 136 const scoped_ptr<ProvidedFileSystemObserver::Changes> changes; |
124 const std::string tag; | 137 const std::string tag; |
125 const storage::AsyncFileUtil::StatusCallback callback; | 138 const storage::AsyncFileUtil::StatusCallback callback; |
126 | 139 |
127 private: | 140 private: |
128 DISALLOW_COPY_AND_ASSIGN(NotifyInQueueArgs); | 141 DISALLOW_COPY_AND_ASSIGN(NotifyInQueueArgs); |
129 }; | 142 }; |
130 | 143 |
131 ProvidedFileSystem::ProvidedFileSystem( | 144 template <class DestinationPolicy> |
| 145 ProvidedFileSystem<DestinationPolicy>::ProvidedFileSystem( |
132 Profile* profile, | 146 Profile* profile, |
133 const ProvidedFileSystemInfo& file_system_info) | 147 const ProvidedFileSystemInfo& file_system_info) |
134 : profile_(profile), | 148 : profile_(profile), |
135 event_router_(extensions::EventRouter::Get(profile)), // May be NULL. | 149 event_router_(DestinationPolicy::Get(profile)), // May be NULL. |
136 file_system_info_(file_system_info), | 150 file_system_info_(file_system_info), |
137 notification_manager_( | 151 notification_manager_( |
138 new NotificationManager(profile_, file_system_info_)), | 152 new NotificationManager(profile_, file_system_info_)), |
139 request_manager_(new RequestManager(profile, | 153 request_manager_(new RequestManager(profile, |
140 file_system_info.extension_id(), | 154 file_system_info.extension_id(), |
141 notification_manager_.get())), | 155 notification_manager_.get())), |
142 watcher_queue_(1), | 156 watcher_queue_(1), |
143 weak_ptr_factory_(this) { | 157 weak_ptr_factory_(this) { |
144 } | 158 } |
145 | 159 template <class DestinationPolicy> |
146 ProvidedFileSystem::~ProvidedFileSystem() { | 160 ProvidedFileSystem<DestinationPolicy>::~ProvidedFileSystem() { |
147 const std::vector<int> request_ids = request_manager_->GetActiveRequestIds(); | 161 const std::vector<int> request_ids = request_manager_->GetActiveRequestIds(); |
148 for (size_t i = 0; i < request_ids.size(); ++i) { | 162 for (size_t i = 0; i < request_ids.size(); ++i) { |
149 Abort(request_ids[i]); | 163 Abort(request_ids[i]); |
150 } | 164 } |
151 } | 165 } |
152 | 166 template <class DestinationPolicy> |
153 void ProvidedFileSystem::SetEventRouterForTesting( | 167 void ProvidedFileSystem<DestinationPolicy>::SetEventRouterForTesting( |
154 extensions::EventRouter* event_router) { | 168 typename DestinationPolicy::EventRouterType* event_router) { |
155 event_router_ = event_router; | 169 event_router_ = event_router; |
156 } | 170 } |
157 | 171 |
158 void ProvidedFileSystem::SetNotificationManagerForTesting( | 172 template <class DestinationPolicy> |
| 173 void ProvidedFileSystem<DestinationPolicy>::SetNotificationManagerForTesting( |
159 scoped_ptr<NotificationManagerInterface> notification_manager) { | 174 scoped_ptr<NotificationManagerInterface> notification_manager) { |
160 notification_manager_ = notification_manager.Pass(); | 175 notification_manager_ = notification_manager.Pass(); |
161 request_manager_.reset(new RequestManager( | 176 request_manager_.reset(new RequestManager( |
162 profile_, file_system_info_.extension_id(), notification_manager_.get())); | 177 profile_, file_system_info_.extension_id(), notification_manager_.get())); |
163 } | 178 } |
164 | 179 |
165 AbortCallback ProvidedFileSystem::RequestUnmount( | 180 template <class DestinationPolicy> |
| 181 AbortCallback ProvidedFileSystem<DestinationPolicy>::RequestUnmount( |
166 const storage::AsyncFileUtil::StatusCallback& callback) { | 182 const storage::AsyncFileUtil::StatusCallback& callback) { |
167 const int request_id = request_manager_->CreateRequest( | 183 const int request_id = request_manager_->CreateRequest( |
168 REQUEST_UNMOUNT, | 184 REQUEST_UNMOUNT, scoped_ptr<RequestManager::HandlerInterface>( |
169 scoped_ptr<RequestManager::HandlerInterface>( | 185 new operations::Unmount<DestinationPolicy>( |
170 new operations::Unmount(event_router_, file_system_info_, callback))); | 186 event_router_, file_system_info_, callback))); |
171 if (!request_id) { | 187 if (!request_id) { |
172 callback.Run(base::File::FILE_ERROR_SECURITY); | 188 callback.Run(base::File::FILE_ERROR_SECURITY); |
173 return AbortCallback(); | 189 return AbortCallback(); |
174 } | 190 } |
175 | 191 |
176 return base::Bind( | 192 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
177 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 193 weak_ptr_factory_.GetWeakPtr(), request_id); |
178 } | 194 } |
179 | 195 |
180 AbortCallback ProvidedFileSystem::GetMetadata( | 196 template <class DestinationPolicy> |
| 197 AbortCallback ProvidedFileSystem<DestinationPolicy>::GetMetadata( |
181 const base::FilePath& entry_path, | 198 const base::FilePath& entry_path, |
182 MetadataFieldMask fields, | 199 MetadataFieldMask fields, |
183 const GetMetadataCallback& callback) { | 200 const GetMetadataCallback& callback) { |
184 const int request_id = request_manager_->CreateRequest( | 201 const int request_id = request_manager_->CreateRequest( |
185 GET_METADATA, | 202 GET_METADATA, |
186 scoped_ptr<RequestManager::HandlerInterface>(new operations::GetMetadata( | 203 scoped_ptr<RequestManager::HandlerInterface>( |
187 event_router_, file_system_info_, entry_path, fields, callback))); | 204 new operations::GetMetadata<DestinationPolicy>( |
| 205 event_router_, file_system_info_, |
| 206 entry_path, fields, callback))); |
188 if (!request_id) { | 207 if (!request_id) { |
189 callback.Run(make_scoped_ptr<EntryMetadata>(NULL), | 208 callback.Run(make_scoped_ptr<EntryMetadata>(NULL), |
190 base::File::FILE_ERROR_SECURITY); | 209 base::File::FILE_ERROR_SECURITY); |
191 return AbortCallback(); | 210 return AbortCallback(); |
192 } | 211 } |
193 | 212 |
194 return base::Bind( | 213 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
195 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 214 weak_ptr_factory_.GetWeakPtr(), request_id); |
196 } | 215 } |
197 | 216 |
198 AbortCallback ProvidedFileSystem::ReadDirectory( | 217 template <class DestinationPolicy> |
| 218 AbortCallback ProvidedFileSystem<DestinationPolicy>::ReadDirectory( |
199 const base::FilePath& directory_path, | 219 const base::FilePath& directory_path, |
200 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { | 220 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { |
201 const int request_id = request_manager_->CreateRequest( | 221 const int request_id = request_manager_->CreateRequest( |
202 READ_DIRECTORY, | 222 READ_DIRECTORY, |
203 scoped_ptr<RequestManager::HandlerInterface>( | 223 scoped_ptr<RequestManager::HandlerInterface>( |
204 new operations::ReadDirectory( | 224 new operations::ReadDirectory<DestinationPolicy>( |
205 event_router_, file_system_info_, directory_path, callback))); | 225 event_router_, file_system_info_, directory_path, callback))); |
206 if (!request_id) { | 226 if (!request_id) { |
207 callback.Run(base::File::FILE_ERROR_SECURITY, | 227 callback.Run(base::File::FILE_ERROR_SECURITY, |
208 storage::AsyncFileUtil::EntryList(), | 228 storage::AsyncFileUtil::EntryList(), |
209 false /* has_more */); | 229 false /* has_more */); |
210 return AbortCallback(); | 230 return AbortCallback(); |
211 } | 231 } |
212 | 232 |
213 return base::Bind( | 233 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
214 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 234 weak_ptr_factory_.GetWeakPtr(), request_id); |
215 } | 235 } |
216 | 236 |
217 AbortCallback ProvidedFileSystem::ReadFile( | 237 template <class DestinationPolicy> |
| 238 AbortCallback ProvidedFileSystem<DestinationPolicy>::ReadFile( |
218 int file_handle, | 239 int file_handle, |
219 net::IOBuffer* buffer, | 240 net::IOBuffer* buffer, |
220 int64 offset, | 241 int64 offset, |
221 int length, | 242 int length, |
222 const ReadChunkReceivedCallback& callback) { | 243 const ReadChunkReceivedCallback& callback) { |
223 TRACE_EVENT1( | 244 TRACE_EVENT1( |
224 "file_system_provider", "ProvidedFileSystem::ReadFile", "length", length); | 245 "file_system_provider", "ProvidedFileSystem::ReadFile", "length", length); |
225 const int request_id = request_manager_->CreateRequest( | 246 const int request_id = request_manager_->CreateRequest( |
226 READ_FILE, | 247 READ_FILE, make_scoped_ptr<RequestManager::HandlerInterface>( |
227 make_scoped_ptr<RequestManager::HandlerInterface>( | 248 new operations::ReadFile<DestinationPolicy>( |
228 new operations::ReadFile(event_router_, | 249 event_router_, file_system_info_, file_handle, buffer, |
229 file_system_info_, | 250 offset, length, callback))); |
230 file_handle, | |
231 buffer, | |
232 offset, | |
233 length, | |
234 callback))); | |
235 if (!request_id) { | 251 if (!request_id) { |
236 callback.Run(0 /* chunk_length */, | 252 callback.Run(0 /* chunk_length */, |
237 false /* has_more */, | 253 false /* has_more */, |
238 base::File::FILE_ERROR_SECURITY); | 254 base::File::FILE_ERROR_SECURITY); |
239 return AbortCallback(); | 255 return AbortCallback(); |
240 } | 256 } |
241 | 257 |
242 return base::Bind( | 258 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
243 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 259 weak_ptr_factory_.GetWeakPtr(), request_id); |
244 } | 260 } |
245 | 261 |
246 AbortCallback ProvidedFileSystem::OpenFile(const base::FilePath& file_path, | 262 template <class DestinationPolicy> |
247 OpenFileMode mode, | 263 AbortCallback ProvidedFileSystem<DestinationPolicy>::OpenFile( |
248 const OpenFileCallback& callback) { | 264 const base::FilePath& file_path, |
| 265 OpenFileMode mode, |
| 266 const OpenFileCallback& callback) { |
249 const int request_id = request_manager_->CreateRequest( | 267 const int request_id = request_manager_->CreateRequest( |
250 OPEN_FILE, | 268 OPEN_FILE, scoped_ptr<RequestManager::HandlerInterface>( |
251 scoped_ptr<RequestManager::HandlerInterface>(new operations::OpenFile( | 269 new operations::OpenFile<DestinationPolicy>( |
252 event_router_, file_system_info_, file_path, mode, | 270 event_router_, file_system_info_, file_path, mode, |
253 base::Bind(&ProvidedFileSystem::OnOpenFileCompleted, | 271 base::Bind(&ProvidedFileSystem::OnOpenFileCompleted, |
254 weak_ptr_factory_.GetWeakPtr(), file_path, mode, | 272 weak_ptr_factory_.GetWeakPtr(), file_path, |
255 callback)))); | 273 mode, callback)))); |
256 if (!request_id) { | 274 if (!request_id) { |
257 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); | 275 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); |
258 return AbortCallback(); | 276 return AbortCallback(); |
259 } | 277 } |
260 | 278 |
261 return base::Bind( | 279 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
262 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 280 weak_ptr_factory_.GetWeakPtr(), request_id); |
263 } | 281 } |
264 | 282 |
265 AbortCallback ProvidedFileSystem::CloseFile( | 283 template <class DestinationPolicy> |
| 284 AbortCallback ProvidedFileSystem<DestinationPolicy>::CloseFile( |
266 int file_handle, | 285 int file_handle, |
267 const storage::AsyncFileUtil::StatusCallback& callback) { | 286 const storage::AsyncFileUtil::StatusCallback& callback) { |
268 const int request_id = request_manager_->CreateRequest( | 287 const int request_id = request_manager_->CreateRequest( |
269 CLOSE_FILE, | 288 CLOSE_FILE, |
270 scoped_ptr<RequestManager::HandlerInterface>(new operations::CloseFile( | 289 scoped_ptr<RequestManager::HandlerInterface>( |
271 event_router_, file_system_info_, file_handle, | 290 new operations::CloseFile<DestinationPolicy>( |
272 base::Bind(&ProvidedFileSystem::OnCloseFileCompleted, | 291 event_router_, file_system_info_, file_handle, |
273 weak_ptr_factory_.GetWeakPtr(), file_handle, callback)))); | 292 base::Bind( |
| 293 &ProvidedFileSystem<DestinationPolicy>::OnCloseFileCompleted, |
| 294 weak_ptr_factory_.GetWeakPtr(), file_handle, |
| 295 callback)))); |
274 if (!request_id) { | 296 if (!request_id) { |
275 callback.Run(base::File::FILE_ERROR_SECURITY); | 297 callback.Run(base::File::FILE_ERROR_SECURITY); |
276 return AbortCallback(); | 298 return AbortCallback(); |
277 } | 299 } |
278 | 300 |
279 return base::Bind( | 301 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
280 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 302 weak_ptr_factory_.GetWeakPtr(), request_id); |
281 } | 303 } |
282 | 304 |
283 AbortCallback ProvidedFileSystem::CreateDirectory( | 305 template <class DestinationPolicy> |
| 306 AbortCallback ProvidedFileSystem<DestinationPolicy>::CreateDirectory( |
284 const base::FilePath& directory_path, | 307 const base::FilePath& directory_path, |
285 bool recursive, | 308 bool recursive, |
286 const storage::AsyncFileUtil::StatusCallback& callback) { | 309 const storage::AsyncFileUtil::StatusCallback& callback) { |
287 const int request_id = request_manager_->CreateRequest( | 310 const int request_id = request_manager_->CreateRequest( |
288 CREATE_DIRECTORY, | 311 CREATE_DIRECTORY, scoped_ptr<RequestManager::HandlerInterface>( |
289 scoped_ptr<RequestManager::HandlerInterface>( | 312 new operations::CreateDirectory<DestinationPolicy>( |
290 new operations::CreateDirectory(event_router_, | 313 event_router_, file_system_info_, |
291 file_system_info_, | 314 directory_path, recursive, callback))); |
292 directory_path, | |
293 recursive, | |
294 callback))); | |
295 if (!request_id) { | 315 if (!request_id) { |
296 callback.Run(base::File::FILE_ERROR_SECURITY); | 316 callback.Run(base::File::FILE_ERROR_SECURITY); |
297 return AbortCallback(); | 317 return AbortCallback(); |
298 } | 318 } |
299 | 319 |
300 return base::Bind( | 320 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
301 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 321 weak_ptr_factory_.GetWeakPtr(), request_id); |
302 } | 322 } |
303 | 323 |
304 AbortCallback ProvidedFileSystem::DeleteEntry( | 324 template <class DestinationPolicy> |
| 325 AbortCallback ProvidedFileSystem<DestinationPolicy>::DeleteEntry( |
305 const base::FilePath& entry_path, | 326 const base::FilePath& entry_path, |
306 bool recursive, | 327 bool recursive, |
307 const storage::AsyncFileUtil::StatusCallback& callback) { | 328 const storage::AsyncFileUtil::StatusCallback& callback) { |
308 const int request_id = request_manager_->CreateRequest( | 329 const int request_id = request_manager_->CreateRequest( |
309 DELETE_ENTRY, | 330 DELETE_ENTRY, scoped_ptr<RequestManager::HandlerInterface>( |
310 scoped_ptr<RequestManager::HandlerInterface>(new operations::DeleteEntry( | 331 new operations::DeleteEntry<DestinationPolicy>( |
311 event_router_, file_system_info_, entry_path, recursive, callback))); | 332 event_router_, file_system_info_, entry_path, |
| 333 recursive, callback))); |
312 if (!request_id) { | 334 if (!request_id) { |
313 callback.Run(base::File::FILE_ERROR_SECURITY); | 335 callback.Run(base::File::FILE_ERROR_SECURITY); |
314 return AbortCallback(); | 336 return AbortCallback(); |
315 } | 337 } |
316 | 338 |
317 return base::Bind( | 339 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
318 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 340 weak_ptr_factory_.GetWeakPtr(), request_id); |
319 } | 341 } |
320 | 342 |
321 AbortCallback ProvidedFileSystem::CreateFile( | 343 template <class DestinationPolicy> |
| 344 AbortCallback ProvidedFileSystem<DestinationPolicy>::CreateFile( |
322 const base::FilePath& file_path, | 345 const base::FilePath& file_path, |
323 const storage::AsyncFileUtil::StatusCallback& callback) { | 346 const storage::AsyncFileUtil::StatusCallback& callback) { |
324 const int request_id = request_manager_->CreateRequest( | 347 const int request_id = request_manager_->CreateRequest( |
325 CREATE_FILE, | 348 CREATE_FILE, |
326 scoped_ptr<RequestManager::HandlerInterface>(new operations::CreateFile( | 349 scoped_ptr<RequestManager::HandlerInterface>( |
327 event_router_, file_system_info_, file_path, callback))); | 350 new operations::CreateFile<DestinationPolicy>( |
| 351 event_router_, file_system_info_, |
| 352 file_path, callback))); |
328 if (!request_id) { | 353 if (!request_id) { |
329 callback.Run(base::File::FILE_ERROR_SECURITY); | 354 callback.Run(base::File::FILE_ERROR_SECURITY); |
330 return AbortCallback(); | 355 return AbortCallback(); |
331 } | 356 } |
332 | 357 |
333 return base::Bind( | 358 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
334 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 359 weak_ptr_factory_.GetWeakPtr(), request_id); |
335 } | 360 } |
336 | 361 |
337 AbortCallback ProvidedFileSystem::CopyEntry( | 362 template <class DestinationPolicy> |
| 363 AbortCallback ProvidedFileSystem<DestinationPolicy>::CopyEntry( |
338 const base::FilePath& source_path, | 364 const base::FilePath& source_path, |
339 const base::FilePath& target_path, | 365 const base::FilePath& target_path, |
340 const storage::AsyncFileUtil::StatusCallback& callback) { | 366 const storage::AsyncFileUtil::StatusCallback& callback) { |
341 const int request_id = request_manager_->CreateRequest( | 367 const int request_id = request_manager_->CreateRequest( |
342 COPY_ENTRY, | 368 COPY_ENTRY, scoped_ptr<RequestManager::HandlerInterface>( |
343 scoped_ptr<RequestManager::HandlerInterface>( | 369 new operations::CopyEntry<DestinationPolicy>( |
344 new operations::CopyEntry(event_router_, | 370 event_router_, file_system_info_, source_path, |
345 file_system_info_, | 371 target_path, callback))); |
346 source_path, | |
347 target_path, | |
348 callback))); | |
349 if (!request_id) { | 372 if (!request_id) { |
350 callback.Run(base::File::FILE_ERROR_SECURITY); | 373 callback.Run(base::File::FILE_ERROR_SECURITY); |
351 return AbortCallback(); | 374 return AbortCallback(); |
352 } | 375 } |
353 | 376 |
354 return base::Bind( | 377 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
355 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 378 weak_ptr_factory_.GetWeakPtr(), request_id); |
356 } | 379 } |
357 | 380 |
358 AbortCallback ProvidedFileSystem::WriteFile( | 381 template <class DestinationPolicy> |
| 382 AbortCallback ProvidedFileSystem<DestinationPolicy>::WriteFile( |
359 int file_handle, | 383 int file_handle, |
360 net::IOBuffer* buffer, | 384 net::IOBuffer* buffer, |
361 int64 offset, | 385 int64 offset, |
362 int length, | 386 int length, |
363 const storage::AsyncFileUtil::StatusCallback& callback) { | 387 const storage::AsyncFileUtil::StatusCallback& callback) { |
364 TRACE_EVENT1("file_system_provider", | 388 TRACE_EVENT1("file_system_provider", |
365 "ProvidedFileSystem::WriteFile", | 389 "ProvidedFileSystem::WriteFile", |
366 "length", | 390 "length", |
367 length); | 391 length); |
368 const int request_id = request_manager_->CreateRequest( | 392 const int request_id = request_manager_->CreateRequest( |
369 WRITE_FILE, | 393 WRITE_FILE, |
370 make_scoped_ptr<RequestManager::HandlerInterface>( | 394 make_scoped_ptr<RequestManager::HandlerInterface>( |
371 new operations::WriteFile(event_router_, | 395 new operations::WriteFile<DestinationPolicy>( |
372 file_system_info_, | 396 event_router_, file_system_info_, file_handle, |
373 file_handle, | 397 make_scoped_refptr(buffer), offset, length, callback))); |
374 make_scoped_refptr(buffer), | |
375 offset, | |
376 length, | |
377 callback))); | |
378 if (!request_id) { | 398 if (!request_id) { |
379 callback.Run(base::File::FILE_ERROR_SECURITY); | 399 callback.Run(base::File::FILE_ERROR_SECURITY); |
380 return AbortCallback(); | 400 return AbortCallback(); |
381 } | 401 } |
382 | 402 |
383 return base::Bind( | 403 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
384 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 404 weak_ptr_factory_.GetWeakPtr(), request_id); |
385 } | 405 } |
386 | 406 |
387 AbortCallback ProvidedFileSystem::MoveEntry( | 407 template <class DestinationPolicy> |
| 408 AbortCallback ProvidedFileSystem<DestinationPolicy>::MoveEntry( |
388 const base::FilePath& source_path, | 409 const base::FilePath& source_path, |
389 const base::FilePath& target_path, | 410 const base::FilePath& target_path, |
390 const storage::AsyncFileUtil::StatusCallback& callback) { | 411 const storage::AsyncFileUtil::StatusCallback& callback) { |
391 const int request_id = request_manager_->CreateRequest( | 412 const int request_id = request_manager_->CreateRequest( |
392 MOVE_ENTRY, | 413 MOVE_ENTRY, scoped_ptr<RequestManager::HandlerInterface>( |
393 scoped_ptr<RequestManager::HandlerInterface>( | 414 new operations::MoveEntry<DestinationPolicy>( |
394 new operations::MoveEntry(event_router_, | 415 event_router_, file_system_info_, source_path, |
395 file_system_info_, | 416 target_path, callback))); |
396 source_path, | |
397 target_path, | |
398 callback))); | |
399 if (!request_id) { | 417 if (!request_id) { |
400 callback.Run(base::File::FILE_ERROR_SECURITY); | 418 callback.Run(base::File::FILE_ERROR_SECURITY); |
401 return AbortCallback(); | 419 return AbortCallback(); |
402 } | 420 } |
403 | 421 |
404 return base::Bind( | 422 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
405 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 423 weak_ptr_factory_.GetWeakPtr(), request_id); |
406 } | 424 } |
407 | 425 |
408 AbortCallback ProvidedFileSystem::Truncate( | 426 template <class DestinationPolicy> |
| 427 AbortCallback ProvidedFileSystem<DestinationPolicy>::Truncate( |
409 const base::FilePath& file_path, | 428 const base::FilePath& file_path, |
410 int64 length, | 429 int64 length, |
411 const storage::AsyncFileUtil::StatusCallback& callback) { | 430 const storage::AsyncFileUtil::StatusCallback& callback) { |
412 const int request_id = request_manager_->CreateRequest( | 431 const int request_id = request_manager_->CreateRequest( |
413 TRUNCATE, | 432 TRUNCATE, |
414 scoped_ptr<RequestManager::HandlerInterface>(new operations::Truncate( | 433 scoped_ptr<RequestManager::HandlerInterface>( |
415 event_router_, file_system_info_, file_path, length, callback))); | 434 new operations::Truncate<DestinationPolicy>( |
| 435 event_router_, file_system_info_, |
| 436 file_path, length, callback))); |
416 if (!request_id) { | 437 if (!request_id) { |
417 callback.Run(base::File::FILE_ERROR_SECURITY); | 438 callback.Run(base::File::FILE_ERROR_SECURITY); |
418 return AbortCallback(); | 439 return AbortCallback(); |
419 } | 440 } |
420 | 441 |
421 return base::Bind( | 442 return base::Bind(&ProvidedFileSystem<DestinationPolicy>::Abort, |
422 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 443 weak_ptr_factory_.GetWeakPtr(), request_id); |
423 } | 444 } |
424 | 445 |
425 AbortCallback ProvidedFileSystem::AddWatcher( | 446 template <class DestinationPolicy> |
| 447 AbortCallback ProvidedFileSystem<DestinationPolicy>::AddWatcher( |
426 const GURL& origin, | 448 const GURL& origin, |
427 const base::FilePath& entry_path, | 449 const base::FilePath& entry_path, |
428 bool recursive, | 450 bool recursive, |
429 bool persistent, | 451 bool persistent, |
430 const storage::AsyncFileUtil::StatusCallback& callback, | 452 const storage::AsyncFileUtil::StatusCallback& callback, |
431 const storage::WatcherManager::NotificationCallback& | 453 const storage::WatcherManager::NotificationCallback& |
432 notification_callback) { | 454 notification_callback) { |
433 const size_t token = watcher_queue_.NewToken(); | 455 const size_t token = watcher_queue_.NewToken(); |
434 watcher_queue_.Enqueue( | 456 watcher_queue_.Enqueue( |
435 token, base::Bind(&ProvidedFileSystem::AddWatcherInQueue, | 457 token, base::Bind( |
436 base::Unretained(this), // Outlived by the queue. | 458 &ProvidedFileSystem<DestinationPolicy>::AddWatcherInQueue, |
437 AddWatcherInQueueArgs(token, origin, entry_path, | 459 base::Unretained(this), // Outlived by the queue. |
438 recursive, persistent, callback, | 460 AddWatcherInQueueArgs(token, origin, entry_path, |
439 notification_callback))); | 461 recursive, persistent, callback, |
| 462 notification_callback))); |
440 return AbortCallback(); | 463 return AbortCallback(); |
441 } | 464 } |
442 | 465 |
443 void ProvidedFileSystem::RemoveWatcher( | 466 template <class DestinationPolicy> |
| 467 void ProvidedFileSystem<DestinationPolicy>::RemoveWatcher( |
444 const GURL& origin, | 468 const GURL& origin, |
445 const base::FilePath& entry_path, | 469 const base::FilePath& entry_path, |
446 bool recursive, | 470 bool recursive, |
447 const storage::AsyncFileUtil::StatusCallback& callback) { | 471 const storage::AsyncFileUtil::StatusCallback& callback) { |
448 const size_t token = watcher_queue_.NewToken(); | 472 const size_t token = watcher_queue_.NewToken(); |
449 watcher_queue_.Enqueue( | 473 watcher_queue_.Enqueue( |
450 token, base::Bind(&ProvidedFileSystem::RemoveWatcherInQueue, | 474 token, base::Bind( |
451 base::Unretained(this), // Outlived by the queue. | 475 &ProvidedFileSystem<DestinationPolicy>::RemoveWatcherInQueue, |
452 token, origin, entry_path, recursive, callback)); | 476 base::Unretained(this), // Outlived by the queue. |
| 477 token, origin, entry_path, recursive, callback)); |
453 } | 478 } |
454 | 479 |
455 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const { | 480 template <class DestinationPolicy> |
| 481 const ProvidedFileSystemInfo& |
| 482 ProvidedFileSystem<DestinationPolicy>::GetFileSystemInfo() const { |
456 return file_system_info_; | 483 return file_system_info_; |
457 } | 484 } |
458 | 485 |
459 RequestManager* ProvidedFileSystem::GetRequestManager() { | 486 template <class DestinationPolicy> |
| 487 RequestManager* ProvidedFileSystem<DestinationPolicy>::GetRequestManager() { |
460 return request_manager_.get(); | 488 return request_manager_.get(); |
461 } | 489 } |
462 | 490 |
463 Watchers* ProvidedFileSystem::GetWatchers() { | 491 template <class DestinationPolicy> |
| 492 Watchers* ProvidedFileSystem<DestinationPolicy>::GetWatchers() { |
464 return &watchers_; | 493 return &watchers_; |
465 } | 494 } |
466 | 495 |
467 const OpenedFiles& ProvidedFileSystem::GetOpenedFiles() const { | 496 template <class DestinationPolicy> |
| 497 const OpenedFiles& |
| 498 ProvidedFileSystem<DestinationPolicy>::GetOpenedFiles() const { |
468 return opened_files_; | 499 return opened_files_; |
469 } | 500 } |
470 | 501 |
471 void ProvidedFileSystem::AddObserver(ProvidedFileSystemObserver* observer) { | 502 template <class DestinationPolicy> |
| 503 void ProvidedFileSystem<DestinationPolicy>::AddObserver( |
| 504 ProvidedFileSystemObserver* observer) { |
472 DCHECK(observer); | 505 DCHECK(observer); |
473 observers_.AddObserver(observer); | 506 observers_.AddObserver(observer); |
474 } | 507 } |
475 | 508 |
476 void ProvidedFileSystem::RemoveObserver(ProvidedFileSystemObserver* observer) { | 509 template <class DestinationPolicy> |
| 510 void ProvidedFileSystem<DestinationPolicy>::RemoveObserver( |
| 511 ProvidedFileSystemObserver* observer) { |
477 DCHECK(observer); | 512 DCHECK(observer); |
478 observers_.RemoveObserver(observer); | 513 observers_.RemoveObserver(observer); |
479 } | 514 } |
480 | 515 |
481 void ProvidedFileSystem::Notify( | 516 template <class DestinationPolicy> |
| 517 void ProvidedFileSystem<DestinationPolicy>::Notify( |
482 const base::FilePath& entry_path, | 518 const base::FilePath& entry_path, |
483 bool recursive, | 519 bool recursive, |
484 storage::WatcherManager::ChangeType change_type, | 520 storage::WatcherManager::ChangeType change_type, |
485 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, | 521 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, |
486 const std::string& tag, | 522 const std::string& tag, |
487 const storage::AsyncFileUtil::StatusCallback& callback) { | 523 const storage::AsyncFileUtil::StatusCallback& callback) { |
488 const size_t token = watcher_queue_.NewToken(); | 524 const size_t token = watcher_queue_.NewToken(); |
489 watcher_queue_.Enqueue( | 525 watcher_queue_.Enqueue( |
490 token, base::Bind(&ProvidedFileSystem::NotifyInQueue, | 526 token, base::Bind(&ProvidedFileSystem<DestinationPolicy>::NotifyInQueue, |
491 base::Unretained(this), // Outlived by the queue. | 527 base::Unretained(this), // Outlived by the queue. |
492 base::Passed(make_scoped_ptr(new NotifyInQueueArgs( | 528 base::Passed(make_scoped_ptr(new NotifyInQueueArgs( |
493 token, entry_path, recursive, change_type, | 529 token, entry_path, recursive, change_type, |
494 changes.Pass(), tag, callback))))); | 530 changes.Pass(), tag, callback))))); |
495 } | 531 } |
496 | 532 |
497 void ProvidedFileSystem::Configure( | 533 template <class DestinationPolicy> |
| 534 void ProvidedFileSystem<DestinationPolicy>::Configure( |
498 const storage::AsyncFileUtil::StatusCallback& callback) { | 535 const storage::AsyncFileUtil::StatusCallback& callback) { |
499 const int request_id = request_manager_->CreateRequest( | 536 const int request_id = request_manager_->CreateRequest( |
500 CONFIGURE, | 537 CONFIGURE, scoped_ptr<RequestManager::HandlerInterface>( |
501 scoped_ptr<RequestManager::HandlerInterface>(new operations::Configure( | 538 new operations::Configure<DestinationPolicy>( |
502 event_router_, file_system_info_, callback))); | 539 event_router_, file_system_info_, callback))); |
503 if (!request_id) | 540 if (!request_id) |
504 callback.Run(base::File::FILE_ERROR_SECURITY); | 541 callback.Run(base::File::FILE_ERROR_SECURITY); |
505 } | 542 } |
506 | 543 |
507 void ProvidedFileSystem::Abort(int operation_request_id) { | 544 template <class DestinationPolicy> |
| 545 void ProvidedFileSystem<DestinationPolicy>::Abort(int operation_request_id) { |
508 request_manager_->RejectRequest(operation_request_id, | 546 request_manager_->RejectRequest(operation_request_id, |
509 make_scoped_ptr(new RequestValue()), | 547 make_scoped_ptr(new RequestValue()), |
510 base::File::FILE_ERROR_ABORT); | 548 base::File::FILE_ERROR_ABORT); |
511 if (!request_manager_->CreateRequest( | 549 if (!request_manager_->CreateRequest( |
512 ABORT, | 550 ABORT, scoped_ptr<RequestManager::HandlerInterface>( |
513 scoped_ptr<RequestManager::HandlerInterface>(new operations::Abort( | 551 new operations::Abort<DestinationPolicy>( |
514 event_router_, file_system_info_, operation_request_id, | 552 event_router_, file_system_info_, operation_request_id, |
515 base::Bind(&EmptyStatusCallback))))) { | 553 base::Bind(&EmptyStatusCallback))))) { |
516 LOG(ERROR) << "Failed to create an abort request."; | 554 LOG(ERROR) << "Failed to create an abort request."; |
517 } | 555 } |
518 } | 556 } |
519 | 557 |
520 AbortCallback ProvidedFileSystem::AddWatcherInQueue( | 558 template <class DestinationPolicy> |
| 559 AbortCallback ProvidedFileSystem<DestinationPolicy>::AddWatcherInQueue( |
521 const AddWatcherInQueueArgs& args) { | 560 const AddWatcherInQueueArgs& args) { |
522 if (args.persistent && (!file_system_info_.supports_notify_tag() || | 561 if (args.persistent && (!file_system_info_.supports_notify_tag() || |
523 !args.notification_callback.is_null())) { | 562 !args.notification_callback.is_null())) { |
524 OnAddWatcherInQueueCompleted(args.token, args.entry_path, args.recursive, | 563 OnAddWatcherInQueueCompleted(args.token, args.entry_path, args.recursive, |
525 Subscriber(), args.callback, | 564 Subscriber(), args.callback, |
526 base::File::FILE_ERROR_INVALID_OPERATION); | 565 base::File::FILE_ERROR_INVALID_OPERATION); |
527 return AbortCallback(); | 566 return AbortCallback(); |
528 } | 567 } |
529 | 568 |
530 // Create a candidate subscriber. This could be done in OnAddWatcherCompleted, | 569 // Create a candidate subscriber. This could be done in OnAddWatcherCompleted, |
531 // but base::Bind supports only up to 7 arguments. | 570 // but base::Bind supports only up to 7 arguments. |
532 Subscriber subscriber; | 571 Subscriber subscriber; |
533 subscriber.origin = args.origin; | 572 subscriber.origin = args.origin; |
534 subscriber.persistent = args.persistent; | 573 subscriber.persistent = args.persistent; |
535 subscriber.notification_callback = args.notification_callback; | 574 subscriber.notification_callback = args.notification_callback; |
536 | 575 |
537 const WatcherKey key(args.entry_path, args.recursive); | 576 const WatcherKey key(args.entry_path, args.recursive); |
538 const Watchers::const_iterator it = watchers_.find(key); | 577 const Watchers::const_iterator it = watchers_.find(key); |
539 if (it != watchers_.end()) { | 578 if (it != watchers_.end()) { |
540 const bool exists = it->second.subscribers.find(args.origin) != | 579 const bool exists = it->second.subscribers.find(args.origin) != |
541 it->second.subscribers.end(); | 580 it->second.subscribers.end(); |
542 OnAddWatcherInQueueCompleted( | 581 OnAddWatcherInQueueCompleted( |
543 args.token, args.entry_path, args.recursive, subscriber, args.callback, | 582 args.token, args.entry_path, args.recursive, subscriber, args.callback, |
544 exists ? base::File::FILE_ERROR_EXISTS : base::File::FILE_OK); | 583 exists ? base::File::FILE_ERROR_EXISTS : base::File::FILE_OK); |
545 return AbortCallback(); | 584 return AbortCallback(); |
546 } | 585 } |
547 | 586 |
548 const int request_id = request_manager_->CreateRequest( | 587 const int request_id = request_manager_->CreateRequest( |
549 ADD_WATCHER, | 588 ADD_WATCHER, |
550 scoped_ptr<RequestManager::HandlerInterface>(new operations::AddWatcher( | 589 scoped_ptr<RequestManager::HandlerInterface>( |
551 event_router_, file_system_info_, args.entry_path, args.recursive, | 590 new operations::AddWatcher<DestinationPolicy>( |
552 base::Bind(&ProvidedFileSystem::OnAddWatcherInQueueCompleted, | 591 event_router_, file_system_info_, args.entry_path, args.recursive, |
553 weak_ptr_factory_.GetWeakPtr(), args.token, | 592 base::Bind( |
554 args.entry_path, args.recursive, subscriber, | 593 &ProvidedFileSystem<DestinationPolicy>:: |
555 args.callback)))); | 594 OnAddWatcherInQueueCompleted, |
| 595 weak_ptr_factory_.GetWeakPtr(), args.token, args.entry_path, |
| 596 args.recursive, subscriber, args.callback)))); |
556 | 597 |
557 if (!request_id) { | 598 if (!request_id) { |
558 OnAddWatcherInQueueCompleted(args.token, args.entry_path, args.recursive, | 599 OnAddWatcherInQueueCompleted(args.token, args.entry_path, args.recursive, |
559 subscriber, args.callback, | 600 subscriber, args.callback, |
560 base::File::FILE_ERROR_SECURITY); | 601 base::File::FILE_ERROR_SECURITY); |
561 } | 602 } |
562 | 603 |
563 return AbortCallback(); | 604 return AbortCallback(); |
564 } | 605 } |
565 | 606 |
566 AbortCallback ProvidedFileSystem::RemoveWatcherInQueue( | 607 template <class DestinationPolicy> |
| 608 AbortCallback ProvidedFileSystem<DestinationPolicy>::RemoveWatcherInQueue( |
567 size_t token, | 609 size_t token, |
568 const GURL& origin, | 610 const GURL& origin, |
569 const base::FilePath& entry_path, | 611 const base::FilePath& entry_path, |
570 bool recursive, | 612 bool recursive, |
571 const storage::AsyncFileUtil::StatusCallback& callback) { | 613 const storage::AsyncFileUtil::StatusCallback& callback) { |
572 const WatcherKey key(entry_path, recursive); | 614 const WatcherKey key(entry_path, recursive); |
573 const Watchers::iterator it = watchers_.find(key); | 615 const Watchers::iterator it = watchers_.find(key); |
574 if (it == watchers_.end() || | 616 if (it == watchers_.end() || |
575 it->second.subscribers.find(origin) == it->second.subscribers.end()) { | 617 it->second.subscribers.find(origin) == it->second.subscribers.end()) { |
576 OnRemoveWatcherInQueueCompleted(token, origin, key, callback, | 618 OnRemoveWatcherInQueueCompleted(token, origin, key, callback, |
577 false /* extension_response */, | 619 false /* extension_response */, |
578 base::File::FILE_ERROR_NOT_FOUND); | 620 base::File::FILE_ERROR_NOT_FOUND); |
579 return AbortCallback(); | 621 return AbortCallback(); |
580 } | 622 } |
581 | 623 |
582 // If there are other subscribers, then do not remove the observer, but simply | 624 // If there are other subscribers, then do not remove the observer, but simply |
583 // return a success. | 625 // return a success. |
584 if (it->second.subscribers.size() > 1) { | 626 if (it->second.subscribers.size() > 1) { |
585 OnRemoveWatcherInQueueCompleted(token, origin, key, callback, | 627 OnRemoveWatcherInQueueCompleted(token, origin, key, callback, |
586 false /* extension_response */, | 628 false /* extension_response */, |
587 base::File::FILE_OK); | 629 base::File::FILE_OK); |
588 return AbortCallback(); | 630 return AbortCallback(); |
589 } | 631 } |
590 | 632 |
591 // Otherwise, emit an event, and remove the watcher. | 633 // Otherwise, emit an event, and remove the watcher. |
592 request_manager_->CreateRequest( | 634 request_manager_->CreateRequest( |
593 REMOVE_WATCHER, | 635 REMOVE_WATCHER, |
594 scoped_ptr<RequestManager::HandlerInterface>( | 636 scoped_ptr<RequestManager::HandlerInterface>( |
595 new operations::RemoveWatcher( | 637 new operations::RemoveWatcher<DestinationPolicy>( |
596 event_router_, file_system_info_, entry_path, recursive, | 638 event_router_, file_system_info_, entry_path, recursive, |
597 base::Bind(&ProvidedFileSystem::OnRemoveWatcherInQueueCompleted, | 639 base::Bind( |
598 weak_ptr_factory_.GetWeakPtr(), token, origin, key, | 640 &ProvidedFileSystem<DestinationPolicy>:: |
599 callback, true /* extension_response */)))); | 641 OnRemoveWatcherInQueueCompleted, |
| 642 weak_ptr_factory_.GetWeakPtr(), token, origin, key, callback, |
| 643 true /* extension_response */)))); |
600 | 644 |
601 return AbortCallback(); | 645 return AbortCallback(); |
602 } | 646 } |
603 | 647 |
604 AbortCallback ProvidedFileSystem::NotifyInQueue( | 648 template <class DestinationPolicy> |
| 649 AbortCallback ProvidedFileSystem<DestinationPolicy>::NotifyInQueue( |
605 scoped_ptr<NotifyInQueueArgs> args) { | 650 scoped_ptr<NotifyInQueueArgs> args) { |
606 const WatcherKey key(args->entry_path, args->recursive); | 651 const WatcherKey key(args->entry_path, args->recursive); |
607 const auto& watcher_it = watchers_.find(key); | 652 const auto& watcher_it = watchers_.find(key); |
608 if (watcher_it == watchers_.end()) { | 653 if (watcher_it == watchers_.end()) { |
609 OnNotifyInQueueCompleted(args.Pass(), base::File::FILE_ERROR_NOT_FOUND); | 654 OnNotifyInQueueCompleted(args.Pass(), base::File::FILE_ERROR_NOT_FOUND); |
610 return AbortCallback(); | 655 return AbortCallback(); |
611 } | 656 } |
612 | 657 |
613 // The tag must be provided if and only if it's explicitly supported. | 658 // The tag must be provided if and only if it's explicitly supported. |
614 if (file_system_info_.supports_notify_tag() == args->tag.empty()) { | 659 if (file_system_info_.supports_notify_tag() == args->tag.empty()) { |
615 OnNotifyInQueueCompleted(args.Pass(), | 660 OnNotifyInQueueCompleted(args.Pass(), |
616 base::File::FILE_ERROR_INVALID_OPERATION); | 661 base::File::FILE_ERROR_INVALID_OPERATION); |
617 return AbortCallback(); | 662 return AbortCallback(); |
618 } | 663 } |
619 | 664 |
620 // It's illegal to provide a tag which is not unique. | 665 // It's illegal to provide a tag which is not unique. |
621 if (!args->tag.empty() && args->tag == watcher_it->second.last_tag) { | 666 if (!args->tag.empty() && args->tag == watcher_it->second.last_tag) { |
622 OnNotifyInQueueCompleted(args.Pass(), | 667 OnNotifyInQueueCompleted(args.Pass(), |
623 base::File::FILE_ERROR_INVALID_OPERATION); | 668 base::File::FILE_ERROR_INVALID_OPERATION); |
624 return AbortCallback(); | 669 return AbortCallback(); |
625 } | 670 } |
626 | 671 |
627 // The object is owned by AutoUpdated, so the reference is valid as long as | 672 // The object is owned by AutoUpdated, so the reference is valid as long as |
628 // callbacks created with AutoUpdater::CreateCallback(). | 673 // callbacks created with AutoUpdater::CreateCallback(). |
629 const ProvidedFileSystemObserver::Changes& changes_ref = *args->changes.get(); | 674 const ProvidedFileSystemObserver::Changes& changes_ref = *args->changes.get(); |
630 const storage::WatcherManager::ChangeType change_type = args->change_type; | 675 const storage::WatcherManager::ChangeType change_type = args->change_type; |
631 | 676 |
632 scoped_refptr<AutoUpdater> auto_updater( | 677 scoped_refptr<AutoUpdater> auto_updater(new AutoUpdater( |
633 new AutoUpdater(base::Bind(&ProvidedFileSystem::OnNotifyInQueueCompleted, | 678 base::Bind( |
634 weak_ptr_factory_.GetWeakPtr(), | 679 &ProvidedFileSystem<DestinationPolicy>::OnNotifyInQueueCompleted, |
635 base::Passed(&args), base::File::FILE_OK))); | 680 weak_ptr_factory_.GetWeakPtr(), base::Passed(&args), |
| 681 base::File::FILE_OK))); |
636 | 682 |
637 // Call all notification callbacks (if any). | 683 // Call all notification callbacks (if any). |
638 for (const auto& subscriber_it : watcher_it->second.subscribers) { | 684 for (const auto& subscriber_it : watcher_it->second.subscribers) { |
639 const storage::WatcherManager::NotificationCallback& notification_callback = | 685 const storage::WatcherManager::NotificationCallback& notification_callback = |
640 subscriber_it.second.notification_callback; | 686 subscriber_it.second.notification_callback; |
641 if (!notification_callback.is_null()) | 687 if (!notification_callback.is_null()) |
642 notification_callback.Run(change_type); | 688 notification_callback.Run(change_type); |
643 } | 689 } |
644 | 690 |
645 // Notify all observers. | 691 // Notify all observers. |
646 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 692 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, |
647 observers_, | 693 observers_, |
648 OnWatcherChanged(file_system_info_, | 694 OnWatcherChanged(file_system_info_, |
649 watcher_it->second, | 695 watcher_it->second, |
650 change_type, | 696 change_type, |
651 changes_ref, | 697 changes_ref, |
652 auto_updater->CreateCallback())); | 698 auto_updater->CreateCallback())); |
653 | 699 |
654 return AbortCallback(); | 700 return AbortCallback(); |
655 } | 701 } |
656 | 702 |
657 base::WeakPtr<ProvidedFileSystemInterface> ProvidedFileSystem::GetWeakPtr() { | 703 template <class DestinationPolicy> |
| 704 base::WeakPtr<ProvidedFileSystemInterface> |
| 705 ProvidedFileSystem<DestinationPolicy>::GetWeakPtr() { |
658 return weak_ptr_factory_.GetWeakPtr(); | 706 return weak_ptr_factory_.GetWeakPtr(); |
659 } | 707 } |
660 | 708 |
661 void ProvidedFileSystem::OnAddWatcherInQueueCompleted( | 709 template <class DestinationPolicy> |
| 710 void ProvidedFileSystem<DestinationPolicy>::OnAddWatcherInQueueCompleted( |
662 size_t token, | 711 size_t token, |
663 const base::FilePath& entry_path, | 712 const base::FilePath& entry_path, |
664 bool recursive, | 713 bool recursive, |
665 const Subscriber& subscriber, | 714 const Subscriber& subscriber, |
666 const storage::AsyncFileUtil::StatusCallback& callback, | 715 const storage::AsyncFileUtil::StatusCallback& callback, |
667 base::File::Error result) { | 716 base::File::Error result) { |
668 if (result != base::File::FILE_OK) { | 717 if (result != base::File::FILE_OK) { |
669 callback.Run(result); | 718 callback.Run(result); |
670 watcher_queue_.Complete(token); | 719 watcher_queue_.Complete(token); |
671 return; | 720 return; |
(...skipping 13 matching lines...) Expand all Loading... |
685 watcher->subscribers[subscriber.origin] = subscriber; | 734 watcher->subscribers[subscriber.origin] = subscriber; |
686 | 735 |
687 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 736 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, |
688 observers_, | 737 observers_, |
689 OnWatcherListChanged(file_system_info_, watchers_)); | 738 OnWatcherListChanged(file_system_info_, watchers_)); |
690 | 739 |
691 callback.Run(base::File::FILE_OK); | 740 callback.Run(base::File::FILE_OK); |
692 watcher_queue_.Complete(token); | 741 watcher_queue_.Complete(token); |
693 } | 742 } |
694 | 743 |
695 void ProvidedFileSystem::OnRemoveWatcherInQueueCompleted( | 744 template <class DestinationPolicy> |
| 745 void ProvidedFileSystem<DestinationPolicy>::OnRemoveWatcherInQueueCompleted( |
696 size_t token, | 746 size_t token, |
697 const GURL& origin, | 747 const GURL& origin, |
698 const WatcherKey& key, | 748 const WatcherKey& key, |
699 const storage::AsyncFileUtil::StatusCallback& callback, | 749 const storage::AsyncFileUtil::StatusCallback& callback, |
700 bool extension_response, | 750 bool extension_response, |
701 base::File::Error result) { | 751 base::File::Error result) { |
702 if (!extension_response && result != base::File::FILE_OK) { | 752 if (!extension_response && result != base::File::FILE_OK) { |
703 watcher_queue_.Complete(token); | 753 watcher_queue_.Complete(token); |
704 callback.Run(result); | 754 callback.Run(result); |
705 return; | 755 return; |
(...skipping 11 matching lines...) Expand all Loading... |
717 OnWatcherListChanged(file_system_info_, watchers_)); | 767 OnWatcherListChanged(file_system_info_, watchers_)); |
718 | 768 |
719 // If there are no more subscribers, then remove the watcher. | 769 // If there are no more subscribers, then remove the watcher. |
720 if (!it->second.subscribers.size()) | 770 if (!it->second.subscribers.size()) |
721 watchers_.erase(it); | 771 watchers_.erase(it); |
722 | 772 |
723 callback.Run(base::File::FILE_OK); | 773 callback.Run(base::File::FILE_OK); |
724 watcher_queue_.Complete(token); | 774 watcher_queue_.Complete(token); |
725 } | 775 } |
726 | 776 |
727 void ProvidedFileSystem::OnNotifyInQueueCompleted( | 777 template <class DestinationPolicy> |
| 778 void ProvidedFileSystem<DestinationPolicy>::OnNotifyInQueueCompleted( |
728 scoped_ptr<NotifyInQueueArgs> args, | 779 scoped_ptr<NotifyInQueueArgs> args, |
729 base::File::Error result) { | 780 base::File::Error result) { |
730 if (result != base::File::FILE_OK) { | 781 if (result != base::File::FILE_OK) { |
731 args->callback.Run(result); | 782 args->callback.Run(result); |
732 watcher_queue_.Complete(args->token); | 783 watcher_queue_.Complete(args->token); |
733 return; | 784 return; |
734 } | 785 } |
735 | 786 |
736 // Check if the entry is still watched. | 787 // Check if the entry is still watched. |
737 const WatcherKey key(args->entry_path, args->recursive); | 788 const WatcherKey key(args->entry_path, args->recursive); |
(...skipping 18 matching lines...) Expand all Loading... |
756 for (const auto& subscriber_it : subscribers) { | 807 for (const auto& subscriber_it : subscribers) { |
757 RemoveWatcher(subscriber_it.second.origin, args->entry_path, | 808 RemoveWatcher(subscriber_it.second.origin, args->entry_path, |
758 args->recursive, base::Bind(&EmptyStatusCallback)); | 809 args->recursive, base::Bind(&EmptyStatusCallback)); |
759 } | 810 } |
760 } | 811 } |
761 | 812 |
762 args->callback.Run(base::File::FILE_OK); | 813 args->callback.Run(base::File::FILE_OK); |
763 watcher_queue_.Complete(args->token); | 814 watcher_queue_.Complete(args->token); |
764 } | 815 } |
765 | 816 |
766 void ProvidedFileSystem::OnOpenFileCompleted(const base::FilePath& file_path, | 817 template <class DestinationPolicy> |
767 OpenFileMode mode, | 818 void ProvidedFileSystem<DestinationPolicy>::OnOpenFileCompleted( |
768 const OpenFileCallback& callback, | 819 const base::FilePath& file_path, |
769 int file_handle, | 820 OpenFileMode mode, |
770 base::File::Error result) { | 821 const OpenFileCallback& callback, |
| 822 int file_handle, |
| 823 base::File::Error result) { |
771 if (result != base::File::FILE_OK) { | 824 if (result != base::File::FILE_OK) { |
772 callback.Run(file_handle, result); | 825 callback.Run(file_handle, result); |
773 return; | 826 return; |
774 } | 827 } |
775 | 828 |
776 opened_files_[file_handle] = OpenedFile(file_path, mode); | 829 opened_files_[file_handle] = OpenedFile(file_path, mode); |
777 callback.Run(file_handle, base::File::FILE_OK); | 830 callback.Run(file_handle, base::File::FILE_OK); |
778 } | 831 } |
779 | 832 |
780 void ProvidedFileSystem::OnCloseFileCompleted( | 833 template <class DestinationPolicy> |
| 834 void ProvidedFileSystem<DestinationPolicy>::OnCloseFileCompleted( |
781 int file_handle, | 835 int file_handle, |
782 const storage::AsyncFileUtil::StatusCallback& callback, | 836 const storage::AsyncFileUtil::StatusCallback& callback, |
783 base::File::Error result) { | 837 base::File::Error result) { |
784 // Closing files is final. Even if an error happened, we remove it from the | 838 // Closing files is final. Even if an error happened, we remove it from the |
785 // list of opened files. | 839 // list of opened files. |
786 opened_files_.erase(file_handle); | 840 opened_files_.erase(file_handle); |
787 callback.Run(result); | 841 callback.Run(result); |
788 } | 842 } |
789 | 843 |
| 844 FOR_EACH_DESTINATION_SPECIALIZE(ProvidedFileSystem) |
| 845 |
790 } // namespace file_system_provider | 846 } // namespace file_system_provider |
791 } // namespace chromeos | 847 } // namespace chromeos |
OLD | NEW |