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 namespace { | |
| 27 | |
| 28 void SetQuotaForOperation(FileSystemOperationContext* op_context, | |
| 29 const GURL& origin_url, | |
| 30 quota::QuotaStatusCode status, | |
| 31 int64 usage, int64 quota) { | |
| 32 if (op_context->file_system_context()->IsStorageUnlimited(origin_url) || | |
| 33 quota == QuotaFileUtil::kNoLimit) { | |
| 34 op_context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit); | |
| 35 } else { | |
| 36 int64 avail = quota - usage; | |
| 37 if (status != quota::kQuotaStatusOk || avail < 0) | |
| 38 avail = 0; | |
| 39 op_context->set_allowed_bytes_growth(avail); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 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)), |
| 55 is_write_operation_(false) { | |
| 56 DCHECK(file_system_context); | |
| 36 DCHECK(dispatcher); | 57 DCHECK(dispatcher); |
| 37 #ifndef NDEBUG | 58 #ifndef NDEBUG |
| 38 pending_operation_ = kOperationNone; | 59 pending_operation_ = kOperationNone; |
| 39 #endif | 60 #endif |
| 40 } | 61 } |
| 41 | 62 |
| 42 FileSystemOperation::~FileSystemOperation() { | 63 FileSystemOperation::~FileSystemOperation() { |
| 43 if (file_writer_delegate_.get()) | 64 if (file_writer_delegate_.get()) |
| 44 FileSystemFileUtilProxy::Close( | 65 FileSystemFileUtilProxy::Close( |
| 45 file_system_operation_context_, | 66 file_system_operation_context_, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 file_system_operation_context_.set_dest_type(dest_type); | 175 file_system_operation_context_.set_dest_type(dest_type); |
| 155 file_system_operation_context_.set_src_virtual_path(virtual_path_0); | 176 file_system_operation_context_.set_src_virtual_path(virtual_path_0); |
| 156 file_system_operation_context_.set_dest_virtual_path(virtual_path_1); | 177 file_system_operation_context_.set_dest_virtual_path(virtual_path_1); |
| 157 if (!file_system_operation_context_.src_file_system_file_util()) | 178 if (!file_system_operation_context_.src_file_system_file_util()) |
| 158 file_system_operation_context_.set_src_file_system_file_util( | 179 file_system_operation_context_.set_src_file_system_file_util( |
| 159 src_file_system_file_util); | 180 src_file_system_file_util); |
| 160 if (!file_system_operation_context_.dest_file_system_file_util()) | 181 if (!file_system_operation_context_.dest_file_system_file_util()) |
| 161 file_system_operation_context_.set_dest_file_system_file_util( | 182 file_system_operation_context_.set_dest_file_system_file_util( |
| 162 dest_file_system_file_util); | 183 dest_file_system_file_util); |
| 163 | 184 |
| 164 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( | 185 GetUsageAndQuotaThenCallback(dest_origin_url, dest_type, |
| 165 &FileSystemOperation::DelayedCopyForQuota)); | 186 callback_factory_.NewCallback(&FileSystemOperation::DelayedCopyForQuota)); |
| 166 } | 187 } |
| 167 | 188 |
| 168 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 189 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
| 169 int64 usage, int64 quota) { | 190 int64 usage, int64 quota) { |
| 170 if (file_system_context()->IsStorageUnlimited( | 191 SetQuotaForOperation(&file_system_operation_context_, |
| 171 file_system_operation_context()->dest_origin_url()) || | 192 file_system_operation_context_.dest_origin_url(), |
| 172 quota == QuotaFileUtil::kNoLimit) { | 193 status, usage, quota); |
| 173 file_system_operation_context_.set_allowed_bytes_growth( | |
| 174 QuotaFileUtil::kNoLimit); | |
| 175 } else { | |
| 176 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | |
| 177 } | |
| 178 FileSystemFileUtilProxy::Copy( | 194 FileSystemFileUtilProxy::Copy( |
| 179 file_system_operation_context_, | 195 file_system_operation_context_, |
| 180 proxy_, | 196 proxy_, |
| 181 file_system_operation_context_.src_virtual_path(), | 197 file_system_operation_context_.src_virtual_path(), |
| 182 file_system_operation_context_.dest_virtual_path(), | 198 file_system_operation_context_.dest_virtual_path(), |
| 183 callback_factory_.NewCallback( | 199 callback_factory_.NewCallback( |
| 184 &FileSystemOperation::DidFinishFileOperation)); | 200 &FileSystemOperation::DidFinishFileOperation)); |
| 185 } | 201 } |
| 186 | 202 |
| 187 void FileSystemOperation::Move(const GURL& src_path, | 203 void FileSystemOperation::Move(const GURL& src_path, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 213 file_system_operation_context_.set_dest_type(dest_type); | 229 file_system_operation_context_.set_dest_type(dest_type); |
| 214 file_system_operation_context_.set_src_virtual_path(virtual_path_0); | 230 file_system_operation_context_.set_src_virtual_path(virtual_path_0); |
| 215 file_system_operation_context_.set_dest_virtual_path(virtual_path_1); | 231 file_system_operation_context_.set_dest_virtual_path(virtual_path_1); |
| 216 if (!file_system_operation_context_.src_file_system_file_util()) | 232 if (!file_system_operation_context_.src_file_system_file_util()) |
| 217 file_system_operation_context_.set_src_file_system_file_util( | 233 file_system_operation_context_.set_src_file_system_file_util( |
| 218 src_file_system_file_util); | 234 src_file_system_file_util); |
| 219 if (!file_system_operation_context_.dest_file_system_file_util()) | 235 if (!file_system_operation_context_.dest_file_system_file_util()) |
| 220 file_system_operation_context_.set_dest_file_system_file_util( | 236 file_system_operation_context_.set_dest_file_system_file_util( |
| 221 dest_file_system_file_util); | 237 dest_file_system_file_util); |
| 222 | 238 |
| 223 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( | 239 GetUsageAndQuotaThenCallback(dest_origin_url, dest_type, |
| 224 &FileSystemOperation::DelayedMoveForQuota)); | 240 callback_factory_.NewCallback(&FileSystemOperation::DelayedMoveForQuota)); |
| 225 } | 241 } |
| 226 | 242 |
| 227 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, | 243 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
| 228 int64 usage, int64 quota) { | 244 int64 usage, int64 quota) { |
| 229 if (file_system_context()->IsStorageUnlimited( | 245 SetQuotaForOperation(&file_system_operation_context_, |
| 230 file_system_operation_context()->dest_origin_url()) || | 246 file_system_operation_context_.dest_origin_url(), |
| 231 quota == QuotaFileUtil::kNoLimit) { | 247 status, usage, quota); |
| 232 file_system_operation_context_.set_allowed_bytes_growth( | |
| 233 QuotaFileUtil::kNoLimit); | |
| 234 } else { | |
| 235 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | |
| 236 } | |
| 237 FileSystemFileUtilProxy::Move( | 248 FileSystemFileUtilProxy::Move( |
| 238 file_system_operation_context_, | 249 file_system_operation_context_, |
| 239 proxy_, | 250 proxy_, |
| 240 file_system_operation_context_.src_virtual_path(), | 251 file_system_operation_context_.src_virtual_path(), |
| 241 file_system_operation_context_.dest_virtual_path(), | 252 file_system_operation_context_.dest_virtual_path(), |
| 242 callback_factory_.NewCallback( | 253 callback_factory_.NewCallback( |
| 243 &FileSystemOperation::DidFinishFileOperation)); | 254 &FileSystemOperation::DidFinishFileOperation)); |
| 244 } | 255 } |
| 245 | 256 |
| 246 void FileSystemOperation::DirectoryExists(const GURL& path) { | 257 void FileSystemOperation::DirectoryExists(const GURL& path) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 file_system_operation_context_.set_src_virtual_path(virtual_path); | 407 file_system_operation_context_.set_src_virtual_path(virtual_path); |
| 397 if (!file_system_operation_context_.src_file_system_file_util()) | 408 if (!file_system_operation_context_.src_file_system_file_util()) |
| 398 file_system_operation_context_.set_src_file_system_file_util( | 409 file_system_operation_context_.set_src_file_system_file_util( |
| 399 file_system_file_util); | 410 file_system_file_util); |
| 400 DCHECK(blob_url.is_valid()); | 411 DCHECK(blob_url.is_valid()); |
| 401 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); | 412 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); |
| 402 blob_request_.reset( | 413 blob_request_.reset( |
| 403 new net::URLRequest(blob_url, file_writer_delegate_.get())); | 414 new net::URLRequest(blob_url, file_writer_delegate_.get())); |
| 404 blob_request_->set_context(url_request_context); | 415 blob_request_->set_context(url_request_context); |
| 405 | 416 |
| 406 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 417 GetUsageAndQuotaThenCallback(origin_url, type, callback_factory_.NewCallback( |
| 407 &FileSystemOperation::DelayedWriteForQuota)); | 418 &FileSystemOperation::DelayedWriteForQuota)); |
| 408 } | 419 } |
| 409 | 420 |
| 410 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, | 421 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, |
| 411 int64 usage, int64 quota) { | 422 int64 usage, int64 quota) { |
| 412 if (file_system_context()->IsStorageUnlimited( | 423 SetQuotaForOperation(&file_system_operation_context_, |
| 413 file_system_operation_context()->dest_origin_url()) || | 424 file_system_operation_context_.src_origin_url(), |
| 414 quota == QuotaFileUtil::kNoLimit) { | 425 status, usage, quota); |
| 415 file_system_operation_context_.set_allowed_bytes_growth( | 426 FileSystemFileUtilProxy::CreateOrOpenAndQuerySize( |
| 416 QuotaFileUtil::kNoLimit); | |
| 417 } else { | |
| 418 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | |
| 419 } | |
| 420 FileSystemFileUtilProxy::CreateOrOpen( | |
| 421 file_system_operation_context_, | 427 file_system_operation_context_, |
| 422 proxy_, | 428 proxy_, |
| 423 file_system_operation_context_.src_virtual_path(), | 429 file_system_operation_context_.src_virtual_path(), |
| 424 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | | 430 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | |
| 425 base::PLATFORM_FILE_ASYNC, | 431 base::PLATFORM_FILE_ASYNC, |
| 426 callback_factory_.NewCallback( | 432 callback_factory_.NewCallback( |
| 427 &FileSystemOperation::OnFileOpenedForWrite)); | 433 &FileSystemOperation::OnFileOpenedForWrite)); |
| 428 } | 434 } |
| 429 | 435 |
| 430 void FileSystemOperation::Truncate(const GURL& path, int64 length) { | 436 void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 442 return; | 448 return; |
| 443 } | 449 } |
| 444 file_system_operation_context_.set_src_origin_url(origin_url); | 450 file_system_operation_context_.set_src_origin_url(origin_url); |
| 445 file_system_operation_context_.set_src_type(type); | 451 file_system_operation_context_.set_src_type(type); |
| 446 file_system_operation_context_.set_src_virtual_path(virtual_path); | 452 file_system_operation_context_.set_src_virtual_path(virtual_path); |
| 447 if (!file_system_operation_context_.src_file_system_file_util()) | 453 if (!file_system_operation_context_.src_file_system_file_util()) |
| 448 file_system_operation_context_.set_src_file_system_file_util( | 454 file_system_operation_context_.set_src_file_system_file_util( |
| 449 file_system_file_util); | 455 file_system_file_util); |
| 450 length_ = length; | 456 length_ = length; |
| 451 | 457 |
| 452 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 458 GetUsageAndQuotaThenCallback(origin_url, type, callback_factory_.NewCallback( |
| 453 &FileSystemOperation::DelayedTruncateForQuota)); | 459 &FileSystemOperation::DelayedTruncateForQuota)); |
| 454 } | 460 } |
| 455 | 461 |
| 456 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, | 462 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, |
| 457 int64 usage, int64 quota) { | 463 int64 usage, int64 quota) { |
| 458 if (file_system_context()->IsStorageUnlimited( | 464 SetQuotaForOperation(&file_system_operation_context_, |
| 459 file_system_operation_context()->dest_origin_url()) || | 465 file_system_operation_context_.src_origin_url(), |
| 460 quota == QuotaFileUtil::kNoLimit) { | 466 status, usage, quota); |
| 461 file_system_operation_context_.set_allowed_bytes_growth( | |
| 462 QuotaFileUtil::kNoLimit); | |
| 463 } else { | |
| 464 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | |
| 465 } | |
| 466 FileSystemFileUtilProxy::Truncate( | 467 FileSystemFileUtilProxy::Truncate( |
| 467 file_system_operation_context_, | 468 file_system_operation_context_, |
| 468 proxy_, | 469 proxy_, |
| 469 file_system_operation_context_.src_virtual_path(), | 470 file_system_operation_context_.src_virtual_path(), |
| 470 length_, callback_factory_.NewCallback( | 471 length_, callback_factory_.NewCallback( |
| 471 &FileSystemOperation::DidFinishFileOperation)); | 472 &FileSystemOperation::DidFinishFileOperation)); |
| 472 } | 473 } |
| 473 | 474 |
| 474 void FileSystemOperation::TouchFile(const GURL& path, | 475 void FileSystemOperation::TouchFile(const GURL& path, |
| 475 const base::Time& last_access_time, | 476 const base::Time& last_access_time, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 #endif | 509 #endif |
| 509 | 510 |
| 510 peer_handle_ = peer_handle; | 511 peer_handle_ = peer_handle; |
| 511 FilePath virtual_path; | 512 FilePath virtual_path; |
| 512 GURL origin_url; | 513 GURL origin_url; |
| 513 FileSystemType type; | 514 FileSystemType type; |
| 514 FileSystemFileUtil* file_system_file_util; | 515 FileSystemFileUtil* file_system_file_util; |
| 515 if (file_flags & ( | 516 if (file_flags & ( |
| 516 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | | 517 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
| 517 base::PLATFORM_FILE_HIDDEN))) { | 518 base::PLATFORM_FILE_HIDDEN))) { |
| 519 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | |
| 518 delete this; | 520 delete this; |
| 519 return; | 521 return; |
| 520 } | 522 } |
| 521 if (file_flags & | 523 if (file_flags & |
| 522 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 524 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | |
| 523 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 525 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | |
| 524 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 526 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 525 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 527 base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 526 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 528 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { |
| 527 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, | 529 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 528 &type, &virtual_path, &file_system_file_util)) { | 530 &type, &virtual_path, &file_system_file_util)) { |
| 529 delete this; | 531 delete this; |
| 530 return; | 532 return; |
| 531 } | 533 } |
| 532 } else { | 534 } else { |
| 533 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 535 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 534 &file_system_file_util)) { | 536 &file_system_file_util)) { |
| 535 delete this; | 537 delete this; |
| 536 return; | 538 return; |
| 537 } | 539 } |
| 538 } | 540 } |
| 539 file_system_operation_context_.set_src_origin_url(origin_url); | 541 file_system_operation_context_.set_src_origin_url(origin_url); |
| 540 file_system_operation_context_.set_src_type(type); | 542 file_system_operation_context_.set_src_type(type); |
| 541 if (!file_system_operation_context_.src_file_system_file_util()) | 543 if (!file_system_operation_context_.src_file_system_file_util()) |
| 542 file_system_operation_context_.set_src_file_system_file_util( | 544 file_system_operation_context_.set_src_file_system_file_util( |
| 543 file_system_file_util); | 545 file_system_file_util); |
| 544 FileSystemFileUtilProxy::CreateOrOpen( | 546 FileSystemFileUtilProxy::CreateOrOpenAndQuerySize( |
| 545 file_system_operation_context_, | 547 file_system_operation_context_, |
| 546 proxy_, | 548 proxy_, |
| 547 virtual_path, | 549 virtual_path, |
| 548 file_flags, | 550 file_flags, |
| 549 callback_factory_.NewCallback( | 551 callback_factory_.NewCallback( |
| 550 &FileSystemOperation::DidOpenFile)); | 552 &FileSystemOperation::DidOpenFile)); |
| 551 } | 553 } |
| 552 | 554 |
| 553 // We can only get here on a write or truncate that's not yet completed. | 555 // We can only get here on a write or truncate that's not yet completed. |
| 554 // We don't support cancelling any other operation at this time. | 556 // We don't support cancelling any other operation at this time. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 579 // cancel_operation so that when the truncate returns, it can see that it's | 581 // cancel_operation so that when the truncate returns, it can see that it's |
| 580 // been cancelled, report it, and report that the cancel has succeeded. | 582 // been cancelled, report it, and report that the cancel has succeeded. |
| 581 DCHECK(!cancel_operation_.get()); | 583 DCHECK(!cancel_operation_.get()); |
| 582 cancel_operation_.swap(cancel_operation); | 584 cancel_operation_.swap(cancel_operation); |
| 583 } | 585 } |
| 584 } | 586 } |
| 585 | 587 |
| 586 // TODO(ericu): Obfuscation integration. | 588 // TODO(ericu): Obfuscation integration. |
| 587 bool FileSystemOperation::GetUsageAndQuotaThenCallback( | 589 bool FileSystemOperation::GetUsageAndQuotaThenCallback( |
| 588 const GURL& origin_url, | 590 const GURL& origin_url, |
| 591 FileSystemType type, | |
| 589 quota::QuotaManager::GetUsageAndQuotaCallback* callback) { | 592 quota::QuotaManager::GetUsageAndQuotaCallback* callback) { |
| 590 quota::QuotaManagerProxy* quota_manager_proxy = | 593 quota::QuotaManagerProxy* quota_manager_proxy = |
| 591 file_system_context()->quota_manager_proxy(); | 594 file_system_context()->quota_manager_proxy(); |
| 592 if (quota_manager_proxy && quota_manager_proxy->quota_manager() && | 595 if (quota_manager_proxy && quota_manager_proxy->quota_manager() && |
| 593 file_system_operation_context_.src_type() != kFileSystemTypeExternal) { | 596 file_system_operation_context_.src_type() != kFileSystemTypeExternal) { |
| 594 quota_manager_proxy->quota_manager()->GetUsageAndQuota( | 597 quota_manager_proxy->quota_manager()->GetUsageAndQuota( |
| 595 file_system_operation_context_.src_origin_url(), | 598 origin_url, |
| 596 FileSystemTypeToQuotaStorageType( | 599 FileSystemTypeToQuotaStorageType(type), |
| 597 file_system_operation_context_.src_type()), | |
| 598 callback); | 600 callback); |
| 599 } else { | 601 } else { |
| 600 if (file_system_context()->IsStorageUnlimited(origin_url)) { | 602 if (file_system_context()->IsStorageUnlimited(origin_url)) { |
| 601 callback->Run(quota::kQuotaStatusOk, 0, QuotaFileUtil::kNoLimit); | 603 callback->Run(quota::kQuotaStatusOk, 0, QuotaFileUtil::kNoLimit); |
| 602 delete callback; | 604 delete callback; |
| 603 } else { | 605 } else { |
| 604 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); | 606 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); |
| 605 delete callback; | 607 delete callback; |
| 606 return false; | 608 return false; |
| 607 } | 609 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 if (rv == base::PLATFORM_FILE_OK) | 727 if (rv == base::PLATFORM_FILE_OK) |
| 726 dispatcher_->DidSucceed(); | 728 dispatcher_->DidSucceed(); |
| 727 else | 729 else |
| 728 dispatcher_->DidFail(rv); | 730 dispatcher_->DidFail(rv); |
| 729 delete this; | 731 delete this; |
| 730 } | 732 } |
| 731 | 733 |
| 732 void FileSystemOperation::DidOpenFile( | 734 void FileSystemOperation::DidOpenFile( |
| 733 base::PlatformFileError rv, | 735 base::PlatformFileError rv, |
| 734 base::PassPlatformFile file, | 736 base::PassPlatformFile file, |
| 735 bool unused) { | 737 bool unused, |
| 738 int64 file_size) { | |
| 736 if (rv == base::PLATFORM_FILE_OK) | 739 if (rv == base::PLATFORM_FILE_OK) |
| 737 dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); | 740 dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_, file_size); |
| 738 else | 741 else |
| 739 dispatcher_->DidFail(rv); | 742 dispatcher_->DidFail(rv); |
| 740 delete this; | 743 delete this; |
| 741 } | 744 } |
| 742 | 745 |
| 743 void FileSystemOperation::OnFileOpenedForWrite( | 746 void FileSystemOperation::OnFileOpenedForWrite( |
| 744 base::PlatformFileError rv, | 747 base::PlatformFileError rv, |
| 745 base::PassPlatformFile file, | 748 base::PassPlatformFile file, |
| 746 bool created) { | 749 bool created, |
| 750 int64 file_size) { | |
| 747 if (base::PLATFORM_FILE_OK != rv) { | 751 if (base::PLATFORM_FILE_OK != rv) { |
| 748 dispatcher_->DidFail(rv); | 752 dispatcher_->DidFail(rv); |
| 749 delete this; | 753 delete this; |
| 750 return; | 754 return; |
| 751 } | 755 } |
| 752 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); | 756 file_writer_delegate_->Start(file.ReleaseValue(), file_size, |
| 757 blob_request_.get()); | |
| 753 } | 758 } |
| 754 | 759 |
| 755 bool FileSystemOperation::VerifyFileSystemPathForRead( | 760 bool FileSystemOperation::VerifyFileSystemPathForRead( |
| 756 const GURL& path, GURL* origin_url, FileSystemType* type, | 761 const GURL& path, GURL* origin_url, FileSystemType* type, |
| 757 FilePath* virtual_path, FileSystemFileUtil** file_system_file_util) { | 762 FilePath* virtual_path, FileSystemFileUtil** file_system_file_util) { |
| 758 | 763 DCHECK(file_system_context()); |
| 759 // If we have no context, we just allow any operations, for testing. | |
| 760 // TODO(ericu): Revisit this hack for security. | |
| 761 if (!file_system_context()) { | |
| 762 #ifdef OS_WIN | |
| 763 // On Windows, the path will look like /C:/foo/bar; we need to remove the | |
| 764 // leading slash to make it valid. But if it's empty, we shouldn't do | |
| 765 // anything. | |
| 766 std::string temp = UnescapeURLComponent(path.path(), | |
| 767 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | |
| 768 if (temp.size()) | |
| 769 temp = temp.substr(1); | |
| 770 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); | |
| 771 #else | |
| 772 *virtual_path = FilePath(path.path()); | |
| 773 #endif | |
| 774 *type = file_system_operation_context_.src_type(); | |
| 775 *origin_url = file_system_operation_context_.src_origin_url(); | |
| 776 *file_system_file_util = NULL; | |
| 777 return true; | |
| 778 } | |
| 779 | 764 |
| 780 // We may want do more checks, but for now it just checks if the given | 765 // We may want do more checks, but for now it just checks if the given |
| 781 // URL is valid. | 766 // URL is valid. |
| 782 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 767 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 783 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); | 768 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| 784 return false; | 769 return false; |
| 785 } | 770 } |
| 786 if (!file_system_context()->path_manager()->IsAccessAllowed( | 771 if (!file_system_context()->path_manager()->IsAccessAllowed( |
| 787 *origin_url, *type, *virtual_path)) { | 772 *origin_url, *type, *virtual_path)) { |
| 788 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 773 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 if (create && file_system_context()->path_manager()->IsRestrictedFileName( | 836 if (create && file_system_context()->path_manager()->IsRestrictedFileName( |
| 852 *type, virtual_path->BaseName())) { | 837 *type, virtual_path->BaseName())) { |
| 853 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 838 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 854 return false; | 839 return false; |
| 855 } | 840 } |
| 856 DCHECK(file_system_file_util); | 841 DCHECK(file_system_file_util); |
| 857 *file_system_file_util = | 842 *file_system_file_util = |
| 858 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); | 843 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); |
| 859 DCHECK(*file_system_file_util); | 844 DCHECK(*file_system_file_util); |
| 860 | 845 |
| 846 is_write_operation_ = true; | |
|
michaeln
2011/07/20 21:28:33
Seems like an odd place to be setting this flag, a
| |
| 861 return true; | 847 return true; |
| 862 } | 848 } |
| 863 | 849 |
| 864 } // namespace fileapi | 850 } // namespace fileapi |
| OLD | NEW |