Chromium Code Reviews| 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/time.h" | 7 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "net/base/escape.h" | 9 #include "net/base/escape.h" |
| 10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
| 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 12 #include "webkit/fileapi/file_system_context.h" | 12 #include "webkit/fileapi/file_system_context.h" |
| 13 #include "webkit/fileapi/file_system_file_util_proxy.h" | 13 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 14 #include "webkit/fileapi/file_system_operation_context.h" | 14 #include "webkit/fileapi/file_system_operation_context.h" |
| 15 #include "webkit/fileapi/file_system_path_manager.h" | 15 #include "webkit/fileapi/file_system_path_manager.h" |
| 16 #include "webkit/fileapi/file_system_quota_util.h" | 16 #include "webkit/fileapi/file_system_quota_util.h" |
| 17 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
| 18 #include "webkit/fileapi/file_system_util.h" | 18 #include "webkit/fileapi/file_system_util.h" |
| 19 #include "webkit/fileapi/file_writer_delegate.h" | 19 #include "webkit/fileapi/file_writer_delegate.h" |
| 20 #include "webkit/fileapi/local_file_system_file_util.h" | 20 #include "webkit/fileapi/local_file_system_file_util.h" |
| 21 #include "webkit/fileapi/quota_file_util.h" | 21 #include "webkit/fileapi/quota_file_util.h" |
| 22 #include "webkit/quota/quota_types.h" | 22 #include "webkit/quota/quota_types.h" |
| 23 | 23 |
| 24 namespace fileapi { | 24 namespace fileapi { |
| 25 | 25 |
| 26 class FileSystemOperation::ScopedQuotaUtilHelper { | |
| 27 public: | |
| 28 ScopedQuotaUtilHelper(FileSystemContext* context, | |
| 29 const GURL& origin_url, | |
| 30 FileSystemType type); | |
| 31 ~ScopedQuotaUtilHelper(); | |
| 32 | |
| 33 private: | |
| 34 FileSystemQuotaUtil* quota_util_; | |
| 35 const GURL& origin_url_; | |
| 36 FileSystemType type_; | |
| 37 DISALLOW_COPY_AND_ASSIGN(ScopedQuotaUtilHelper); | |
| 38 }; | |
| 39 | |
| 40 FileSystemOperation::ScopedQuotaUtilHelper::ScopedQuotaUtilHelper( | |
| 41 FileSystemContext* context, const GURL& origin_url, FileSystemType type) | |
| 42 : origin_url_(origin_url), type_(type) { | |
| 43 DCHECK(context); | |
| 44 DCHECK(type != kFileSystemTypeUnknown); | |
|
ericu
2011/08/30 17:50:29
It would be safer to check that it's one of the kn
Dai Mikurube (NOT FULLTIME)
2011/08/31 07:12:02
Thanks. I guess we want some other opinion on thi
kinuko
2011/08/31 07:25:34
Basically if it's one of the types that doesn't su
| |
| 45 quota_util_ = context->GetQuotaUtil(type_); | |
| 46 if (quota_util_) { | |
| 47 DCHECK(quota_util_->proxy()); | |
| 48 quota_util_->proxy()->StartUpdateOrigin(origin_url_, type_); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 FileSystemOperation::ScopedQuotaUtilHelper::~ScopedQuotaUtilHelper() { | |
| 53 if (quota_util_) { | |
| 54 DCHECK(quota_util_->proxy()); | |
| 55 quota_util_->proxy()->EndUpdateOrigin(origin_url_, type_); | |
| 56 } | |
| 57 } | |
| 58 | |
| 26 FileSystemOperation::FileSystemOperation( | 59 FileSystemOperation::FileSystemOperation( |
| 27 FileSystemCallbackDispatcher* dispatcher, | 60 FileSystemCallbackDispatcher* dispatcher, |
| 28 scoped_refptr<base::MessageLoopProxy> proxy, | 61 scoped_refptr<base::MessageLoopProxy> proxy, |
| 29 FileSystemContext* file_system_context, | 62 FileSystemContext* file_system_context, |
| 30 FileSystemFileUtil* file_system_file_util) | 63 FileSystemFileUtil* file_system_file_util) |
| 31 : proxy_(proxy), | 64 : proxy_(proxy), |
| 32 dispatcher_(dispatcher), | 65 dispatcher_(dispatcher), |
| 33 file_system_operation_context_( | 66 file_system_operation_context_( |
| 34 file_system_context, file_system_file_util), | 67 file_system_context, file_system_file_util), |
| 35 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 68 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 void FileSystemOperation::DelayedCreateFileForQuota( | 130 void FileSystemOperation::DelayedCreateFileForQuota( |
| 98 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 131 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 99 if (file_system_context()->IsStorageUnlimited( | 132 if (file_system_context()->IsStorageUnlimited( |
| 100 file_system_operation_context()->src_origin_url()) || | 133 file_system_operation_context()->src_origin_url()) || |
| 101 quota == QuotaFileUtil::kNoLimit) { | 134 quota == QuotaFileUtil::kNoLimit) { |
| 102 file_system_operation_context_.set_allowed_bytes_growth( | 135 file_system_operation_context_.set_allowed_bytes_growth( |
| 103 QuotaFileUtil::kNoLimit); | 136 QuotaFileUtil::kNoLimit); |
| 104 } else { | 137 } else { |
| 105 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 138 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 106 } | 139 } |
| 140 | |
| 141 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
| 142 file_system_context(), | |
| 143 file_system_operation_context_.src_origin_url(), | |
| 144 file_system_operation_context_.src_type())); | |
| 145 | |
| 107 FileSystemFileUtilProxy::EnsureFileExists( | 146 FileSystemFileUtilProxy::EnsureFileExists( |
| 108 file_system_operation_context_, | 147 file_system_operation_context_, |
| 109 proxy_, | 148 proxy_, |
| 110 src_virtual_path_, | 149 src_virtual_path_, |
| 111 callback_factory_.NewCallback( | 150 callback_factory_.NewCallback( |
| 112 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive | 151 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive |
| 113 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); | 152 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); |
| 114 } | 153 } |
| 115 | 154 |
| 116 void FileSystemOperation::CreateDirectory(const GURL& path, | 155 void FileSystemOperation::CreateDirectory(const GURL& path, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 145 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 184 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
| 146 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 185 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 147 if (file_system_context()->IsStorageUnlimited( | 186 if (file_system_context()->IsStorageUnlimited( |
| 148 file_system_operation_context()->src_origin_url()) || | 187 file_system_operation_context()->src_origin_url()) || |
| 149 quota == QuotaFileUtil::kNoLimit) { | 188 quota == QuotaFileUtil::kNoLimit) { |
| 150 file_system_operation_context_.set_allowed_bytes_growth( | 189 file_system_operation_context_.set_allowed_bytes_growth( |
| 151 QuotaFileUtil::kNoLimit); | 190 QuotaFileUtil::kNoLimit); |
| 152 } else { | 191 } else { |
| 153 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 192 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 154 } | 193 } |
| 194 | |
| 195 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
| 196 file_system_context(), | |
| 197 file_system_operation_context_.src_origin_url(), | |
| 198 file_system_operation_context_.src_type())); | |
| 199 | |
| 155 FileSystemFileUtilProxy::CreateDirectory( | 200 FileSystemFileUtilProxy::CreateDirectory( |
| 156 file_system_operation_context_, | 201 file_system_operation_context_, |
| 157 proxy_, | 202 proxy_, |
| 158 src_virtual_path_, | 203 src_virtual_path_, |
| 159 exclusive_, | 204 exclusive_, |
| 160 recursive_, | 205 recursive_, |
| 161 callback_factory_.NewCallback( | 206 callback_factory_.NewCallback( |
| 162 &FileSystemOperation::DidFinishFileOperation)); | 207 &FileSystemOperation::DidFinishFileOperation)); |
| 163 } | 208 } |
| 164 | 209 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 246 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
| 202 int64 usage, int64 quota) { | 247 int64 usage, int64 quota) { |
| 203 if (file_system_context()->IsStorageUnlimited( | 248 if (file_system_context()->IsStorageUnlimited( |
| 204 file_system_operation_context()->dest_origin_url()) || | 249 file_system_operation_context()->dest_origin_url()) || |
| 205 quota == QuotaFileUtil::kNoLimit) { | 250 quota == QuotaFileUtil::kNoLimit) { |
| 206 file_system_operation_context_.set_allowed_bytes_growth( | 251 file_system_operation_context_.set_allowed_bytes_growth( |
| 207 QuotaFileUtil::kNoLimit); | 252 QuotaFileUtil::kNoLimit); |
| 208 } else { | 253 } else { |
| 209 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 254 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 210 } | 255 } |
| 256 | |
| 257 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
| 258 file_system_context(), | |
| 259 file_system_operation_context_.dest_origin_url(), | |
| 260 file_system_operation_context_.dest_type())); | |
| 261 | |
| 211 FileSystemFileUtilProxy::Copy( | 262 FileSystemFileUtilProxy::Copy( |
| 212 file_system_operation_context_, | 263 file_system_operation_context_, |
| 213 proxy_, | 264 proxy_, |
| 214 src_virtual_path_, | 265 src_virtual_path_, |
| 215 dest_virtual_path_, | 266 dest_virtual_path_, |
| 216 callback_factory_.NewCallback( | 267 callback_factory_.NewCallback( |
| 217 &FileSystemOperation::DidFinishFileOperation)); | 268 &FileSystemOperation::DidFinishFileOperation)); |
| 218 } | 269 } |
| 219 | 270 |
| 220 void FileSystemOperation::Move(const GURL& src_path, | 271 void FileSystemOperation::Move(const GURL& src_path, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, | 307 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
| 257 int64 usage, int64 quota) { | 308 int64 usage, int64 quota) { |
| 258 if (file_system_context()->IsStorageUnlimited( | 309 if (file_system_context()->IsStorageUnlimited( |
| 259 file_system_operation_context()->dest_origin_url()) || | 310 file_system_operation_context()->dest_origin_url()) || |
| 260 quota == QuotaFileUtil::kNoLimit) { | 311 quota == QuotaFileUtil::kNoLimit) { |
| 261 file_system_operation_context_.set_allowed_bytes_growth( | 312 file_system_operation_context_.set_allowed_bytes_growth( |
| 262 QuotaFileUtil::kNoLimit); | 313 QuotaFileUtil::kNoLimit); |
| 263 } else { | 314 } else { |
| 264 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 315 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 265 } | 316 } |
| 317 | |
| 318 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
| 319 file_system_context(), | |
| 320 file_system_operation_context_.dest_origin_url(), | |
| 321 file_system_operation_context_.dest_type())); | |
| 322 | |
| 266 FileSystemFileUtilProxy::Move( | 323 FileSystemFileUtilProxy::Move( |
| 267 file_system_operation_context_, | 324 file_system_operation_context_, |
| 268 proxy_, | 325 proxy_, |
| 269 src_virtual_path_, | 326 src_virtual_path_, |
| 270 dest_virtual_path_, | 327 dest_virtual_path_, |
| 271 callback_factory_.NewCallback( | 328 callback_factory_.NewCallback( |
| 272 &FileSystemOperation::DidFinishFileOperation)); | 329 &FileSystemOperation::DidFinishFileOperation)); |
| 273 } | 330 } |
| 274 | 331 |
| 275 void FileSystemOperation::DirectoryExists(const GURL& path) { | 332 void FileSystemOperation::DirectoryExists(const GURL& path) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, | 494 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, |
| 438 int64 usage, int64 quota) { | 495 int64 usage, int64 quota) { |
| 439 if (file_system_context()->IsStorageUnlimited( | 496 if (file_system_context()->IsStorageUnlimited( |
| 440 file_system_operation_context()->src_origin_url()) || | 497 file_system_operation_context()->src_origin_url()) || |
| 441 quota == QuotaFileUtil::kNoLimit) { | 498 quota == QuotaFileUtil::kNoLimit) { |
| 442 file_system_operation_context_.set_allowed_bytes_growth( | 499 file_system_operation_context_.set_allowed_bytes_growth( |
| 443 QuotaFileUtil::kNoLimit); | 500 QuotaFileUtil::kNoLimit); |
| 444 } else { | 501 } else { |
| 445 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 502 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 446 } | 503 } |
| 504 | |
| 505 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
| 506 file_system_context(), | |
| 507 file_system_operation_context_.src_origin_url(), | |
| 508 file_system_operation_context_.src_type())); | |
| 509 | |
| 447 FileSystemFileUtilProxy::CreateOrOpen( | 510 FileSystemFileUtilProxy::CreateOrOpen( |
| 448 file_system_operation_context_, | 511 file_system_operation_context_, |
| 449 proxy_, | 512 proxy_, |
| 450 src_virtual_path_, | 513 src_virtual_path_, |
| 451 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | | 514 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | |
| 452 base::PLATFORM_FILE_ASYNC, | 515 base::PLATFORM_FILE_ASYNC, |
| 453 callback_factory_.NewCallback( | 516 callback_factory_.NewCallback( |
| 454 &FileSystemOperation::OnFileOpenedForWrite)); | 517 &FileSystemOperation::OnFileOpenedForWrite)); |
| 455 } | 518 } |
| 456 | 519 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 481 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, | 544 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, |
| 482 int64 usage, int64 quota) { | 545 int64 usage, int64 quota) { |
| 483 if (file_system_context()->IsStorageUnlimited( | 546 if (file_system_context()->IsStorageUnlimited( |
| 484 file_system_operation_context()->src_origin_url()) || | 547 file_system_operation_context()->src_origin_url()) || |
| 485 quota == QuotaFileUtil::kNoLimit) { | 548 quota == QuotaFileUtil::kNoLimit) { |
| 486 file_system_operation_context_.set_allowed_bytes_growth( | 549 file_system_operation_context_.set_allowed_bytes_growth( |
| 487 QuotaFileUtil::kNoLimit); | 550 QuotaFileUtil::kNoLimit); |
| 488 } else { | 551 } else { |
| 489 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 552 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 490 } | 553 } |
| 554 | |
| 555 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
| 556 file_system_context(), | |
| 557 file_system_operation_context_.src_origin_url(), | |
| 558 file_system_operation_context_.src_type())); | |
| 559 | |
| 491 FileSystemFileUtilProxy::Truncate( | 560 FileSystemFileUtilProxy::Truncate( |
| 492 file_system_operation_context_, | 561 file_system_operation_context_, |
| 493 proxy_, | 562 proxy_, |
| 494 src_virtual_path_, | 563 src_virtual_path_, |
| 495 length_, callback_factory_.NewCallback( | 564 length_, callback_factory_.NewCallback( |
| 496 &FileSystemOperation::DidFinishFileOperation)); | 565 &FileSystemOperation::DidFinishFileOperation)); |
| 497 } | 566 } |
| 498 | 567 |
| 499 void FileSystemOperation::TouchFile(const GURL& path, | 568 void FileSystemOperation::TouchFile(const GURL& path, |
| 500 const base::Time& last_access_time, | 569 const base::Time& last_access_time, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 int64 usage, int64 quota) { | 644 int64 usage, int64 quota) { |
| 576 if (file_system_context()->IsStorageUnlimited( | 645 if (file_system_context()->IsStorageUnlimited( |
| 577 file_system_operation_context()->dest_origin_url()) || | 646 file_system_operation_context()->dest_origin_url()) || |
| 578 quota == QuotaFileUtil::kNoLimit) { | 647 quota == QuotaFileUtil::kNoLimit) { |
| 579 file_system_operation_context_.set_allowed_bytes_growth( | 648 file_system_operation_context_.set_allowed_bytes_growth( |
| 580 QuotaFileUtil::kNoLimit); | 649 QuotaFileUtil::kNoLimit); |
| 581 } else { | 650 } else { |
| 582 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 651 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 583 } | 652 } |
| 584 | 653 |
| 654 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | |
| 655 file_system_context(), | |
| 656 file_system_operation_context_.src_origin_url(), | |
| 657 file_system_operation_context_.src_type())); | |
| 658 | |
| 585 FileSystemFileUtilProxy::CreateOrOpen( | 659 FileSystemFileUtilProxy::CreateOrOpen( |
| 586 file_system_operation_context_, | 660 file_system_operation_context_, |
| 587 proxy_, | 661 proxy_, |
| 588 src_virtual_path_, | 662 src_virtual_path_, |
| 589 file_flags_, | 663 file_flags_, |
| 590 callback_factory_.NewCallback( | 664 callback_factory_.NewCallback( |
| 591 &FileSystemOperation::DidOpenFile)); | 665 &FileSystemOperation::DidOpenFile)); |
| 592 } | 666 } |
| 593 | 667 |
| 594 // We can only get here on a write or truncate that's not yet completed. | 668 // We can only get here on a write or truncate that's not yet completed. |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 } | 969 } |
| 896 DCHECK(file_system_file_util); | 970 DCHECK(file_system_file_util); |
| 897 *file_system_file_util = | 971 *file_system_file_util = |
| 898 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); | 972 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); |
| 899 DCHECK(*file_system_file_util); | 973 DCHECK(*file_system_file_util); |
| 900 | 974 |
| 901 return true; | 975 return true; |
| 902 } | 976 } |
| 903 | 977 |
| 904 } // namespace fileapi | 978 } // namespace fileapi |
| OLD | NEW |