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

Side by Side Diff: webkit/quota/quota_manager.cc

Issue 7029007: Implement EvictOriginData in QuotaManager. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed, updated the test, and reflected the comments. Created 9 years, 7 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/quota/quota_manager.h" 5 #include "webkit/quota/quota_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <set> 9 #include <set>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "base/stl_util-inl.h" 15 #include "base/stl_util-inl.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
18 #include "webkit/quota/quota_client.h"
18 #include "webkit/quota/quota_database.h" 19 #include "webkit/quota/quota_database.h"
19 #include "webkit/quota/quota_types.h" 20 #include "webkit/quota/quota_types.h"
20 #include "webkit/quota/usage_tracker.h" 21 #include "webkit/quota/usage_tracker.h"
21 22
22 using base::ScopedCallbackFactory; 23 using base::ScopedCallbackFactory;
23 24
24 namespace quota { 25 namespace quota {
25 26
26 namespace { 27 namespace {
27 // Returns the initial size of the temporary storage quota. 28 // Returns the initial size of the temporary storage quota.
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 const FilePath& profile_path, 518 const FilePath& profile_path,
518 base::MessageLoopProxy* io_thread, 519 base::MessageLoopProxy* io_thread,
519 base::MessageLoopProxy* db_thread) 520 base::MessageLoopProxy* db_thread)
520 : is_incognito_(is_incognito), 521 : is_incognito_(is_incognito),
521 profile_path_(profile_path), 522 profile_path_(profile_path),
522 proxy_(new QuotaManagerProxy( 523 proxy_(new QuotaManagerProxy(
523 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), 524 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)),
524 db_disabled_(false), 525 db_disabled_(false),
525 io_thread_(io_thread), 526 io_thread_(io_thread),
526 db_thread_(db_thread), 527 db_thread_(db_thread),
527 temporary_global_quota_(-1) { 528 num_eviction_requested_clients_(0),
529 num_evicted_clients_(0),
530 temporary_global_quota_(-1),
531 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
528 } 532 }
529 533
530 QuotaManager::~QuotaManager() { 534 QuotaManager::~QuotaManager() {
531 DCHECK(io_thread_->BelongsToCurrentThread()); 535 DCHECK(io_thread_->BelongsToCurrentThread());
536 if (num_eviction_requested_clients_ > 0)
537 delete evict_origin_data_callback_;
532 proxy_->manager_ = NULL; 538 proxy_->manager_ = NULL;
533 std::for_each(clients_.begin(), clients_.end(), 539 std::for_each(clients_.begin(), clients_.end(),
534 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); 540 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed));
535 if (database_.get()) 541 if (database_.get())
536 db_thread_->DeleteSoon(FROM_HERE, database_.release()); 542 db_thread_->DeleteSoon(FROM_HERE, database_.release());
537 } 543 }
538 544
539 void QuotaManager::GetUsageAndQuota( 545 void QuotaManager::GetUsageAndQuota(
540 const GURL& origin, StorageType type, 546 const GURL& origin, StorageType type,
541 GetUsageAndQuotaCallback* callback_ptr) { 547 GetUsageAndQuotaCallback* callback_ptr) {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 if (db_disabled_) { 772 if (db_disabled_) {
767 callback->Run(GURL()); 773 callback->Run(GURL());
768 delete callback; 774 delete callback;
769 return; 775 return;
770 } 776 }
771 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( 777 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask(
772 this, database_.get(), db_thread_, type, origins_in_use_, callback)); 778 this, database_.get(), db_thread_, type, origins_in_use_, callback));
773 task->Start(); 779 task->Start();
774 } 780 }
775 781
782 void QuotaManager::OnOriginDataEvicted(
783 QuotaStatusCode status) {
784 DCHECK(io_thread_->BelongsToCurrentThread());
785
786 if (status != kQuotaStatusOk) {
787 // TODO(dmikurube): Handle error.
788 }
789
790 ++num_evicted_clients_;
791 DCHECK(num_evicted_clients_ <= num_eviction_requested_clients_);
792 if (num_evicted_clients_ == num_eviction_requested_clients_) {
793 num_eviction_requested_clients_ = 0;
794 num_evicted_clients_ = 0;
795
796 evict_origin_data_callback_->Run(kQuotaStatusOk);
797 delete evict_origin_data_callback_;
798 }
799 }
800
776 void QuotaManager::EvictOriginData( 801 void QuotaManager::EvictOriginData(
777 const GURL& origin, 802 const GURL& origin,
778 StorageType type, 803 StorageType type,
779 EvictOriginDataCallback* callback) { 804 EvictOriginDataCallback* callback) {
780 // TODO(dmikurube): Implement it. 805 DCHECK(io_thread_->BelongsToCurrentThread());
806 DCHECK(database_.get());
807 DCHECK(num_evicted_clients_ == 0);
kinuko 2011/05/18 04:45:12 num_evicted_clients_ == 0 wouldn't guarantee we're
Dai Mikurube (NOT FULLTIME) 2011/05/18 05:08:00 Do you mean DCHECK(num_eviction_requested_clients_
808
809 num_eviction_requested_clients_ = clients_.size();
810 num_evicted_clients_ = 0;
811
812 if (origin.is_empty() || num_eviction_requested_clients_ == 0) {
813 callback->Run(kQuotaStatusOk);
814 delete callback;
815 return;
816 }
817
818 evict_origin_data_callback_ = callback;
819 for (QuotaClientList::iterator p = clients_.begin();
820 p != clients_.end();
821 ++p) {
822 (*p)->DeleteOriginData(origin, kStorageTypeTemporary, callback_factory_.
823 NewCallback(&QuotaManager::OnOriginDataEvicted));
824 }
781 } 825 }
782 826
783 void QuotaManager::GetUsageAndQuotaForEviction( 827 void QuotaManager::GetUsageAndQuotaForEviction(
784 GetUsageAndQuotaForEvictionCallback* callback) { 828 GetUsageAndQuotaForEvictionCallback* callback) {
785 // TODO(dmikurube): Implement it. 829 // TODO(dmikurube): Implement it.
786 } 830 }
787 831
788 void QuotaManager::DeleteOnCorrectThread() const { 832 void QuotaManager::DeleteOnCorrectThread() const {
789 if (!io_thread_->BelongsToCurrentThread()) { 833 if (!io_thread_->BelongsToCurrentThread()) {
790 io_thread_->DeleteSoon(FROM_HERE, this); 834 io_thread_->DeleteSoon(FROM_HERE, this);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 922
879 QuotaManagerProxy::QuotaManagerProxy( 923 QuotaManagerProxy::QuotaManagerProxy(
880 QuotaManager* manager, base::MessageLoopProxy* io_thread) 924 QuotaManager* manager, base::MessageLoopProxy* io_thread)
881 : manager_(manager), io_thread_(io_thread) { 925 : manager_(manager), io_thread_(io_thread) {
882 } 926 }
883 927
884 QuotaManagerProxy::~QuotaManagerProxy() { 928 QuotaManagerProxy::~QuotaManagerProxy() {
885 } 929 }
886 930
887 } // namespace quota 931 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698