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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 &type, &src_virtual_path_, &file_util)) { | 115 &type, &src_virtual_path_, &file_util)) { |
116 delete this; | 116 delete this; |
117 return; | 117 return; |
118 } | 118 } |
119 file_system_operation_context_.set_src_origin_url(origin_url); | 119 file_system_operation_context_.set_src_origin_url(origin_url); |
120 file_system_operation_context_.set_src_type(type); | 120 file_system_operation_context_.set_src_type(type); |
121 if (!file_system_operation_context_.src_file_util()) | 121 if (!file_system_operation_context_.src_file_util()) |
122 file_system_operation_context_.set_src_file_util(file_util); | 122 file_system_operation_context_.set_src_file_util(file_util); |
123 exclusive_ = exclusive; | 123 exclusive_ = exclusive; |
124 | 124 |
125 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 125 GetUsageAndQuotaThenCallback( |
126 &FileSystemOperation::DelayedCreateFileForQuota)); | 126 origin_url, |
| 127 base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, |
| 128 weak_factory_.GetWeakPtr())); |
127 } | 129 } |
128 | 130 |
129 void FileSystemOperation::DelayedCreateFileForQuota( | 131 void FileSystemOperation::DelayedCreateFileForQuota( |
130 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 132 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
131 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 133 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
132 | 134 |
133 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 135 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
134 file_system_context(), | 136 file_system_context(), |
135 file_system_operation_context_.src_origin_url(), | 137 file_system_operation_context_.src_origin_url(), |
136 file_system_operation_context_.src_type())); | 138 file_system_operation_context_.src_type())); |
(...skipping 24 matching lines...) Expand all Loading... |
161 delete this; | 163 delete this; |
162 return; | 164 return; |
163 } | 165 } |
164 file_system_operation_context_.set_src_origin_url(origin_url); | 166 file_system_operation_context_.set_src_origin_url(origin_url); |
165 file_system_operation_context_.set_src_type(type); | 167 file_system_operation_context_.set_src_type(type); |
166 if (!file_system_operation_context_.src_file_util()) | 168 if (!file_system_operation_context_.src_file_util()) |
167 file_system_operation_context_.set_src_file_util(file_util); | 169 file_system_operation_context_.set_src_file_util(file_util); |
168 exclusive_ = exclusive; | 170 exclusive_ = exclusive; |
169 recursive_ = recursive; | 171 recursive_ = recursive; |
170 | 172 |
171 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 173 GetUsageAndQuotaThenCallback( |
172 &FileSystemOperation::DelayedCreateDirectoryForQuota)); | 174 origin_url, |
| 175 base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, |
| 176 weak_factory_.GetWeakPtr())); |
173 } | 177 } |
174 | 178 |
175 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 179 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
176 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 180 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
177 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 181 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
178 | 182 |
179 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 183 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
180 file_system_context(), | 184 file_system_context(), |
181 file_system_operation_context_.src_origin_url(), | 185 file_system_operation_context_.src_origin_url(), |
182 file_system_operation_context_.src_type())); | 186 file_system_operation_context_.src_type())); |
(...skipping 27 matching lines...) Expand all Loading... |
210 } | 214 } |
211 file_system_operation_context_.set_src_origin_url(src_origin_url); | 215 file_system_operation_context_.set_src_origin_url(src_origin_url); |
212 file_system_operation_context_.set_dest_origin_url(dest_origin_url); | 216 file_system_operation_context_.set_dest_origin_url(dest_origin_url); |
213 file_system_operation_context_.set_src_type(src_type); | 217 file_system_operation_context_.set_src_type(src_type); |
214 file_system_operation_context_.set_dest_type(dest_type); | 218 file_system_operation_context_.set_dest_type(dest_type); |
215 if (!file_system_operation_context_.src_file_util()) | 219 if (!file_system_operation_context_.src_file_util()) |
216 file_system_operation_context_.set_src_file_util(src_file_util); | 220 file_system_operation_context_.set_src_file_util(src_file_util); |
217 if (!file_system_operation_context_.dest_file_util()) | 221 if (!file_system_operation_context_.dest_file_util()) |
218 file_system_operation_context_.set_dest_file_util(dest_file_util); | 222 file_system_operation_context_.set_dest_file_util(dest_file_util); |
219 | 223 |
220 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( | 224 GetUsageAndQuotaThenCallback( |
221 &FileSystemOperation::DelayedCopyForQuota)); | 225 dest_origin_url, |
| 226 base::Bind(&FileSystemOperation::DelayedCopyForQuota, |
| 227 weak_factory_.GetWeakPtr())); |
222 } | 228 } |
223 | 229 |
224 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 230 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
225 int64 usage, int64 quota) { | 231 int64 usage, int64 quota) { |
226 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 232 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
227 | 233 |
228 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 234 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
229 file_system_context(), | 235 file_system_context(), |
230 file_system_operation_context_.dest_origin_url(), | 236 file_system_operation_context_.dest_origin_url(), |
231 file_system_operation_context_.dest_type())); | 237 file_system_operation_context_.dest_type())); |
(...skipping 27 matching lines...) Expand all Loading... |
259 } | 265 } |
260 file_system_operation_context_.set_src_origin_url(src_origin_url); | 266 file_system_operation_context_.set_src_origin_url(src_origin_url); |
261 file_system_operation_context_.set_dest_origin_url(dest_origin_url); | 267 file_system_operation_context_.set_dest_origin_url(dest_origin_url); |
262 file_system_operation_context_.set_src_type(src_type); | 268 file_system_operation_context_.set_src_type(src_type); |
263 file_system_operation_context_.set_dest_type(dest_type); | 269 file_system_operation_context_.set_dest_type(dest_type); |
264 if (!file_system_operation_context_.src_file_util()) | 270 if (!file_system_operation_context_.src_file_util()) |
265 file_system_operation_context_.set_src_file_util(src_file_util); | 271 file_system_operation_context_.set_src_file_util(src_file_util); |
266 if (!file_system_operation_context_.dest_file_util()) | 272 if (!file_system_operation_context_.dest_file_util()) |
267 file_system_operation_context_.set_dest_file_util(dest_file_util); | 273 file_system_operation_context_.set_dest_file_util(dest_file_util); |
268 | 274 |
269 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( | 275 GetUsageAndQuotaThenCallback( |
270 &FileSystemOperation::DelayedMoveForQuota)); | 276 dest_origin_url, |
| 277 base::Bind(&FileSystemOperation::DelayedMoveForQuota, |
| 278 weak_factory_.GetWeakPtr())); |
271 } | 279 } |
272 | 280 |
273 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, | 281 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
274 int64 usage, int64 quota) { | 282 int64 usage, int64 quota) { |
275 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 283 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
276 | 284 |
277 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 285 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
278 file_system_context(), | 286 file_system_context(), |
279 file_system_operation_context_.dest_origin_url(), | 287 file_system_operation_context_.dest_origin_url(), |
280 file_system_operation_context_.dest_type())); | 288 file_system_operation_context_.dest_type())); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 file_system_operation_context_.set_src_origin_url(origin_url); | 439 file_system_operation_context_.set_src_origin_url(origin_url); |
432 file_system_operation_context_.set_src_type(type); | 440 file_system_operation_context_.set_src_type(type); |
433 if (!file_system_operation_context_.src_file_util()) | 441 if (!file_system_operation_context_.src_file_util()) |
434 file_system_operation_context_.set_src_file_util(file_util); | 442 file_system_operation_context_.set_src_file_util(file_util); |
435 DCHECK(blob_url.is_valid()); | 443 DCHECK(blob_url.is_valid()); |
436 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); | 444 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); |
437 blob_request_.reset( | 445 blob_request_.reset( |
438 new net::URLRequest(blob_url, file_writer_delegate_.get())); | 446 new net::URLRequest(blob_url, file_writer_delegate_.get())); |
439 blob_request_->set_context(url_request_context); | 447 blob_request_->set_context(url_request_context); |
440 | 448 |
441 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 449 GetUsageAndQuotaThenCallback( |
442 &FileSystemOperation::DelayedWriteForQuota)); | 450 origin_url, |
| 451 base::Bind(&FileSystemOperation::DelayedWriteForQuota, |
| 452 weak_factory_.GetWeakPtr())); |
443 } | 453 } |
444 | 454 |
445 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, | 455 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, |
446 int64 usage, int64 quota) { | 456 int64 usage, int64 quota) { |
447 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 457 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
448 | 458 |
449 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 459 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
450 file_system_context(), | 460 file_system_context(), |
451 file_system_operation_context_.src_origin_url(), | 461 file_system_operation_context_.src_origin_url(), |
452 file_system_operation_context_.src_type())); | 462 file_system_operation_context_.src_type())); |
(...skipping 20 matching lines...) Expand all Loading... |
473 &type, &src_virtual_path_, &file_util)) { | 483 &type, &src_virtual_path_, &file_util)) { |
474 delete this; | 484 delete this; |
475 return; | 485 return; |
476 } | 486 } |
477 file_system_operation_context_.set_src_origin_url(origin_url); | 487 file_system_operation_context_.set_src_origin_url(origin_url); |
478 file_system_operation_context_.set_src_type(type); | 488 file_system_operation_context_.set_src_type(type); |
479 if (!file_system_operation_context_.src_file_util()) | 489 if (!file_system_operation_context_.src_file_util()) |
480 file_system_operation_context_.set_src_file_util(file_util); | 490 file_system_operation_context_.set_src_file_util(file_util); |
481 length_ = length; | 491 length_ = length; |
482 | 492 |
483 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 493 GetUsageAndQuotaThenCallback( |
484 &FileSystemOperation::DelayedTruncateForQuota)); | 494 origin_url, |
| 495 base::Bind(&FileSystemOperation::DelayedTruncateForQuota, |
| 496 weak_factory_.GetWeakPtr())); |
485 } | 497 } |
486 | 498 |
487 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, | 499 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, |
488 int64 usage, int64 quota) { | 500 int64 usage, int64 quota) { |
489 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 501 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
490 | 502 |
491 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 503 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
492 file_system_context(), | 504 file_system_context(), |
493 file_system_operation_context_.src_origin_url(), | 505 file_system_operation_context_.src_origin_url(), |
494 file_system_operation_context_.src_type())); | 506 file_system_operation_context_.src_type())); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 delete this; | 574 delete this; |
563 return; | 575 return; |
564 } | 576 } |
565 } | 577 } |
566 file_system_operation_context_.set_src_origin_url(origin_url); | 578 file_system_operation_context_.set_src_origin_url(origin_url); |
567 file_system_operation_context_.set_src_type(type); | 579 file_system_operation_context_.set_src_type(type); |
568 if (!file_system_operation_context_.src_file_util()) | 580 if (!file_system_operation_context_.src_file_util()) |
569 file_system_operation_context_.set_src_file_util(file_util); | 581 file_system_operation_context_.set_src_file_util(file_util); |
570 file_flags_ = file_flags; | 582 file_flags_ = file_flags; |
571 | 583 |
572 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 584 GetUsageAndQuotaThenCallback( |
573 &FileSystemOperation::DelayedOpenFileForQuota)); | 585 origin_url, |
| 586 base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, |
| 587 weak_factory_.GetWeakPtr())); |
574 } | 588 } |
575 | 589 |
576 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, | 590 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, |
577 int64 usage, int64 quota) { | 591 int64 usage, int64 quota) { |
578 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); | 592 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); |
579 | 593 |
580 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 594 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
581 file_system_context(), | 595 file_system_context(), |
582 file_system_operation_context_.src_origin_url(), | 596 file_system_operation_context_.src_origin_url(), |
583 file_system_operation_context_.src_type())); | 597 file_system_operation_context_.src_type())); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 // since it's been proxied to another thread. We need to save the | 630 // since it's been proxied to another thread. We need to save the |
617 // cancel_operation so that when the truncate returns, it can see that it's | 631 // cancel_operation so that when the truncate returns, it can see that it's |
618 // been cancelled, report it, and report that the cancel has succeeded. | 632 // been cancelled, report it, and report that the cancel has succeeded. |
619 DCHECK(!cancel_operation_.get()); | 633 DCHECK(!cancel_operation_.get()); |
620 cancel_operation_.swap(cancel_operation); | 634 cancel_operation_.swap(cancel_operation); |
621 } | 635 } |
622 } | 636 } |
623 | 637 |
624 void FileSystemOperation::GetUsageAndQuotaThenCallback( | 638 void FileSystemOperation::GetUsageAndQuotaThenCallback( |
625 const GURL& origin_url, | 639 const GURL& origin_url, |
626 quota::QuotaManager::GetUsageAndQuotaCallback* callback) { | 640 const quota::QuotaManager::GetUsageAndQuotaCallback& callback) { |
627 quota::QuotaManagerProxy* quota_manager_proxy = | 641 quota::QuotaManagerProxy* quota_manager_proxy = |
628 file_system_context()->quota_manager_proxy(); | 642 file_system_context()->quota_manager_proxy(); |
629 if (!quota_manager_proxy || | 643 if (!quota_manager_proxy || |
630 !file_system_context()->GetQuotaUtil( | 644 !file_system_context()->GetQuotaUtil( |
631 file_system_operation_context_.src_type())) { | 645 file_system_operation_context_.src_type())) { |
632 // If we don't have the quota manager or the requested filesystem type | 646 // If we don't have the quota manager or the requested filesystem type |
633 // does not support quota, we should be able to let it go. | 647 // does not support quota, we should be able to let it go. |
634 callback->Run(quota::kQuotaStatusOk, 0, kint64max); | 648 callback.Run(quota::kQuotaStatusOk, 0, kint64max); |
635 delete callback; | |
636 return; | 649 return; |
637 } | 650 } |
638 DCHECK(quota_manager_proxy); | 651 DCHECK(quota_manager_proxy); |
639 DCHECK(quota_manager_proxy->quota_manager()); | 652 DCHECK(quota_manager_proxy->quota_manager()); |
640 quota_manager_proxy->quota_manager()->GetUsageAndQuota( | 653 quota_manager_proxy->quota_manager()->GetUsageAndQuota( |
641 file_system_operation_context_.src_origin_url(), | 654 file_system_operation_context_.src_origin_url(), |
642 FileSystemTypeToQuotaStorageType( | 655 FileSystemTypeToQuotaStorageType( |
643 file_system_operation_context_.src_type()), | 656 file_system_operation_context_.src_type()), |
644 callback); | 657 callback); |
645 } | 658 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 return false; | 901 return false; |
889 } | 902 } |
890 DCHECK(file_util); | 903 DCHECK(file_util); |
891 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); | 904 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); |
892 DCHECK(*file_util); | 905 DCHECK(*file_util); |
893 | 906 |
894 return true; | 907 return true; |
895 } | 908 } |
896 | 909 |
897 } // namespace fileapi | 910 } // namespace fileapi |
OLD | NEW |