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 num_eviction_requested_clients_(0), | |
528 num_evicted_clients_(0), | |
529 temporary_global_quota_(-1), | 527 temporary_global_quota_(-1), |
530 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 528 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
531 } | 529 } |
532 | 530 |
533 QuotaManager::~QuotaManager() { | 531 QuotaManager::~QuotaManager() { |
534 DCHECK(io_thread_->BelongsToCurrentThread()); | 532 DCHECK(io_thread_->BelongsToCurrentThread()); |
535 proxy_->manager_ = NULL; | 533 proxy_->manager_ = NULL; |
536 std::for_each(clients_.begin(), clients_.end(), | 534 std::for_each(clients_.begin(), clients_.end(), |
537 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); | 535 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); |
538 if (database_.get()) | 536 if (database_.get()) |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( | 772 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( |
775 this, database_.get(), db_thread_, type, origins_in_use_, callback)); | 773 this, database_.get(), db_thread_, type, origins_in_use_, callback)); |
776 task->Start(); | 774 task->Start(); |
777 } | 775 } |
778 | 776 |
779 void QuotaManager::DidOriginDataEvicted( | 777 void QuotaManager::DidOriginDataEvicted( |
780 QuotaStatusCode status) { | 778 QuotaStatusCode status) { |
781 DCHECK(io_thread_->BelongsToCurrentThread()); | 779 DCHECK(io_thread_->BelongsToCurrentThread()); |
782 | 780 |
783 if (status != kQuotaStatusOk) { | 781 if (status != kQuotaStatusOk) { |
784 // TODO(dmikurube): Handle error. | 782 // TODO(dmikurube): Handle error. |
kinuko
2011/05/18 14:10:51
might want to record the # of errors in the evicti
Dai Mikurube (NOT FULLTIME)
2011/05/19 02:28:03
Done. Added a TODO: "The origin with some error s
| |
785 } | 783 } |
786 | 784 |
787 ++num_evicted_clients_; | 785 ++eviction_context_.num_evicted_clients; |
788 DCHECK(num_evicted_clients_ <= num_eviction_requested_clients_); | 786 DCHECK(eviction_context_.num_evicted_clients <= |
789 if (num_evicted_clients_ == num_eviction_requested_clients_) { | 787 eviction_context_.num_eviction_requested_clients); |
790 num_eviction_requested_clients_ = 0; | 788 if (eviction_context_.num_evicted_clients == |
791 num_evicted_clients_ = 0; | 789 eviction_context_.num_eviction_requested_clients) { |
kinuko
2011/05/18 14:10:51
Nit: Looking at this code again (with longer varia
Dai Mikurube (NOT FULLTIME)
2011/05/19 02:28:03
Is that so impressive? As I replied to Michael, I
kinuko
2011/05/19 02:48:42
Mikurube-san, as you can see this comment is prefi
Dai Mikurube (NOT FULLTIME)
2011/05/19 03:20:09
FYI, what I thought was tracking both of the total
| |
790 eviction_context_.num_eviction_requested_clients = 0; | |
791 eviction_context_.num_evicted_clients = 0; | |
792 | 792 |
793 evict_origin_data_callback_->Run(kQuotaStatusOk); | 793 eviction_context_.evict_origin_data_callback->Run(kQuotaStatusOk); |
794 evict_origin_data_callback_.reset(); | 794 eviction_context_.evict_origin_data_callback.reset(); |
795 } | 795 } |
796 } | 796 } |
797 | 797 |
798 void QuotaManager::EvictOriginData( | 798 void QuotaManager::EvictOriginData( |
799 const GURL& origin, | 799 const GURL& origin, |
800 StorageType type, | 800 StorageType type, |
801 EvictOriginDataCallback* callback) { | 801 EvictOriginDataCallback* callback) { |
802 DCHECK(io_thread_->BelongsToCurrentThread()); | 802 DCHECK(io_thread_->BelongsToCurrentThread()); |
803 DCHECK(database_.get()); | 803 DCHECK(database_.get()); |
804 DCHECK(num_eviction_requested_clients_ == 0); | 804 DCHECK(eviction_context_.num_eviction_requested_clients == 0); |
805 DCHECK(type == kStorageTypeTemporary); | 805 DCHECK(type == kStorageTypeTemporary); |
806 | 806 |
807 int num_clients = clients_.size(); | 807 int num_clients = clients_.size(); |
808 | 808 |
809 if (origin.is_empty() || num_clients == 0) { | 809 if (origin.is_empty() || num_clients == 0) { |
810 callback->Run(kQuotaStatusOk); | 810 callback->Run(kQuotaStatusOk); |
811 delete callback; | 811 delete callback; |
812 return; | 812 return; |
813 } | 813 } |
814 | 814 |
815 num_eviction_requested_clients_ = num_clients; | 815 eviction_context_.num_eviction_requested_clients = num_clients; |
816 num_evicted_clients_ = 0; | 816 eviction_context_.num_evicted_clients = 0; |
817 | 817 |
818 evict_origin_data_callback_.reset(callback); | 818 eviction_context_.evict_origin_data_callback.reset(callback); |
819 for (QuotaClientList::iterator p = clients_.begin(); | 819 for (QuotaClientList::iterator p = clients_.begin(); |
820 p != clients_.end(); | 820 p != clients_.end(); |
821 ++p) { | 821 ++p) { |
822 (*p)->DeleteOriginData(origin, type, callback_factory_. | 822 (*p)->DeleteOriginData(origin, type, callback_factory_. |
823 NewCallback(&QuotaManager::DidOriginDataEvicted)); | 823 NewCallback(&QuotaManager::DidOriginDataEvicted)); |
824 } | 824 } |
825 } | 825 } |
826 | 826 |
827 void QuotaManager::DidGetAvailableSpaceForEviction( | |
828 QuotaStatusCode status, | |
829 int64 available_space) { | |
830 eviction_context_.get_usage_and_quota_callback->Run(status, | |
831 eviction_context_.usage, eviction_context_.quota, available_space); | |
832 eviction_context_.get_usage_and_quota_callback.reset(); | |
833 } | |
834 | |
835 void QuotaManager::DidGetGlobalQuotaForEviction( | |
836 QuotaStatusCode status, | |
837 int64 quota) { | |
838 if (status != kQuotaStatusOk) { | |
839 eviction_context_.get_usage_and_quota_callback->Run(status, | |
840 eviction_context_.usage, quota, 0); | |
841 eviction_context_.get_usage_and_quota_callback.reset(); | |
842 return; | |
843 } | |
844 | |
845 eviction_context_.quota = quota; | |
846 GetAvailableSpace(callback_factory_. | |
847 NewCallback(&QuotaManager::DidGetAvailableSpaceForEviction)); | |
848 } | |
849 | |
850 void QuotaManager::DidGetGlobalUsageForEviction(int64 usage) { | |
851 eviction_context_.usage = usage; | |
852 GetTemporaryGlobalQuota(callback_factory_. | |
853 NewCallback(&QuotaManager::DidGetGlobalQuotaForEviction)); | |
854 } | |
855 | |
827 void QuotaManager::GetUsageAndQuotaForEviction( | 856 void QuotaManager::GetUsageAndQuotaForEviction( |
828 GetUsageAndQuotaForEvictionCallback* callback) { | 857 GetUsageAndQuotaForEvictionCallback* callback) { |
829 // TODO(dmikurube): Implement it. | 858 DCHECK(io_thread_->BelongsToCurrentThread()); |
859 DCHECK(!eviction_context_.get_usage_and_quota_callback.get()); | |
860 | |
861 eviction_context_.get_usage_and_quota_callback.reset(callback); | |
862 // TODO(dmikurube): Make kStorageTypeTemporary an argument? | |
863 GetGlobalUsage(kStorageTypeTemporary, callback_factory_. | |
864 NewCallback(&QuotaManager::DidGetGlobalUsageForEviction)); | |
830 } | 865 } |
831 | 866 |
832 void QuotaManager::DeleteOnCorrectThread() const { | 867 void QuotaManager::DeleteOnCorrectThread() const { |
833 if (!io_thread_->BelongsToCurrentThread()) { | 868 if (!io_thread_->BelongsToCurrentThread()) { |
834 io_thread_->DeleteSoon(FROM_HERE, this); | 869 io_thread_->DeleteSoon(FROM_HERE, this); |
835 return; | 870 return; |
836 } | 871 } |
837 delete this; | 872 delete this; |
838 } | 873 } |
839 | 874 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 | 957 |
923 QuotaManagerProxy::QuotaManagerProxy( | 958 QuotaManagerProxy::QuotaManagerProxy( |
924 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 959 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
925 : manager_(manager), io_thread_(io_thread) { | 960 : manager_(manager), io_thread_(io_thread) { |
926 } | 961 } |
927 | 962 |
928 QuotaManagerProxy::~QuotaManagerProxy() { | 963 QuotaManagerProxy::~QuotaManagerProxy() { |
929 } | 964 } |
930 | 965 |
931 } // namespace quota | 966 } // namespace quota |
OLD | NEW |