| 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 FileSystemOperation::ScopedQuotaUtilHelper::ScopedQuotaUtilHelper( |
| 27 FileSystemContext* context, const GURL& origin_url, FileSystemType type) |
| 28 : origin_url_(origin_url), type_(type) { |
| 29 DCHECK(context); |
| 30 DCHECK(type != kFileSystemTypeUnknown); |
| 31 quota_util_ = context->GetQuotaUtil(type_); |
| 32 if (quota_util_) { |
| 33 DCHECK(quota_util_->proxy()); |
| 34 quota_util_->proxy()->StartUpdateOrigin(origin_url_, type_); |
| 35 } |
| 36 } |
| 37 |
| 38 FileSystemOperation::ScopedQuotaUtilHelper::~ScopedQuotaUtilHelper() { |
| 39 if (quota_util_) { |
| 40 DCHECK(quota_util_->proxy()); |
| 41 quota_util_->proxy()->EndUpdateOrigin(origin_url_, type_); |
| 42 } |
| 43 } |
| 44 |
| 26 FileSystemOperation::FileSystemOperation( | 45 FileSystemOperation::FileSystemOperation( |
| 27 FileSystemCallbackDispatcher* dispatcher, | 46 FileSystemCallbackDispatcher* dispatcher, |
| 28 scoped_refptr<base::MessageLoopProxy> proxy, | 47 scoped_refptr<base::MessageLoopProxy> proxy, |
| 29 FileSystemContext* file_system_context, | 48 FileSystemContext* file_system_context, |
| 30 FileSystemFileUtil* file_system_file_util) | 49 FileSystemFileUtil* file_system_file_util) |
| 31 : proxy_(proxy), | 50 : proxy_(proxy), |
| 32 dispatcher_(dispatcher), | 51 dispatcher_(dispatcher), |
| 33 file_system_operation_context_( | 52 file_system_operation_context_( |
| 34 file_system_context, file_system_file_util), | 53 file_system_context, file_system_file_util), |
| 35 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 54 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( | 116 void FileSystemOperation::DelayedCreateFileForQuota( |
| 98 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 117 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 99 if (file_system_context()->IsStorageUnlimited( | 118 if (file_system_context()->IsStorageUnlimited( |
| 100 file_system_operation_context()->src_origin_url()) || | 119 file_system_operation_context()->src_origin_url()) || |
| 101 quota == QuotaFileUtil::kNoLimit) { | 120 quota == QuotaFileUtil::kNoLimit) { |
| 102 file_system_operation_context_.set_allowed_bytes_growth( | 121 file_system_operation_context_.set_allowed_bytes_growth( |
| 103 QuotaFileUtil::kNoLimit); | 122 QuotaFileUtil::kNoLimit); |
| 104 } else { | 123 } else { |
| 105 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 124 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 106 } | 125 } |
| 126 |
| 127 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 128 file_system_context(), |
| 129 file_system_operation_context_.src_origin_url(), |
| 130 file_system_operation_context_.src_type())); |
| 131 |
| 107 FileSystemFileUtilProxy::EnsureFileExists( | 132 FileSystemFileUtilProxy::EnsureFileExists( |
| 108 file_system_operation_context_, | 133 file_system_operation_context_, |
| 109 proxy_, | 134 proxy_, |
| 110 src_virtual_path_, | 135 src_virtual_path_, |
| 111 callback_factory_.NewCallback( | 136 callback_factory_.NewCallback( |
| 112 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive | 137 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive |
| 113 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); | 138 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); |
| 114 } | 139 } |
| 115 | 140 |
| 116 void FileSystemOperation::CreateDirectory(const GURL& path, | 141 void FileSystemOperation::CreateDirectory(const GURL& path, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 145 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 170 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
| 146 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 171 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 147 if (file_system_context()->IsStorageUnlimited( | 172 if (file_system_context()->IsStorageUnlimited( |
| 148 file_system_operation_context()->src_origin_url()) || | 173 file_system_operation_context()->src_origin_url()) || |
| 149 quota == QuotaFileUtil::kNoLimit) { | 174 quota == QuotaFileUtil::kNoLimit) { |
| 150 file_system_operation_context_.set_allowed_bytes_growth( | 175 file_system_operation_context_.set_allowed_bytes_growth( |
| 151 QuotaFileUtil::kNoLimit); | 176 QuotaFileUtil::kNoLimit); |
| 152 } else { | 177 } else { |
| 153 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 178 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 154 } | 179 } |
| 180 |
| 181 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 182 file_system_context(), |
| 183 file_system_operation_context_.src_origin_url(), |
| 184 file_system_operation_context_.src_type())); |
| 185 |
| 155 FileSystemFileUtilProxy::CreateDirectory( | 186 FileSystemFileUtilProxy::CreateDirectory( |
| 156 file_system_operation_context_, | 187 file_system_operation_context_, |
| 157 proxy_, | 188 proxy_, |
| 158 src_virtual_path_, | 189 src_virtual_path_, |
| 159 exclusive_, | 190 exclusive_, |
| 160 recursive_, | 191 recursive_, |
| 161 callback_factory_.NewCallback( | 192 callback_factory_.NewCallback( |
| 162 &FileSystemOperation::DidFinishFileOperation)); | 193 &FileSystemOperation::DidFinishFileOperation)); |
| 163 } | 194 } |
| 164 | 195 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 232 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
| 202 int64 usage, int64 quota) { | 233 int64 usage, int64 quota) { |
| 203 if (file_system_context()->IsStorageUnlimited( | 234 if (file_system_context()->IsStorageUnlimited( |
| 204 file_system_operation_context()->dest_origin_url()) || | 235 file_system_operation_context()->dest_origin_url()) || |
| 205 quota == QuotaFileUtil::kNoLimit) { | 236 quota == QuotaFileUtil::kNoLimit) { |
| 206 file_system_operation_context_.set_allowed_bytes_growth( | 237 file_system_operation_context_.set_allowed_bytes_growth( |
| 207 QuotaFileUtil::kNoLimit); | 238 QuotaFileUtil::kNoLimit); |
| 208 } else { | 239 } else { |
| 209 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 240 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 210 } | 241 } |
| 242 |
| 243 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 244 file_system_context(), |
| 245 file_system_operation_context_.dest_origin_url(), |
| 246 file_system_operation_context_.dest_type())); |
| 247 |
| 211 FileSystemFileUtilProxy::Copy( | 248 FileSystemFileUtilProxy::Copy( |
| 212 file_system_operation_context_, | 249 file_system_operation_context_, |
| 213 proxy_, | 250 proxy_, |
| 214 src_virtual_path_, | 251 src_virtual_path_, |
| 215 dest_virtual_path_, | 252 dest_virtual_path_, |
| 216 callback_factory_.NewCallback( | 253 callback_factory_.NewCallback( |
| 217 &FileSystemOperation::DidFinishFileOperation)); | 254 &FileSystemOperation::DidFinishFileOperation)); |
| 218 } | 255 } |
| 219 | 256 |
| 220 void FileSystemOperation::Move(const GURL& src_path, | 257 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, | 293 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
| 257 int64 usage, int64 quota) { | 294 int64 usage, int64 quota) { |
| 258 if (file_system_context()->IsStorageUnlimited( | 295 if (file_system_context()->IsStorageUnlimited( |
| 259 file_system_operation_context()->dest_origin_url()) || | 296 file_system_operation_context()->dest_origin_url()) || |
| 260 quota == QuotaFileUtil::kNoLimit) { | 297 quota == QuotaFileUtil::kNoLimit) { |
| 261 file_system_operation_context_.set_allowed_bytes_growth( | 298 file_system_operation_context_.set_allowed_bytes_growth( |
| 262 QuotaFileUtil::kNoLimit); | 299 QuotaFileUtil::kNoLimit); |
| 263 } else { | 300 } else { |
| 264 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 301 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 265 } | 302 } |
| 303 |
| 304 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 305 file_system_context(), |
| 306 file_system_operation_context_.dest_origin_url(), |
| 307 file_system_operation_context_.dest_type())); |
| 308 |
| 266 FileSystemFileUtilProxy::Move( | 309 FileSystemFileUtilProxy::Move( |
| 267 file_system_operation_context_, | 310 file_system_operation_context_, |
| 268 proxy_, | 311 proxy_, |
| 269 src_virtual_path_, | 312 src_virtual_path_, |
| 270 dest_virtual_path_, | 313 dest_virtual_path_, |
| 271 callback_factory_.NewCallback( | 314 callback_factory_.NewCallback( |
| 272 &FileSystemOperation::DidFinishFileOperation)); | 315 &FileSystemOperation::DidFinishFileOperation)); |
| 273 } | 316 } |
| 274 | 317 |
| 275 void FileSystemOperation::DirectoryExists(const GURL& path) { | 318 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, | 480 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, |
| 438 int64 usage, int64 quota) { | 481 int64 usage, int64 quota) { |
| 439 if (file_system_context()->IsStorageUnlimited( | 482 if (file_system_context()->IsStorageUnlimited( |
| 440 file_system_operation_context()->src_origin_url()) || | 483 file_system_operation_context()->src_origin_url()) || |
| 441 quota == QuotaFileUtil::kNoLimit) { | 484 quota == QuotaFileUtil::kNoLimit) { |
| 442 file_system_operation_context_.set_allowed_bytes_growth( | 485 file_system_operation_context_.set_allowed_bytes_growth( |
| 443 QuotaFileUtil::kNoLimit); | 486 QuotaFileUtil::kNoLimit); |
| 444 } else { | 487 } else { |
| 445 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 488 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 446 } | 489 } |
| 490 |
| 491 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 492 file_system_context(), |
| 493 file_system_operation_context_.src_origin_url(), |
| 494 file_system_operation_context_.src_type())); |
| 495 |
| 447 FileSystemFileUtilProxy::CreateOrOpen( | 496 FileSystemFileUtilProxy::CreateOrOpen( |
| 448 file_system_operation_context_, | 497 file_system_operation_context_, |
| 449 proxy_, | 498 proxy_, |
| 450 src_virtual_path_, | 499 src_virtual_path_, |
| 451 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | | 500 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | |
| 452 base::PLATFORM_FILE_ASYNC, | 501 base::PLATFORM_FILE_ASYNC, |
| 453 callback_factory_.NewCallback( | 502 callback_factory_.NewCallback( |
| 454 &FileSystemOperation::OnFileOpenedForWrite)); | 503 &FileSystemOperation::OnFileOpenedForWrite)); |
| 455 } | 504 } |
| 456 | 505 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 481 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, | 530 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, |
| 482 int64 usage, int64 quota) { | 531 int64 usage, int64 quota) { |
| 483 if (file_system_context()->IsStorageUnlimited( | 532 if (file_system_context()->IsStorageUnlimited( |
| 484 file_system_operation_context()->src_origin_url()) || | 533 file_system_operation_context()->src_origin_url()) || |
| 485 quota == QuotaFileUtil::kNoLimit) { | 534 quota == QuotaFileUtil::kNoLimit) { |
| 486 file_system_operation_context_.set_allowed_bytes_growth( | 535 file_system_operation_context_.set_allowed_bytes_growth( |
| 487 QuotaFileUtil::kNoLimit); | 536 QuotaFileUtil::kNoLimit); |
| 488 } else { | 537 } else { |
| 489 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 538 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 490 } | 539 } |
| 540 |
| 541 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 542 file_system_context(), |
| 543 file_system_operation_context_.src_origin_url(), |
| 544 file_system_operation_context_.src_type())); |
| 545 |
| 491 FileSystemFileUtilProxy::Truncate( | 546 FileSystemFileUtilProxy::Truncate( |
| 492 file_system_operation_context_, | 547 file_system_operation_context_, |
| 493 proxy_, | 548 proxy_, |
| 494 src_virtual_path_, | 549 src_virtual_path_, |
| 495 length_, callback_factory_.NewCallback( | 550 length_, callback_factory_.NewCallback( |
| 496 &FileSystemOperation::DidFinishFileOperation)); | 551 &FileSystemOperation::DidFinishFileOperation)); |
| 497 } | 552 } |
| 498 | 553 |
| 499 void FileSystemOperation::TouchFile(const GURL& path, | 554 void FileSystemOperation::TouchFile(const GURL& path, |
| 500 const base::Time& last_access_time, | 555 const base::Time& last_access_time, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 int64 usage, int64 quota) { | 630 int64 usage, int64 quota) { |
| 576 if (file_system_context()->IsStorageUnlimited( | 631 if (file_system_context()->IsStorageUnlimited( |
| 577 file_system_operation_context()->dest_origin_url()) || | 632 file_system_operation_context()->dest_origin_url()) || |
| 578 quota == QuotaFileUtil::kNoLimit) { | 633 quota == QuotaFileUtil::kNoLimit) { |
| 579 file_system_operation_context_.set_allowed_bytes_growth( | 634 file_system_operation_context_.set_allowed_bytes_growth( |
| 580 QuotaFileUtil::kNoLimit); | 635 QuotaFileUtil::kNoLimit); |
| 581 } else { | 636 } else { |
| 582 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 637 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
| 583 } | 638 } |
| 584 | 639 |
| 640 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 641 file_system_context(), |
| 642 file_system_operation_context_.src_origin_url(), |
| 643 file_system_operation_context_.src_type())); |
| 644 |
| 585 FileSystemFileUtilProxy::CreateOrOpen( | 645 FileSystemFileUtilProxy::CreateOrOpen( |
| 586 file_system_operation_context_, | 646 file_system_operation_context_, |
| 587 proxy_, | 647 proxy_, |
| 588 src_virtual_path_, | 648 src_virtual_path_, |
| 589 file_flags_, | 649 file_flags_, |
| 590 callback_factory_.NewCallback( | 650 callback_factory_.NewCallback( |
| 591 &FileSystemOperation::DidOpenFile)); | 651 &FileSystemOperation::DidOpenFile)); |
| 592 } | 652 } |
| 593 | 653 |
| 594 // We can only get here on a write or truncate that's not yet completed. | 654 // 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 } | 955 } |
| 896 DCHECK(file_system_file_util); | 956 DCHECK(file_system_file_util); |
| 897 *file_system_file_util = | 957 *file_system_file_util = |
| 898 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); | 958 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); |
| 899 DCHECK(*file_system_file_util); | 959 DCHECK(*file_system_file_util); |
| 900 | 960 |
| 901 return true; | 961 return true; |
| 902 } | 962 } |
| 903 | 963 |
| 904 } // namespace fileapi | 964 } // namespace fileapi |
| OLD | NEW |