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 |
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" | |
kinuko
2011/05/18 05:48:35
nit: this is already included in quota_manager.h
Dai Mikurube (NOT FULLTIME)
2011/05/18 06:04:57
Done.
| |
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 Loading... | |
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()); |
532 proxy_->manager_ = NULL; | 536 proxy_->manager_ = NULL; |
533 std::for_each(clients_.begin(), clients_.end(), | 537 std::for_each(clients_.begin(), clients_.end(), |
534 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); | 538 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); |
535 if (database_.get()) | 539 if (database_.get()) |
536 db_thread_->DeleteSoon(FROM_HERE, database_.release()); | 540 db_thread_->DeleteSoon(FROM_HERE, database_.release()); |
537 } | 541 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 if (db_disabled_) { | 770 if (db_disabled_) { |
767 callback->Run(GURL()); | 771 callback->Run(GURL()); |
768 delete callback; | 772 delete callback; |
769 return; | 773 return; |
770 } | 774 } |
771 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( | 775 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( |
772 this, database_.get(), db_thread_, type, origins_in_use_, callback)); | 776 this, database_.get(), db_thread_, type, origins_in_use_, callback)); |
773 task->Start(); | 777 task->Start(); |
774 } | 778 } |
775 | 779 |
780 void QuotaManager::OnOriginDataEvicted( | |
781 QuotaStatusCode status) { | |
782 DCHECK(io_thread_->BelongsToCurrentThread()); | |
783 | |
784 if (status != kQuotaStatusOk) { | |
785 // TODO(dmikurube): Handle error. | |
786 } | |
787 | |
788 ++num_evicted_clients_; | |
789 DCHECK(num_evicted_clients_ <= num_eviction_requested_clients_); | |
790 if (num_evicted_clients_ == num_eviction_requested_clients_) { | |
791 num_eviction_requested_clients_ = 0; | |
792 num_evicted_clients_ = 0; | |
793 | |
kinuko
2011/05/18 05:48:35
Here can we call DeleteOriginFromDatabase (if ther
Dai Mikurube (NOT FULLTIME)
2011/05/18 06:04:57
How about add it later? (Since it looks like not
| |
794 evict_origin_data_callback_->Run(kQuotaStatusOk); | |
795 evict_origin_data_callback_.reset(NULL); | |
kinuko
2011/05/18 05:48:35
reset() will do (no need to specify NULL)
Dai Mikurube (NOT FULLTIME)
2011/05/18 06:04:57
Done.
| |
796 } | |
797 } | |
798 | |
776 void QuotaManager::EvictOriginData( | 799 void QuotaManager::EvictOriginData( |
777 const GURL& origin, | 800 const GURL& origin, |
778 StorageType type, | 801 StorageType type, |
779 EvictOriginDataCallback* callback) { | 802 EvictOriginDataCallback* callback) { |
780 // TODO(dmikurube): Implement it. | 803 DCHECK(io_thread_->BelongsToCurrentThread()); |
804 DCHECK(database_.get()); | |
805 DCHECK(num_eviction_requested_clients_ == 0); | |
806 | |
kinuko
2011/05/18 05:48:35
DCHECK(type == kStorageTypeTemporary) ?
Dai Mikurube (NOT FULLTIME)
2011/05/18 06:04:57
Done.
| |
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, kStorageTypeTemporary, callback_factory_. | |
kinuko
2011/05/18 05:48:35
s/kStorageTypeTemporary/type/ ?
Dai Mikurube (NOT FULLTIME)
2011/05/18 06:04:57
Done.
| |
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 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 |