OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 : proxy_(proxy), | 64 : proxy_(proxy), |
65 dispatcher_(dispatcher), | 65 dispatcher_(dispatcher), |
66 operation_context_(file_system_context, NULL), | 66 operation_context_(file_system_context, NULL), |
67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
68 #ifndef NDEBUG | 68 #ifndef NDEBUG |
69 pending_operation_ = kOperationNone; | 69 pending_operation_ = kOperationNone; |
70 #endif | 70 #endif |
71 } | 71 } |
72 | 72 |
73 FileSystemOperation::~FileSystemOperation() { | 73 FileSystemOperation::~FileSystemOperation() { |
74 if (file_writer_delegate_.get()) { | 74 if (file_writer_delegate_.get()) |
75 FileSystemOperationContext* c = | 75 FileSystemFileUtilProxy::Close( |
76 new FileSystemOperationContext(operation_context_); | 76 operation_context_, proxy_, file_writer_delegate_->file(), |
77 base::FileUtilProxy::RelayClose( | |
78 proxy_, | |
79 base::Bind(&FileSystemFileUtil::Close, | |
80 base::Unretained(c->src_file_util()), | |
81 base::Owned(c)), | |
82 file_writer_delegate_->file(), | |
83 FileSystemFileUtilProxy::StatusCallback()); | 77 FileSystemFileUtilProxy::StatusCallback()); |
84 } | |
85 } | 78 } |
86 | 79 |
87 void FileSystemOperation::OpenFileSystem( | 80 void FileSystemOperation::OpenFileSystem( |
88 const GURL& origin_url, fileapi::FileSystemType type, bool create) { | 81 const GURL& origin_url, fileapi::FileSystemType type, bool create) { |
89 #ifndef NDEBUG | 82 #ifndef NDEBUG |
90 DCHECK(dispatcher_.get()); | 83 DCHECK(dispatcher_.get()); |
91 DCHECK(kOperationNone == pending_operation_); | 84 DCHECK(kOperationNone == pending_operation_); |
92 pending_operation_ = static_cast<FileSystemOperation::OperationType>( | 85 pending_operation_ = static_cast<FileSystemOperation::OperationType>( |
93 kOperationOpenFileSystem); | 86 kOperationOpenFileSystem); |
94 #endif | 87 #endif |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 359 |
367 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, | 360 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, |
368 int64 usage, int64 quota) { | 361 int64 usage, int64 quota) { |
369 operation_context_.set_allowed_bytes_growth(quota - usage); | 362 operation_context_.set_allowed_bytes_growth(quota - usage); |
370 | 363 |
371 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 364 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
372 file_system_context(), | 365 file_system_context(), |
373 operation_context_.src_origin_url(), | 366 operation_context_.src_origin_url(), |
374 operation_context_.src_type())); | 367 operation_context_.src_type())); |
375 | 368 |
376 int file_flags = base::PLATFORM_FILE_OPEN | | 369 FileSystemFileUtilProxy::CreateOrOpen( |
377 base::PLATFORM_FILE_WRITE | | 370 operation_context_, |
378 base::PLATFORM_FILE_ASYNC; | |
379 | |
380 base::FileUtilProxy::RelayCreateOrOpen( | |
381 proxy_, | 371 proxy_, |
382 base::Bind(&FileSystemFileUtil::CreateOrOpen, | 372 src_virtual_path_, |
383 base::Unretained(operation_context_.src_file_util()), | 373 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | |
384 base::Unretained(&operation_context_), | 374 base::PLATFORM_FILE_ASYNC, |
385 src_virtual_path_, file_flags), | |
386 base::Bind(&FileSystemFileUtil::Close, | |
387 base::Unretained(operation_context_.src_file_util()), | |
388 base::Unretained(&operation_context_)), | |
389 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, | 375 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, |
390 weak_factory_.GetWeakPtr())); | 376 weak_factory_.GetWeakPtr())); |
391 } | 377 } |
392 | 378 |
393 void FileSystemOperation::Truncate(const GURL& path, int64 length) { | 379 void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
394 #ifndef NDEBUG | 380 #ifndef NDEBUG |
395 DCHECK(dispatcher_.get()); | 381 DCHECK(dispatcher_.get()); |
396 DCHECK(kOperationNone == pending_operation_); | 382 DCHECK(kOperationNone == pending_operation_); |
397 pending_operation_ = kOperationTruncate; | 383 pending_operation_ = kOperationTruncate; |
398 #endif | 384 #endif |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 471 |
486 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, | 472 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, |
487 int64 usage, int64 quota) { | 473 int64 usage, int64 quota) { |
488 operation_context_.set_allowed_bytes_growth(quota - usage); | 474 operation_context_.set_allowed_bytes_growth(quota - usage); |
489 | 475 |
490 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 476 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
491 file_system_context(), | 477 file_system_context(), |
492 operation_context_.src_origin_url(), | 478 operation_context_.src_origin_url(), |
493 operation_context_.src_type())); | 479 operation_context_.src_type())); |
494 | 480 |
495 base::FileUtilProxy::RelayCreateOrOpen( | 481 FileSystemFileUtilProxy::CreateOrOpen( |
496 proxy_, | 482 operation_context_, proxy_, src_virtual_path_, file_flags_, |
497 base::Bind(&FileSystemFileUtil::CreateOrOpen, | |
498 base::Unretained(operation_context_.src_file_util()), | |
499 base::Unretained(&operation_context_), | |
500 src_virtual_path_, file_flags_), | |
501 base::Bind(&FileSystemFileUtil::Close, | |
502 base::Unretained(operation_context_.src_file_util()), | |
503 base::Unretained(&operation_context_)), | |
504 base::Bind(&FileSystemOperation::DidOpenFile, | 483 base::Bind(&FileSystemOperation::DidOpenFile, |
505 weak_factory_.GetWeakPtr())); | 484 weak_factory_.GetWeakPtr())); |
506 } | 485 } |
507 | 486 |
508 void FileSystemOperation::SyncGetPlatformPath(const GURL& path, | 487 void FileSystemOperation::SyncGetPlatformPath(const GURL& path, |
509 FilePath* platform_path) { | 488 FilePath* platform_path) { |
510 #ifndef NDEBUG | 489 #ifndef NDEBUG |
511 DCHECK(kOperationNone == pending_operation_); | 490 DCHECK(kOperationNone == pending_operation_); |
512 pending_operation_ = kOperationGetLocalPath; | 491 pending_operation_ = kOperationGetLocalPath; |
513 #endif | 492 #endif |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 bool result = VerifyFileSystemPathForWrite( | 841 bool result = VerifyFileSystemPathForWrite( |
863 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); | 842 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); |
864 operation_context_.set_dest_origin_url(origin_url); | 843 operation_context_.set_dest_origin_url(origin_url); |
865 operation_context_.set_dest_type(type); | 844 operation_context_.set_dest_type(type); |
866 if (!operation_context_.dest_file_util()) | 845 if (!operation_context_.dest_file_util()) |
867 operation_context_.set_dest_file_util(file_util); | 846 operation_context_.set_dest_file_util(file_util); |
868 return result; | 847 return result; |
869 } | 848 } |
870 | 849 |
871 } // namespace fileapi | 850 } // namespace fileapi |
OLD | NEW |