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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/provided_file_system.cc

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

Powered by Google App Engine
This is Rietveld 408576698