Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: webkit/fileapi/file_system_operation.cc

Issue 8070001: Use base::Callback in Quota related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: choke lint Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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),
68 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
67 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 69 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(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(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 &type, &src_virtual_path_, &file_util)) { 115 &type, &src_virtual_path_, &file_util)) {
114 delete this; 116 delete this;
115 return; 117 return;
116 } 118 }
117 file_system_operation_context_.set_src_origin_url(origin_url); 119 file_system_operation_context_.set_src_origin_url(origin_url);
118 file_system_operation_context_.set_src_type(type); 120 file_system_operation_context_.set_src_type(type);
119 if (!file_system_operation_context_.src_file_util()) 121 if (!file_system_operation_context_.src_file_util())
120 file_system_operation_context_.set_src_file_util(file_util); 122 file_system_operation_context_.set_src_file_util(file_util);
121 exclusive_ = exclusive; 123 exclusive_ = exclusive;
122 124
123 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( 125 GetUsageAndQuotaThenCallback(
124 &FileSystemOperation::DelayedCreateFileForQuota)); 126 origin_url,
127 base::Bind(&FileSystemOperation::DelayedCreateFileForQuota,
128 weak_factory_.GetWeakPtr()));
125 } 129 }
126 130
127 void FileSystemOperation::DelayedCreateFileForQuota( 131 void FileSystemOperation::DelayedCreateFileForQuota(
128 quota::QuotaStatusCode status, int64 usage, int64 quota) { 132 quota::QuotaStatusCode status, int64 usage, int64 quota) {
129 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); 133 file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
130 134
131 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 135 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
132 file_system_context(), 136 file_system_context(),
133 file_system_operation_context_.src_origin_url(), 137 file_system_operation_context_.src_origin_url(),
134 file_system_operation_context_.src_type())); 138 file_system_operation_context_.src_type()));
(...skipping 23 matching lines...) Expand all
158 delete this; 162 delete this;
159 return; 163 return;
160 } 164 }
161 file_system_operation_context_.set_src_origin_url(origin_url); 165 file_system_operation_context_.set_src_origin_url(origin_url);
162 file_system_operation_context_.set_src_type(type); 166 file_system_operation_context_.set_src_type(type);
163 if (!file_system_operation_context_.src_file_util()) 167 if (!file_system_operation_context_.src_file_util())
164 file_system_operation_context_.set_src_file_util(file_util); 168 file_system_operation_context_.set_src_file_util(file_util);
165 exclusive_ = exclusive; 169 exclusive_ = exclusive;
166 recursive_ = recursive; 170 recursive_ = recursive;
167 171
168 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( 172 GetUsageAndQuotaThenCallback(
169 &FileSystemOperation::DelayedCreateDirectoryForQuota)); 173 origin_url,
174 base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota,
175 weak_factory_.GetWeakPtr()));
170 } 176 }
171 177
172 void FileSystemOperation::DelayedCreateDirectoryForQuota( 178 void FileSystemOperation::DelayedCreateDirectoryForQuota(
173 quota::QuotaStatusCode status, int64 usage, int64 quota) { 179 quota::QuotaStatusCode status, int64 usage, int64 quota) {
174 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); 180 file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
175 181
176 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 182 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
177 file_system_context(), 183 file_system_context(),
178 file_system_operation_context_.src_origin_url(), 184 file_system_operation_context_.src_origin_url(),
179 file_system_operation_context_.src_type())); 185 file_system_operation_context_.src_type()));
(...skipping 30 matching lines...) Expand all
210 } 216 }
211 file_system_operation_context_.set_src_origin_url(src_origin_url); 217 file_system_operation_context_.set_src_origin_url(src_origin_url);
212 file_system_operation_context_.set_dest_origin_url(dest_origin_url); 218 file_system_operation_context_.set_dest_origin_url(dest_origin_url);
213 file_system_operation_context_.set_src_type(src_type); 219 file_system_operation_context_.set_src_type(src_type);
214 file_system_operation_context_.set_dest_type(dest_type); 220 file_system_operation_context_.set_dest_type(dest_type);
215 if (!file_system_operation_context_.src_file_util()) 221 if (!file_system_operation_context_.src_file_util())
216 file_system_operation_context_.set_src_file_util(src_file_util); 222 file_system_operation_context_.set_src_file_util(src_file_util);
217 if (!file_system_operation_context_.dest_file_util()) 223 if (!file_system_operation_context_.dest_file_util())
218 file_system_operation_context_.set_dest_file_util(dest_file_util); 224 file_system_operation_context_.set_dest_file_util(dest_file_util);
219 225
220 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( 226 GetUsageAndQuotaThenCallback(
221 &FileSystemOperation::DelayedCopyForQuota)); 227 dest_origin_url,
228 base::Bind(&FileSystemOperation::DelayedCopyForQuota,
229 weak_factory_.GetWeakPtr()));
222 } 230 }
223 231
224 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, 232 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status,
225 int64 usage, int64 quota) { 233 int64 usage, int64 quota) {
226 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); 234 file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
227 235
228 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 236 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
229 file_system_context(), 237 file_system_context(),
230 file_system_operation_context_.dest_origin_url(), 238 file_system_operation_context_.dest_origin_url(),
231 file_system_operation_context_.dest_type())); 239 file_system_operation_context_.dest_type()));
(...skipping 29 matching lines...) Expand all
261 } 269 }
262 file_system_operation_context_.set_src_origin_url(src_origin_url); 270 file_system_operation_context_.set_src_origin_url(src_origin_url);
263 file_system_operation_context_.set_dest_origin_url(dest_origin_url); 271 file_system_operation_context_.set_dest_origin_url(dest_origin_url);
264 file_system_operation_context_.set_src_type(src_type); 272 file_system_operation_context_.set_src_type(src_type);
265 file_system_operation_context_.set_dest_type(dest_type); 273 file_system_operation_context_.set_dest_type(dest_type);
266 if (!file_system_operation_context_.src_file_util()) 274 if (!file_system_operation_context_.src_file_util())
267 file_system_operation_context_.set_src_file_util(src_file_util); 275 file_system_operation_context_.set_src_file_util(src_file_util);
268 if (!file_system_operation_context_.dest_file_util()) 276 if (!file_system_operation_context_.dest_file_util())
269 file_system_operation_context_.set_dest_file_util(dest_file_util); 277 file_system_operation_context_.set_dest_file_util(dest_file_util);
270 278
271 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( 279 GetUsageAndQuotaThenCallback(
272 &FileSystemOperation::DelayedMoveForQuota)); 280 dest_origin_url,
281 base::Bind(&FileSystemOperation::DelayedMoveForQuota,
282 weak_factory_.GetWeakPtr()));
273 } 283 }
274 284
275 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, 285 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status,
276 int64 usage, int64 quota) { 286 int64 usage, int64 quota) {
277 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); 287 file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
278 288
279 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 289 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
280 file_system_context(), 290 file_system_context(),
281 file_system_operation_context_.dest_origin_url(), 291 file_system_operation_context_.dest_origin_url(),
282 file_system_operation_context_.dest_type())); 292 file_system_operation_context_.dest_type()));
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 file_system_operation_context_.set_src_origin_url(origin_url); 445 file_system_operation_context_.set_src_origin_url(origin_url);
436 file_system_operation_context_.set_src_type(type); 446 file_system_operation_context_.set_src_type(type);
437 if (!file_system_operation_context_.src_file_util()) 447 if (!file_system_operation_context_.src_file_util())
438 file_system_operation_context_.set_src_file_util(file_util); 448 file_system_operation_context_.set_src_file_util(file_util);
439 DCHECK(blob_url.is_valid()); 449 DCHECK(blob_url.is_valid());
440 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); 450 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_));
441 blob_request_.reset( 451 blob_request_.reset(
442 new net::URLRequest(blob_url, file_writer_delegate_.get())); 452 new net::URLRequest(blob_url, file_writer_delegate_.get()));
443 blob_request_->set_context(url_request_context); 453 blob_request_->set_context(url_request_context);
444 454
445 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( 455 GetUsageAndQuotaThenCallback(
446 &FileSystemOperation::DelayedWriteForQuota)); 456 origin_url,
457 base::Bind(&FileSystemOperation::DelayedWriteForQuota,
458 weak_factory_.GetWeakPtr()));
447 } 459 }
448 460
449 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, 461 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
450 int64 usage, int64 quota) { 462 int64 usage, int64 quota) {
451 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); 463 file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
452 464
453 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 465 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
454 file_system_context(), 466 file_system_context(),
455 file_system_operation_context_.src_origin_url(), 467 file_system_operation_context_.src_origin_url(),
456 file_system_operation_context_.src_type())); 468 file_system_operation_context_.src_type()));
(...skipping 20 matching lines...) Expand all
477 &type, &src_virtual_path_, &file_util)) { 489 &type, &src_virtual_path_, &file_util)) {
478 delete this; 490 delete this;
479 return; 491 return;
480 } 492 }
481 file_system_operation_context_.set_src_origin_url(origin_url); 493 file_system_operation_context_.set_src_origin_url(origin_url);
482 file_system_operation_context_.set_src_type(type); 494 file_system_operation_context_.set_src_type(type);
483 if (!file_system_operation_context_.src_file_util()) 495 if (!file_system_operation_context_.src_file_util())
484 file_system_operation_context_.set_src_file_util(file_util); 496 file_system_operation_context_.set_src_file_util(file_util);
485 length_ = length; 497 length_ = length;
486 498
487 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( 499 GetUsageAndQuotaThenCallback(
488 &FileSystemOperation::DelayedTruncateForQuota)); 500 origin_url,
501 base::Bind(&FileSystemOperation::DelayedTruncateForQuota,
502 weak_factory_.GetWeakPtr()));
489 } 503 }
490 504
491 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, 505 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status,
492 int64 usage, int64 quota) { 506 int64 usage, int64 quota) {
493 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); 507 file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
494 508
495 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 509 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
496 file_system_context(), 510 file_system_context(),
497 file_system_operation_context_.src_origin_url(), 511 file_system_operation_context_.src_origin_url(),
498 file_system_operation_context_.src_type())); 512 file_system_operation_context_.src_type()));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 delete this; 581 delete this;
568 return; 582 return;
569 } 583 }
570 } 584 }
571 file_system_operation_context_.set_src_origin_url(origin_url); 585 file_system_operation_context_.set_src_origin_url(origin_url);
572 file_system_operation_context_.set_src_type(type); 586 file_system_operation_context_.set_src_type(type);
573 if (!file_system_operation_context_.src_file_util()) 587 if (!file_system_operation_context_.src_file_util())
574 file_system_operation_context_.set_src_file_util(file_util); 588 file_system_operation_context_.set_src_file_util(file_util);
575 file_flags_ = file_flags; 589 file_flags_ = file_flags;
576 590
577 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( 591 GetUsageAndQuotaThenCallback(
578 &FileSystemOperation::DelayedOpenFileForQuota)); 592 origin_url,
593 base::Bind(&FileSystemOperation::DelayedOpenFileForQuota,
594 weak_factory_.GetWeakPtr()));
579 } 595 }
580 596
581 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, 597 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status,
582 int64 usage, int64 quota) { 598 int64 usage, int64 quota) {
583 file_system_operation_context_.set_allowed_bytes_growth(quota - usage); 599 file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
584 600
585 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 601 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
586 file_system_context(), 602 file_system_context(),
587 file_system_operation_context_.src_origin_url(), 603 file_system_operation_context_.src_origin_url(),
588 file_system_operation_context_.src_type())); 604 file_system_operation_context_.src_type()));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // since it's been proxied to another thread. We need to save the 640 // since it's been proxied to another thread. We need to save the
625 // cancel_operation so that when the truncate returns, it can see that it's 641 // cancel_operation so that when the truncate returns, it can see that it's
626 // been cancelled, report it, and report that the cancel has succeeded. 642 // been cancelled, report it, and report that the cancel has succeeded.
627 DCHECK(!cancel_operation_.get()); 643 DCHECK(!cancel_operation_.get());
628 cancel_operation_.swap(cancel_operation); 644 cancel_operation_.swap(cancel_operation);
629 } 645 }
630 } 646 }
631 647
632 void FileSystemOperation::GetUsageAndQuotaThenCallback( 648 void FileSystemOperation::GetUsageAndQuotaThenCallback(
633 const GURL& origin_url, 649 const GURL& origin_url,
634 quota::QuotaManager::GetUsageAndQuotaCallback* callback) { 650 quota::QuotaManager::GetUsageAndQuotaCallback callback) {
635 quota::QuotaManagerProxy* quota_manager_proxy = 651 quota::QuotaManagerProxy* quota_manager_proxy =
636 file_system_context()->quota_manager_proxy(); 652 file_system_context()->quota_manager_proxy();
637 if (!quota_manager_proxy || 653 if (!quota_manager_proxy ||
638 !file_system_context()->GetQuotaUtil( 654 !file_system_context()->GetQuotaUtil(
639 file_system_operation_context_.src_type())) { 655 file_system_operation_context_.src_type())) {
640 // If we don't have the quota manager or the requested filesystem type 656 // If we don't have the quota manager or the requested filesystem type
641 // does not support quota, we should be able to let it go. 657 // does not support quota, we should be able to let it go.
642 callback->Run(quota::kQuotaStatusOk, 0, kint64max); 658 callback.Run(quota::kQuotaStatusOk, 0, kint64max);
643 delete callback;
644 return; 659 return;
645 } 660 }
646 DCHECK(quota_manager_proxy); 661 DCHECK(quota_manager_proxy);
647 DCHECK(quota_manager_proxy->quota_manager()); 662 DCHECK(quota_manager_proxy->quota_manager());
648 quota_manager_proxy->quota_manager()->GetUsageAndQuota( 663 quota_manager_proxy->quota_manager()->GetUsageAndQuota(
649 file_system_operation_context_.src_origin_url(), 664 file_system_operation_context_.src_origin_url(),
650 FileSystemTypeToQuotaStorageType( 665 FileSystemTypeToQuotaStorageType(
651 file_system_operation_context_.src_type()), 666 file_system_operation_context_.src_type()),
652 callback); 667 callback);
653 } 668 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 return false; 911 return false;
897 } 912 }
898 DCHECK(file_util); 913 DCHECK(file_util);
899 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); 914 *file_util = file_system_context()->path_manager()->GetFileUtil(*type);
900 DCHECK(*file_util); 915 DCHECK(*file_util);
901 916
902 return true; 917 return true;
903 } 918 }
904 919
905 } // namespace fileapi 920 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698