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 ++eviction_context_.num_eviction_error; |
| 783 // TODO(dmikurube): The origin with some error should have lower priority in |
| 784 // the next eviction? |
785 } | 785 } |
786 | 786 |
787 ++num_evicted_clients_; | 787 ++eviction_context_.num_evicted_clients; |
788 DCHECK(num_evicted_clients_ <= num_eviction_requested_clients_); | 788 DCHECK(eviction_context_.num_evicted_clients <= |
789 if (num_evicted_clients_ == num_eviction_requested_clients_) { | 789 eviction_context_.num_eviction_requested_clients); |
790 num_eviction_requested_clients_ = 0; | 790 if (eviction_context_.num_evicted_clients == |
791 num_evicted_clients_ = 0; | 791 eviction_context_.num_eviction_requested_clients) { |
| 792 eviction_context_.num_eviction_requested_clients = 0; |
| 793 eviction_context_.num_evicted_clients = 0; |
792 | 794 |
793 evict_origin_data_callback_->Run(kQuotaStatusOk); | 795 // TODO(dmikurube): Call DeleteOriginFromDatabase here. |
794 evict_origin_data_callback_.reset(); | 796 eviction_context_.evict_origin_data_callback->Run(kQuotaStatusOk); |
| 797 eviction_context_.evict_origin_data_callback.reset(); |
795 } | 798 } |
796 } | 799 } |
797 | 800 |
798 void QuotaManager::EvictOriginData( | 801 void QuotaManager::EvictOriginData( |
799 const GURL& origin, | 802 const GURL& origin, |
800 StorageType type, | 803 StorageType type, |
801 EvictOriginDataCallback* callback) { | 804 EvictOriginDataCallback* callback) { |
802 DCHECK(io_thread_->BelongsToCurrentThread()); | 805 DCHECK(io_thread_->BelongsToCurrentThread()); |
803 DCHECK(database_.get()); | 806 DCHECK(database_.get()); |
804 DCHECK(num_eviction_requested_clients_ == 0); | 807 DCHECK(eviction_context_.num_eviction_requested_clients == 0); |
805 DCHECK(type == kStorageTypeTemporary); | 808 DCHECK(type == kStorageTypeTemporary); |
806 | 809 |
807 int num_clients = clients_.size(); | 810 int num_clients = clients_.size(); |
808 | 811 |
809 if (origin.is_empty() || num_clients == 0) { | 812 if (origin.is_empty() || num_clients == 0) { |
810 callback->Run(kQuotaStatusOk); | 813 callback->Run(kQuotaStatusOk); |
811 delete callback; | 814 delete callback; |
812 return; | 815 return; |
813 } | 816 } |
814 | 817 |
815 num_eviction_requested_clients_ = num_clients; | 818 eviction_context_.num_eviction_requested_clients = num_clients; |
816 num_evicted_clients_ = 0; | 819 eviction_context_.num_evicted_clients = 0; |
817 | 820 |
818 evict_origin_data_callback_.reset(callback); | 821 eviction_context_.evict_origin_data_callback.reset(callback); |
819 for (QuotaClientList::iterator p = clients_.begin(); | 822 for (QuotaClientList::iterator p = clients_.begin(); |
820 p != clients_.end(); | 823 p != clients_.end(); |
821 ++p) { | 824 ++p) { |
822 (*p)->DeleteOriginData(origin, type, callback_factory_. | 825 (*p)->DeleteOriginData(origin, type, callback_factory_. |
823 NewCallback(&QuotaManager::DidOriginDataEvicted)); | 826 NewCallback(&QuotaManager::DidOriginDataEvicted)); |
824 } | 827 } |
825 } | 828 } |
826 | 829 |
| 830 void QuotaManager::DidGetAvailableSpaceForEviction( |
| 831 QuotaStatusCode status, |
| 832 int64 available_space) { |
| 833 eviction_context_.get_usage_and_quota_callback->Run(status, |
| 834 eviction_context_.usage, eviction_context_.quota, available_space); |
| 835 eviction_context_.get_usage_and_quota_callback.reset(); |
| 836 } |
| 837 |
| 838 void QuotaManager::DidGetGlobalQuotaForEviction( |
| 839 QuotaStatusCode status, |
| 840 int64 quota) { |
| 841 if (status != kQuotaStatusOk) { |
| 842 eviction_context_.get_usage_and_quota_callback->Run(status, |
| 843 eviction_context_.usage, quota, 0); |
| 844 eviction_context_.get_usage_and_quota_callback.reset(); |
| 845 return; |
| 846 } |
| 847 |
| 848 eviction_context_.quota = quota; |
| 849 GetAvailableSpace(callback_factory_. |
| 850 NewCallback(&QuotaManager::DidGetAvailableSpaceForEviction)); |
| 851 } |
| 852 |
| 853 void QuotaManager::DidGetGlobalUsageForEviction(int64 usage) { |
| 854 eviction_context_.usage = usage; |
| 855 GetTemporaryGlobalQuota(callback_factory_. |
| 856 NewCallback(&QuotaManager::DidGetGlobalQuotaForEviction)); |
| 857 } |
| 858 |
827 void QuotaManager::GetUsageAndQuotaForEviction( | 859 void QuotaManager::GetUsageAndQuotaForEviction( |
828 GetUsageAndQuotaForEvictionCallback* callback) { | 860 GetUsageAndQuotaForEvictionCallback* callback) { |
829 // TODO(dmikurube): Implement it. | 861 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 862 DCHECK(!eviction_context_.get_usage_and_quota_callback.get()); |
| 863 |
| 864 eviction_context_.get_usage_and_quota_callback.reset(callback); |
| 865 // TODO(dmikurube): Make kStorageTypeTemporary an argument. |
| 866 GetGlobalUsage(kStorageTypeTemporary, callback_factory_. |
| 867 NewCallback(&QuotaManager::DidGetGlobalUsageForEviction)); |
830 } | 868 } |
831 | 869 |
832 void QuotaManager::DeleteOnCorrectThread() const { | 870 void QuotaManager::DeleteOnCorrectThread() const { |
833 if (!io_thread_->BelongsToCurrentThread()) { | 871 if (!io_thread_->BelongsToCurrentThread()) { |
834 io_thread_->DeleteSoon(FROM_HERE, this); | 872 io_thread_->DeleteSoon(FROM_HERE, this); |
835 return; | 873 return; |
836 } | 874 } |
837 delete this; | 875 delete this; |
838 } | 876 } |
839 | 877 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 | 960 |
923 QuotaManagerProxy::QuotaManagerProxy( | 961 QuotaManagerProxy::QuotaManagerProxy( |
924 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 962 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
925 : manager_(manager), io_thread_(io_thread) { | 963 : manager_(manager), io_thread_(io_thread) { |
926 } | 964 } |
927 | 965 |
928 QuotaManagerProxy::~QuotaManagerProxy() { | 966 QuotaManagerProxy::~QuotaManagerProxy() { |
929 } | 967 } |
930 | 968 |
931 } // namespace quota | 969 } // namespace quota |
OLD | NEW |