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/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 |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 const FilePath& profile_path, | 517 const FilePath& profile_path, |
518 base::MessageLoopProxy* io_thread, | 518 base::MessageLoopProxy* io_thread, |
519 base::MessageLoopProxy* db_thread) | 519 base::MessageLoopProxy* db_thread) |
520 : is_incognito_(is_incognito), | 520 : is_incognito_(is_incognito), |
521 profile_path_(profile_path), | 521 profile_path_(profile_path), |
522 proxy_(new QuotaManagerProxy( | 522 proxy_(new QuotaManagerProxy( |
523 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), | 523 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), |
524 db_disabled_(false), | 524 db_disabled_(false), |
525 io_thread_(io_thread), | 525 io_thread_(io_thread), |
526 db_thread_(db_thread), | 526 db_thread_(db_thread), |
527 temporary_global_quota_(-1) { | 527 num_eviction_requested_clients_(0), |
| 528 num_evicted_clients_(0), |
| 529 temporary_global_quota_(-1), |
| 530 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
528 } | 531 } |
529 | 532 |
530 QuotaManager::~QuotaManager() { | 533 QuotaManager::~QuotaManager() { |
531 DCHECK(io_thread_->BelongsToCurrentThread()); | 534 DCHECK(io_thread_->BelongsToCurrentThread()); |
532 proxy_->manager_ = NULL; | 535 proxy_->manager_ = NULL; |
533 std::for_each(clients_.begin(), clients_.end(), | 536 std::for_each(clients_.begin(), clients_.end(), |
534 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); | 537 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); |
535 if (database_.get()) | 538 if (database_.get()) |
536 db_thread_->DeleteSoon(FROM_HERE, database_.release()); | 539 db_thread_->DeleteSoon(FROM_HERE, database_.release()); |
537 } | 540 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 if (db_disabled_) { | 769 if (db_disabled_) { |
767 callback->Run(GURL()); | 770 callback->Run(GURL()); |
768 delete callback; | 771 delete callback; |
769 return; | 772 return; |
770 } | 773 } |
771 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( | 774 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( |
772 this, database_.get(), db_thread_, type, origins_in_use_, callback)); | 775 this, database_.get(), db_thread_, type, origins_in_use_, callback)); |
773 task->Start(); | 776 task->Start(); |
774 } | 777 } |
775 | 778 |
| 779 void QuotaManager::DidOriginDataEvicted( |
| 780 QuotaStatusCode status) { |
| 781 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 782 |
| 783 if (status != kQuotaStatusOk) { |
| 784 // TODO(dmikurube): Handle error. |
| 785 } |
| 786 |
| 787 ++num_evicted_clients_; |
| 788 DCHECK(num_evicted_clients_ <= num_eviction_requested_clients_); |
| 789 if (num_evicted_clients_ == num_eviction_requested_clients_) { |
| 790 num_eviction_requested_clients_ = 0; |
| 791 num_evicted_clients_ = 0; |
| 792 |
| 793 evict_origin_data_callback_->Run(kQuotaStatusOk); |
| 794 evict_origin_data_callback_.reset(); |
| 795 } |
| 796 } |
| 797 |
776 void QuotaManager::EvictOriginData( | 798 void QuotaManager::EvictOriginData( |
777 const GURL& origin, | 799 const GURL& origin, |
778 StorageType type, | 800 StorageType type, |
779 EvictOriginDataCallback* callback) { | 801 EvictOriginDataCallback* callback) { |
780 // TODO(dmikurube): Implement it. | 802 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 803 DCHECK(database_.get()); |
| 804 DCHECK(num_eviction_requested_clients_ == 0); |
| 805 DCHECK(type == kStorageTypeTemporary); |
| 806 |
| 807 int num_clients = clients_.size(); |
| 808 |
| 809 if (origin.is_empty() || num_clients == 0) { |
| 810 callback->Run(kQuotaStatusOk); |
| 811 delete callback; |
| 812 return; |
| 813 } |
| 814 |
| 815 num_eviction_requested_clients_ = num_clients; |
| 816 num_evicted_clients_ = 0; |
| 817 |
| 818 evict_origin_data_callback_.reset(callback); |
| 819 for (QuotaClientList::iterator p = clients_.begin(); |
| 820 p != clients_.end(); |
| 821 ++p) { |
| 822 (*p)->DeleteOriginData(origin, type, callback_factory_. |
| 823 NewCallback(&QuotaManager::DidOriginDataEvicted)); |
| 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 Loading... |
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 |
OLD | NEW |