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

Side by Side Diff: webkit/fileapi/file_system_operation.cc

Issue 10197007: Change webkit/{fileapi,quota} code to use TaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/fileapi/file_system_operation.h" 5 #include "webkit/fileapi/file_system_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/task_runner.h"
8 #include "base/time.h" 9 #include "base/time.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
10 #include "net/base/escape.h" 11 #include "net/base/escape.h"
11 #include "net/url_request/url_request_context.h" 12 #include "net/url_request/url_request_context.h"
12 #include "webkit/blob/shareable_file_reference.h" 13 #include "webkit/blob/shareable_file_reference.h"
13 #include "webkit/fileapi/file_system_context.h" 14 #include "webkit/fileapi/file_system_context.h"
14 #include "webkit/fileapi/file_system_file_util_proxy.h" 15 #include "webkit/fileapi/file_system_file_util_proxy.h"
15 #include "webkit/fileapi/file_system_mount_point_provider.h" 16 #include "webkit/fileapi/file_system_mount_point_provider.h"
16 #include "webkit/fileapi/file_system_operation_context.h" 17 #include "webkit/fileapi/file_system_operation_context.h"
17 #include "webkit/fileapi/file_system_quota_util.h" 18 #include "webkit/fileapi/file_system_quota_util.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 : type(kFileSystemTypeUnknown) { 76 : type(kFileSystemTypeUnknown) {
76 } 77 }
77 78
78 FileSystemOperation::TaskParamsForDidGetQuota::~TaskParamsForDidGetQuota() {} 79 FileSystemOperation::TaskParamsForDidGetQuota::~TaskParamsForDidGetQuota() {}
79 80
80 FileSystemOperation::~FileSystemOperation() { 81 FileSystemOperation::~FileSystemOperation() {
81 if (file_writer_delegate_.get()) { 82 if (file_writer_delegate_.get()) {
82 FileSystemOperationContext* c = 83 FileSystemOperationContext* c =
83 new FileSystemOperationContext(operation_context_); 84 new FileSystemOperationContext(operation_context_);
84 base::FileUtilProxy::RelayClose( 85 base::FileUtilProxy::RelayClose(
85 proxy_, 86 task_runner_,
86 base::Bind(&FileSystemFileUtil::Close, 87 base::Bind(&FileSystemFileUtil::Close,
87 base::Unretained(src_util_), 88 base::Unretained(src_util_),
88 base::Owned(c)), 89 base::Owned(c)),
89 file_writer_delegate_->file(), 90 file_writer_delegate_->file(),
90 base::FileUtilProxy::StatusCallback()); 91 base::FileUtilProxy::StatusCallback());
91 } 92 }
92 } 93 }
93 94
94 void FileSystemOperation::CreateFile(const GURL& path_url, 95 void FileSystemOperation::CreateFile(const GURL& path_url,
95 bool exclusive, 96 bool exclusive,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 184
184 base::PlatformFileError result = SetUpFileSystemPath( 185 base::PlatformFileError result = SetUpFileSystemPath(
185 path_url, &src_path_, &src_util_, PATH_FOR_READ); 186 path_url, &src_path_, &src_util_, PATH_FOR_READ);
186 if (result != base::PLATFORM_FILE_OK) { 187 if (result != base::PLATFORM_FILE_OK) {
187 callback.Run(result); 188 callback.Run(result);
188 delete this; 189 delete this;
189 return; 190 return;
190 } 191 }
191 192
192 FileSystemFileUtilProxy::GetFileInfo( 193 FileSystemFileUtilProxy::GetFileInfo(
193 proxy_, &operation_context_, src_util_, src_path_, 194 task_runner_, &operation_context_, src_util_, src_path_,
194 base::Bind(&FileSystemOperation::DidDirectoryExists, 195 base::Bind(&FileSystemOperation::DidDirectoryExists,
195 base::Owned(this), callback)); 196 base::Owned(this), callback));
196 } 197 }
197 198
198 void FileSystemOperation::FileExists(const GURL& path_url, 199 void FileSystemOperation::FileExists(const GURL& path_url,
199 const StatusCallback& callback) { 200 const StatusCallback& callback) {
200 DCHECK(SetPendingOperationType(kOperationFileExists)); 201 DCHECK(SetPendingOperationType(kOperationFileExists));
201 202
202 base::PlatformFileError result = SetUpFileSystemPath( 203 base::PlatformFileError result = SetUpFileSystemPath(
203 path_url, &src_path_, &src_util_, PATH_FOR_READ); 204 path_url, &src_path_, &src_util_, PATH_FOR_READ);
204 if (result != base::PLATFORM_FILE_OK) { 205 if (result != base::PLATFORM_FILE_OK) {
205 callback.Run(result); 206 callback.Run(result);
206 delete this; 207 delete this;
207 return; 208 return;
208 } 209 }
209 210
210 FileSystemFileUtilProxy::GetFileInfo( 211 FileSystemFileUtilProxy::GetFileInfo(
211 proxy_, &operation_context_, src_util_, src_path_, 212 task_runner_, &operation_context_, src_util_, src_path_,
212 base::Bind(&FileSystemOperation::DidFileExists, 213 base::Bind(&FileSystemOperation::DidFileExists,
213 base::Owned(this), callback)); 214 base::Owned(this), callback));
214 } 215 }
215 216
216 void FileSystemOperation::GetMetadata(const GURL& path_url, 217 void FileSystemOperation::GetMetadata(const GURL& path_url,
217 const GetMetadataCallback& callback) { 218 const GetMetadataCallback& callback) {
218 DCHECK(SetPendingOperationType(kOperationGetMetadata)); 219 DCHECK(SetPendingOperationType(kOperationGetMetadata));
219 220
220 base::PlatformFileError result = SetUpFileSystemPath( 221 base::PlatformFileError result = SetUpFileSystemPath(
221 path_url, &src_path_, &src_util_, PATH_FOR_READ); 222 path_url, &src_path_, &src_util_, PATH_FOR_READ);
222 if (result != base::PLATFORM_FILE_OK) { 223 if (result != base::PLATFORM_FILE_OK) {
223 callback.Run(result, base::PlatformFileInfo(), FilePath()); 224 callback.Run(result, base::PlatformFileInfo(), FilePath());
224 delete this; 225 delete this;
225 return; 226 return;
226 } 227 }
227 228
228 FileSystemFileUtilProxy::GetFileInfo( 229 FileSystemFileUtilProxy::GetFileInfo(
229 proxy_, &operation_context_, src_util_, src_path_, 230 task_runner_, &operation_context_, src_util_, src_path_,
230 base::Bind(&FileSystemOperation::DidGetMetadata, 231 base::Bind(&FileSystemOperation::DidGetMetadata,
231 base::Owned(this), callback)); 232 base::Owned(this), callback));
232 } 233 }
233 234
234 void FileSystemOperation::ReadDirectory(const GURL& path_url, 235 void FileSystemOperation::ReadDirectory(const GURL& path_url,
235 const ReadDirectoryCallback& callback) { 236 const ReadDirectoryCallback& callback) {
236 DCHECK(SetPendingOperationType(kOperationReadDirectory)); 237 DCHECK(SetPendingOperationType(kOperationReadDirectory));
237 238
238 base::PlatformFileError result = SetUpFileSystemPath( 239 base::PlatformFileError result = SetUpFileSystemPath(
239 path_url, &src_path_, &src_util_, PATH_FOR_READ); 240 path_url, &src_path_, &src_util_, PATH_FOR_READ);
240 if (result != base::PLATFORM_FILE_OK) { 241 if (result != base::PLATFORM_FILE_OK) {
241 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); 242 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
242 delete this; 243 delete this;
243 return; 244 return;
244 } 245 }
245 246
246 FileSystemFileUtilProxy::ReadDirectory( 247 FileSystemFileUtilProxy::ReadDirectory(
247 proxy_, &operation_context_, src_util_, src_path_, 248 task_runner_, &operation_context_, src_util_, src_path_,
248 base::Bind(&FileSystemOperation::DidReadDirectory, 249 base::Bind(&FileSystemOperation::DidReadDirectory,
249 base::Owned(this), callback)); 250 base::Owned(this), callback));
250 } 251 }
251 252
252 void FileSystemOperation::Remove(const GURL& path_url, bool recursive, 253 void FileSystemOperation::Remove(const GURL& path_url, bool recursive,
253 const StatusCallback& callback) { 254 const StatusCallback& callback) {
254 DCHECK(SetPendingOperationType(kOperationRemove)); 255 DCHECK(SetPendingOperationType(kOperationRemove));
255 256
256 base::PlatformFileError result = SetUpFileSystemPath( 257 base::PlatformFileError result = SetUpFileSystemPath(
257 path_url, &src_path_, &src_util_, PATH_FOR_WRITE); 258 path_url, &src_path_, &src_util_, PATH_FOR_WRITE);
258 if (result != base::PLATFORM_FILE_OK) { 259 if (result != base::PLATFORM_FILE_OK) {
259 callback.Run(result); 260 callback.Run(result);
260 delete this; 261 delete this;
261 return; 262 return;
262 } 263 }
263 264
264 scoped_quota_notifier_.reset(new ScopedQuotaNotifier( 265 scoped_quota_notifier_.reset(new ScopedQuotaNotifier(
265 file_system_context(), src_path_.origin(), src_path_.type())); 266 file_system_context(), src_path_.origin(), src_path_.type()));
266 267
267 FileSystemFileUtilProxy::Delete( 268 FileSystemFileUtilProxy::Delete(
268 proxy_, &operation_context_, src_util_, src_path_, recursive, 269 task_runner_, &operation_context_, src_util_, src_path_, recursive,
269 base::Bind(&FileSystemOperation::DidFinishFileOperation, 270 base::Bind(&FileSystemOperation::DidFinishFileOperation,
270 base::Owned(this), callback)); 271 base::Owned(this), callback));
271 } 272 }
272 273
273 void FileSystemOperation::Write( 274 void FileSystemOperation::Write(
274 const net::URLRequestContext* url_request_context, 275 const net::URLRequestContext* url_request_context,
275 const GURL& path_url, 276 const GURL& path_url,
276 const GURL& blob_url, 277 const GURL& blob_url,
277 int64 offset, 278 int64 offset,
278 const WriteCallback& callback) { 279 const WriteCallback& callback) {
279 DCHECK(SetPendingOperationType(kOperationWrite)); 280 DCHECK(SetPendingOperationType(kOperationWrite));
280 281
281 base::PlatformFileError result = SetUpFileSystemPath( 282 base::PlatformFileError result = SetUpFileSystemPath(
282 path_url, &src_path_, &src_util_, PATH_FOR_WRITE); 283 path_url, &src_path_, &src_util_, PATH_FOR_WRITE);
283 if (result != base::PLATFORM_FILE_OK) { 284 if (result != base::PLATFORM_FILE_OK) {
284 callback.Run(result, 0, false); 285 callback.Run(result, 0, false);
285 delete this; 286 delete this;
286 return; 287 return;
287 } 288 }
288 DCHECK(blob_url.is_valid()); 289 DCHECK(blob_url.is_valid());
289 file_writer_delegate_.reset(new FileWriterDelegate( 290 file_writer_delegate_.reset(new FileWriterDelegate(
290 this, src_path_, offset, proxy_)); 291 this, src_path_, offset, task_runner_));
291 set_write_callback(callback); 292 set_write_callback(callback);
292 blob_request_.reset( 293 blob_request_.reset(
293 new net::URLRequest(blob_url, file_writer_delegate_.get())); 294 new net::URLRequest(blob_url, file_writer_delegate_.get()));
294 blob_request_->set_context(url_request_context); 295 blob_request_->set_context(url_request_context);
295 296
296 GetUsageAndQuotaThenRunTask( 297 GetUsageAndQuotaThenRunTask(
297 src_path_.origin(), src_path_.type(), 298 src_path_.origin(), src_path_.type(),
298 base::Bind(&FileSystemOperation::DoWrite, base::Unretained(this)), 299 base::Bind(&FileSystemOperation::DoWrite, base::Unretained(this)),
299 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, 0, true)); 300 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, 0, true));
300 } 301 }
(...skipping 24 matching lines...) Expand all
325 326
326 base::PlatformFileError result = SetUpFileSystemPath( 327 base::PlatformFileError result = SetUpFileSystemPath(
327 path_url, &src_path_, &src_util_, PATH_FOR_WRITE); 328 path_url, &src_path_, &src_util_, PATH_FOR_WRITE);
328 if (result != base::PLATFORM_FILE_OK) { 329 if (result != base::PLATFORM_FILE_OK) {
329 callback.Run(result); 330 callback.Run(result);
330 delete this; 331 delete this;
331 return; 332 return;
332 } 333 }
333 334
334 FileSystemFileUtilProxy::Touch( 335 FileSystemFileUtilProxy::Touch(
335 proxy_, &operation_context_, src_util_, src_path_, 336 task_runner_, &operation_context_, src_util_, src_path_,
336 last_access_time, last_modified_time, 337 last_access_time, last_modified_time,
337 base::Bind(&FileSystemOperation::DidTouchFile, 338 base::Bind(&FileSystemOperation::DidTouchFile,
338 base::Owned(this), callback)); 339 base::Owned(this), callback));
339 } 340 }
340 341
341 void FileSystemOperation::OpenFile(const GURL& path_url, 342 void FileSystemOperation::OpenFile(const GURL& path_url,
342 int file_flags, 343 int file_flags,
343 base::ProcessHandle peer_handle, 344 base::ProcessHandle peer_handle,
344 const OpenFileCallback& callback) { 345 const OpenFileCallback& callback) {
345 DCHECK(SetPendingOperationType(kOperationOpenFile)); 346 DCHECK(SetPendingOperationType(kOperationOpenFile));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 delete this; 438 delete this;
438 } 439 }
439 440
440 void FileSystemOperation::CreateSnapshotFile( 441 void FileSystemOperation::CreateSnapshotFile(
441 const GURL& path_url, 442 const GURL& path_url,
442 const SnapshotFileCallback& callback) { 443 const SnapshotFileCallback& callback) {
443 GetMetadata(path_url, base::Bind(&GetMetadataForSnapshot, callback)); 444 GetMetadata(path_url, base::Bind(&GetMetadataForSnapshot, callback));
444 } 445 }
445 446
446 FileSystemOperation::FileSystemOperation( 447 FileSystemOperation::FileSystemOperation(
447 scoped_refptr<base::MessageLoopProxy> proxy, 448 base::TaskRunner* task_runner,
448 FileSystemContext* file_system_context) 449 FileSystemContext* file_system_context)
449 : proxy_(proxy), 450 : task_runner_(task_runner),
450 operation_context_(file_system_context), 451 operation_context_(file_system_context),
451 src_util_(NULL), 452 src_util_(NULL),
452 dest_util_(NULL), 453 dest_util_(NULL),
453 peer_handle_(base::kNullProcessHandle), 454 peer_handle_(base::kNullProcessHandle),
454 pending_operation_(kOperationNone) { 455 pending_operation_(kOperationNone) {
455 } 456 }
456 457
457 void FileSystemOperation::GetUsageAndQuotaThenRunTask( 458 void FileSystemOperation::GetUsageAndQuotaThenRunTask(
458 const GURL& origin, FileSystemType type, 459 const GURL& origin, FileSystemType type,
459 const base::Closure& task, 460 const base::Closure& task,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 scoped_quota_notifier_.reset(new ScopedQuotaNotifier( 499 scoped_quota_notifier_.reset(new ScopedQuotaNotifier(
499 file_system_context(), params.origin, params.type)); 500 file_system_context(), params.origin, params.type));
500 501
501 params.task.Run(); 502 params.task.Run();
502 } 503 }
503 504
504 void FileSystemOperation::DoCreateFile( 505 void FileSystemOperation::DoCreateFile(
505 const StatusCallback& callback, 506 const StatusCallback& callback,
506 bool exclusive) { 507 bool exclusive) {
507 FileSystemFileUtilProxy::EnsureFileExists( 508 FileSystemFileUtilProxy::EnsureFileExists(
508 proxy_, &operation_context_, src_util_, src_path_, 509 task_runner_, &operation_context_, src_util_, src_path_,
509 base::Bind( 510 base::Bind(
510 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive 511 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive
511 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, 512 : &FileSystemOperation::DidEnsureFileExistsNonExclusive,
512 base::Owned(this), callback)); 513 base::Owned(this), callback));
513 } 514 }
514 515
515 void FileSystemOperation::DoCreateDirectory( 516 void FileSystemOperation::DoCreateDirectory(
516 const StatusCallback& callback, 517 const StatusCallback& callback,
517 bool exclusive, bool recursive) { 518 bool exclusive, bool recursive) {
518 FileSystemFileUtilProxy::CreateDirectory( 519 FileSystemFileUtilProxy::CreateDirectory(
519 proxy_, &operation_context_, src_util_, src_path_, exclusive, recursive, 520 task_runner_, &operation_context_,
521 src_util_, src_path_, exclusive, recursive,
520 base::Bind(&FileSystemOperation::DidFinishFileOperation, 522 base::Bind(&FileSystemOperation::DidFinishFileOperation,
521 base::Owned(this), callback)); 523 base::Owned(this), callback));
522 } 524 }
523 525
524 void FileSystemOperation::DoCopy(const StatusCallback& callback) { 526 void FileSystemOperation::DoCopy(const StatusCallback& callback) {
525 FileSystemFileUtilProxy::Copy( 527 FileSystemFileUtilProxy::Copy(
526 proxy_, &operation_context_, 528 task_runner_, &operation_context_,
527 src_util_, dest_util_, 529 src_util_, dest_util_,
528 src_path_, dest_path_, 530 src_path_, dest_path_,
529 base::Bind(&FileSystemOperation::DidFinishFileOperation, 531 base::Bind(&FileSystemOperation::DidFinishFileOperation,
530 base::Owned(this), callback)); 532 base::Owned(this), callback));
531 } 533 }
532 534
533 void FileSystemOperation::DoMove(const StatusCallback& callback) { 535 void FileSystemOperation::DoMove(const StatusCallback& callback) {
534 FileSystemFileUtilProxy::Move( 536 FileSystemFileUtilProxy::Move(
535 proxy_, &operation_context_, 537 task_runner_, &operation_context_,
536 src_util_, dest_util_, 538 src_util_, dest_util_,
537 src_path_, dest_path_, 539 src_path_, dest_path_,
538 base::Bind(&FileSystemOperation::DidFinishFileOperation, 540 base::Bind(&FileSystemOperation::DidFinishFileOperation,
539 base::Owned(this), callback)); 541 base::Owned(this), callback));
540 } 542 }
541 543
542 void FileSystemOperation::DoWrite() { 544 void FileSystemOperation::DoWrite() {
543 int file_flags = base::PLATFORM_FILE_OPEN | 545 int file_flags = base::PLATFORM_FILE_OPEN |
544 base::PLATFORM_FILE_WRITE | 546 base::PLATFORM_FILE_WRITE |
545 base::PLATFORM_FILE_ASYNC; 547 base::PLATFORM_FILE_ASYNC;
546 548
547 FileSystemFileUtilProxy::CreateOrOpen( 549 FileSystemFileUtilProxy::CreateOrOpen(
548 proxy_, &operation_context_, src_util_, src_path_, file_flags, 550 task_runner_, &operation_context_, src_util_, src_path_, file_flags,
549 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, 551 base::Bind(&FileSystemOperation::OnFileOpenedForWrite,
550 base::Unretained(this))); 552 base::Unretained(this)));
551 } 553 }
552 554
553 void FileSystemOperation::DoTruncate(const StatusCallback& callback, 555 void FileSystemOperation::DoTruncate(const StatusCallback& callback,
554 int64 length) { 556 int64 length) {
555 FileSystemFileUtilProxy::Truncate( 557 FileSystemFileUtilProxy::Truncate(
556 proxy_, &operation_context_, src_util_, src_path_, length, 558 task_runner_, &operation_context_, src_util_, src_path_, length,
557 base::Bind(&FileSystemOperation::DidFinishFileOperation, 559 base::Bind(&FileSystemOperation::DidFinishFileOperation,
558 base::Owned(this), callback)); 560 base::Owned(this), callback));
559 } 561 }
560 562
561 void FileSystemOperation::DoOpenFile(const OpenFileCallback& callback, 563 void FileSystemOperation::DoOpenFile(const OpenFileCallback& callback,
562 int file_flags) { 564 int file_flags) {
563 FileSystemFileUtilProxy::CreateOrOpen( 565 FileSystemFileUtilProxy::CreateOrOpen(
564 proxy_, &operation_context_, src_util_, src_path_, file_flags, 566 task_runner_, &operation_context_, src_util_, src_path_, file_flags,
565 base::Bind(&FileSystemOperation::DidOpenFile, 567 base::Bind(&FileSystemOperation::DidOpenFile,
566 base::Owned(this), callback)); 568 base::Owned(this), callback));
567 } 569 }
568 570
569 void FileSystemOperation::DidEnsureFileExistsExclusive( 571 void FileSystemOperation::DidEnsureFileExistsExclusive(
570 const StatusCallback& callback, 572 const StatusCallback& callback,
571 base::PlatformFileError rv, bool created) { 573 base::PlatformFileError rv, bool created) {
572 if (rv == base::PLATFORM_FILE_OK && !created) { 574 if (rv == base::PLATFORM_FILE_OK && !created) {
573 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); 575 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS);
574 } else { 576 } else {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } 737 }
736 738
737 bool FileSystemOperation::SetPendingOperationType(OperationType type) { 739 bool FileSystemOperation::SetPendingOperationType(OperationType type) {
738 if (pending_operation_ != kOperationNone) 740 if (pending_operation_ != kOperationNone)
739 return false; 741 return false;
740 pending_operation_ = type; 742 pending_operation_ = type;
741 return true; 743 return true;
742 } 744 }
743 745
744 } // namespace fileapi 746 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698