| 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/time.h" | 8 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 9 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
| 10 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
| 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 12 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 12 #include "webkit/fileapi/file_system_context.h" | 13 #include "webkit/fileapi/file_system_context.h" |
| 13 #include "webkit/fileapi/file_system_file_util_proxy.h" | 14 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 14 #include "webkit/fileapi/file_system_operation_context.h" | 15 #include "webkit/fileapi/file_system_operation_context.h" |
| 15 #include "webkit/fileapi/file_system_path_manager.h" | 16 #include "webkit/fileapi/file_system_path_manager.h" |
| 16 #include "webkit/fileapi/file_system_quota_util.h" | 17 #include "webkit/fileapi/file_system_quota_util.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } | 58 } |
| 58 | 59 |
| 59 FileSystemOperation::FileSystemOperation( | 60 FileSystemOperation::FileSystemOperation( |
| 60 FileSystemCallbackDispatcher* dispatcher, | 61 FileSystemCallbackDispatcher* dispatcher, |
| 61 scoped_refptr<base::MessageLoopProxy> proxy, | 62 scoped_refptr<base::MessageLoopProxy> proxy, |
| 62 FileSystemContext* file_system_context, | 63 FileSystemContext* file_system_context, |
| 63 FileSystemFileUtil* file_util) | 64 FileSystemFileUtil* file_util) |
| 64 : proxy_(proxy), | 65 : proxy_(proxy), |
| 65 dispatcher_(dispatcher), | 66 dispatcher_(dispatcher), |
| 66 file_system_operation_context_(file_system_context, file_util), | 67 file_system_operation_context_(file_system_context, file_util), |
| 67 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 68 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), |
| 69 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 68 DCHECK(dispatcher); | 70 DCHECK(dispatcher); |
| 69 #ifndef NDEBUG | 71 #ifndef NDEBUG |
| 70 pending_operation_ = kOperationNone; | 72 pending_operation_ = kOperationNone; |
| 71 #endif | 73 #endif |
| 72 } | 74 } |
| 73 | 75 |
| 74 FileSystemOperation::~FileSystemOperation() { | 76 FileSystemOperation::~FileSystemOperation() { |
| 75 if (file_writer_delegate_.get()) | 77 if (file_writer_delegate_.get()) |
| 76 FileSystemFileUtilProxy::Close( | 78 FileSystemFileUtilProxy::Close( |
| 77 file_system_operation_context_, | 79 file_system_operation_context_, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 174 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
| 173 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 175 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 174 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 176 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 175 | 177 |
| 176 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 178 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 177 file_system_context(), | 179 file_system_context(), |
| 178 file_system_operation_context_.src_origin_url(), | 180 file_system_operation_context_.src_origin_url(), |
| 179 file_system_operation_context_.src_type())); | 181 file_system_operation_context_.src_type())); |
| 180 | 182 |
| 181 FileSystemFileUtilProxy::CreateDirectory( | 183 FileSystemFileUtilProxy::CreateDirectory( |
| 182 file_system_operation_context_, | 184 file_system_operation_context_, proxy_, src_virtual_path_, exclusive_, |
| 183 proxy_, | |
| 184 src_virtual_path_, | |
| 185 exclusive_, | |
| 186 recursive_, | 185 recursive_, |
| 187 callback_factory_.NewCallback( | 186 callback_factory_.NewCallback( |
| 188 &FileSystemOperation::DidFinishFileOperation)); | 187 &FileSystemOperation::DidFinishFileOperation)); |
| 189 } | 188 } |
| 190 | 189 |
| 191 void FileSystemOperation::Copy(const GURL& src_path, | 190 void FileSystemOperation::Copy(const GURL& src_path, |
| 192 const GURL& dest_path) { | 191 const GURL& dest_path) { |
| 193 #ifndef NDEBUG | 192 #ifndef NDEBUG |
| 194 DCHECK(kOperationNone == pending_operation_); | 193 DCHECK(kOperationNone == pending_operation_); |
| 195 pending_operation_ = kOperationCopy; | 194 pending_operation_ = kOperationCopy; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 file_system_context(), | 453 file_system_context(), |
| 455 file_system_operation_context_.src_origin_url(), | 454 file_system_operation_context_.src_origin_url(), |
| 456 file_system_operation_context_.src_type())); | 455 file_system_operation_context_.src_type())); |
| 457 | 456 |
| 458 FileSystemFileUtilProxy::CreateOrOpen( | 457 FileSystemFileUtilProxy::CreateOrOpen( |
| 459 file_system_operation_context_, | 458 file_system_operation_context_, |
| 460 proxy_, | 459 proxy_, |
| 461 src_virtual_path_, | 460 src_virtual_path_, |
| 462 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | | 461 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | |
| 463 base::PLATFORM_FILE_ASYNC, | 462 base::PLATFORM_FILE_ASYNC, |
| 464 callback_factory_.NewCallback( | 463 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, |
| 465 &FileSystemOperation::OnFileOpenedForWrite)); | 464 weak_factory_.GetWeakPtr())); |
| 466 } | 465 } |
| 467 | 466 |
| 468 void FileSystemOperation::Truncate(const GURL& path, int64 length) { | 467 void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
| 469 #ifndef NDEBUG | 468 #ifndef NDEBUG |
| 470 DCHECK(kOperationNone == pending_operation_); | 469 DCHECK(kOperationNone == pending_operation_); |
| 471 pending_operation_ = kOperationTruncate; | 470 pending_operation_ = kOperationTruncate; |
| 472 #endif | 471 #endif |
| 473 GURL origin_url; | 472 GURL origin_url; |
| 474 FileSystemType type; | 473 FileSystemType type; |
| 475 FileSystemFileUtil* file_util; | 474 FileSystemFileUtil* file_util; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, | 580 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, |
| 582 int64 usage, int64 quota) { | 581 int64 usage, int64 quota) { |
| 583 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 582 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 584 | 583 |
| 585 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 584 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 586 file_system_context(), | 585 file_system_context(), |
| 587 file_system_operation_context_.src_origin_url(), | 586 file_system_operation_context_.src_origin_url(), |
| 588 file_system_operation_context_.src_type())); | 587 file_system_operation_context_.src_type())); |
| 589 | 588 |
| 590 FileSystemFileUtilProxy::CreateOrOpen( | 589 FileSystemFileUtilProxy::CreateOrOpen( |
| 591 file_system_operation_context_, | 590 file_system_operation_context_, proxy_, src_virtual_path_, file_flags_, |
| 592 proxy_, | 591 base::Bind(&FileSystemOperation::DidOpenFile, |
| 593 src_virtual_path_, | 592 weak_factory_.GetWeakPtr())); |
| 594 file_flags_, | |
| 595 callback_factory_.NewCallback( | |
| 596 &FileSystemOperation::DidOpenFile)); | |
| 597 } | 593 } |
| 598 | 594 |
| 599 // We can only get here on a write or truncate that's not yet completed. | 595 // We can only get here on a write or truncate that's not yet completed. |
| 600 // We don't support cancelling any other operation at this time. | 596 // We don't support cancelling any other operation at this time. |
| 601 void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) { | 597 void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) { |
| 602 scoped_ptr<FileSystemOperation> cancel_operation(cancel_operation_ptr); | 598 scoped_ptr<FileSystemOperation> cancel_operation(cancel_operation_ptr); |
| 603 if (file_writer_delegate_.get()) { | 599 if (file_writer_delegate_.get()) { |
| 604 #ifndef NDEBUG | 600 #ifndef NDEBUG |
| 605 DCHECK(kOperationWrite == pending_operation_); | 601 DCHECK(kOperationWrite == pending_operation_); |
| 606 #endif | 602 #endif |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 return false; | 892 return false; |
| 897 } | 893 } |
| 898 DCHECK(file_util); | 894 DCHECK(file_util); |
| 899 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); | 895 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); |
| 900 DCHECK(*file_util); | 896 DCHECK(*file_util); |
| 901 | 897 |
| 902 return true; | 898 return true; |
| 903 } | 899 } |
| 904 | 900 |
| 905 } // namespace fileapi | 901 } // namespace fileapi |
| OLD | NEW |