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 <deque> | 7 #include <deque> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "webkit/quota/quota_client.h" | |
17 #include "webkit/quota/quota_database.h" | 18 #include "webkit/quota/quota_database.h" |
18 #include "webkit/quota/quota_types.h" | 19 #include "webkit/quota/quota_types.h" |
19 #include "webkit/quota/usage_tracker.h" | 20 #include "webkit/quota/usage_tracker.h" |
20 | 21 |
21 using base::ScopedCallbackFactory; | 22 using base::ScopedCallbackFactory; |
22 | 23 |
23 namespace quota { | 24 namespace quota { |
24 | 25 |
25 namespace { | 26 namespace { |
26 // Returns the initial size of the temporary storage quota. | 27 // Returns the initial size of the temporary storage quota. |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 const FilePath& profile_path, | 509 const FilePath& profile_path, |
509 base::MessageLoopProxy* io_thread, | 510 base::MessageLoopProxy* io_thread, |
510 base::MessageLoopProxy* db_thread) | 511 base::MessageLoopProxy* db_thread) |
511 : is_incognito_(is_incognito), | 512 : is_incognito_(is_incognito), |
512 profile_path_(profile_path), | 513 profile_path_(profile_path), |
513 proxy_(new QuotaManagerProxy( | 514 proxy_(new QuotaManagerProxy( |
514 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), | 515 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), |
515 db_disabled_(false), | 516 db_disabled_(false), |
516 io_thread_(io_thread), | 517 io_thread_(io_thread), |
517 db_thread_(db_thread), | 518 db_thread_(db_thread), |
518 temporary_global_quota_(-1) { | 519 num_deletion_requested_clients_(0), |
520 num_deleted_clients_(0), | |
521 temporary_global_quota_(-1), | |
522 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
519 } | 523 } |
520 | 524 |
521 QuotaManager::~QuotaManager() { | 525 QuotaManager::~QuotaManager() { |
522 DCHECK(io_thread_->BelongsToCurrentThread()); | 526 DCHECK(io_thread_->BelongsToCurrentThread()); |
523 proxy_->manager_ = NULL; | 527 proxy_->manager_ = NULL; |
524 std::for_each(clients_.begin(), clients_.end(), | 528 std::for_each(clients_.begin(), clients_.end(), |
525 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); | 529 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); |
526 if (database_.get()) | 530 if (database_.get()) |
527 db_thread_->DeleteSoon(FROM_HERE, database_.release()); | 531 db_thread_->DeleteSoon(FROM_HERE, database_.release()); |
528 } | 532 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 if (db_disabled_) { | 732 if (db_disabled_) { |
729 callback->Run(GURL()); | 733 callback->Run(GURL()); |
730 delete callback; | 734 delete callback; |
731 return; | 735 return; |
732 } | 736 } |
733 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( | 737 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( |
734 this, database_.get(), db_thread_, type, origins_in_use_, callback)); | 738 this, database_.get(), db_thread_, type, origins_in_use_, callback)); |
735 task->Start(); | 739 task->Start(); |
736 } | 740 } |
737 | 741 |
742 void QuotaManager::OnOriginDataEvicted( | |
743 QuotaStatusCode status) { | |
744 LOG(ERROR) << "QM::OnOriginDataDeleted"; | |
745 DCHECK(io_thread_->BelongsToCurrentThread()); | |
746 | |
747 if (status != kQuotaStatusOk) { | |
748 // TODO(dmikurube): Handle error. | |
749 } | |
750 | |
751 ++num_deleted_clients_; | |
752 DCHECK(num_deleted_clients_ <= num_deletion_requested_clients_); | |
753 if (num_deleted_clients_ == num_deletion_requested_clients_) { | |
754 num_deletion_requested_clients_ = 0; | |
755 num_deleted_clients_ = 0; | |
756 | |
757 // TODO(dmikurube): Get usage, quota and physical space and then callback. | |
758 evict_origin_data_callback_->Run(kQuotaStatusOk); | |
759 delete evict_origin_data_callback_; | |
michaeln
2011/05/17 19:30:01
is the callback leaked if the class is destructed
Dai Mikurube (NOT FULLTIME)
2011/05/18 04:34:48
Done.
| |
760 } | |
761 } | |
762 | |
738 void QuotaManager::EvictOriginData( | 763 void QuotaManager::EvictOriginData( |
739 const GURL& origin, | 764 const GURL& origin, |
740 StorageType type, | 765 StorageType type, |
741 EvictOriginDataCallback* callback) { | 766 EvictOriginDataCallback* callback) { |
742 // TODO(dmikurube): Implement it. | 767 LOG(ERROR) << "QM::DeleteOriginData"; |
michaeln
2011/05/17 19:30:01
Please fixup the LOG(ERROR) usage throughout. It's
Dai Mikurube (NOT FULLTIME)
2011/05/18 04:34:48
Yeah, I'll remove them finally for other changes.
| |
768 DCHECK(io_thread_->BelongsToCurrentThread()); | |
michaeln
2011/05/17 19:30:01
Since LazyInitialize has this DCHECK, consider rem
Dai Mikurube (NOT FULLTIME)
2011/05/18 04:34:48
LazyInitialize here was replaced with DCHECK(datab
| |
769 LazyInitialize(); | |
770 | |
771 int num_clients = clients_.size(); | |
772 | |
773 if (origin.is_empty() || num_clients == 0 || num_deleted_clients_ > 0) { | |
774 callback->Run(kQuotaStatusOk); | |
775 delete callback; | |
776 return; | |
777 } | |
778 | |
779 num_deletion_requested_clients_ = num_clients; | |
780 num_deleted_clients_ = 0; | |
781 | |
782 for (QuotaClientList::iterator p = clients_.begin(); | |
783 p != clients_.end(); | |
784 ++p) { | |
785 evict_origin_data_callback_ = callback; | |
michaeln
2011/05/17 19:30:01
maybe move this assignment up out of the loop
Dai Mikurube (NOT FULLTIME)
2011/05/18 04:34:48
Done.
| |
786 (*p)->DeleteOriginData(origin, kStorageTypeTemporary, callback_factory_. | |
787 NewCallback(&QuotaManager::OnOriginDataEvicted)); | |
788 } | |
743 } | 789 } |
744 | 790 |
745 void QuotaManager::GetUsageAndQuotaForEviction( | 791 void QuotaManager::GetUsageAndQuotaForEviction( |
746 GetUsageAndQuotaForEvictionCallback* callback) { | 792 GetUsageAndQuotaForEvictionCallback* callback) { |
747 // TODO(dmikurube): Implement it. | 793 // TODO(dmikurube): Implement it. |
748 } | 794 } |
749 | 795 |
750 void QuotaManager::DeleteOnCorrectThread() const { | 796 void QuotaManager::DeleteOnCorrectThread() const { |
751 if (!io_thread_->BelongsToCurrentThread()) { | 797 if (!io_thread_->BelongsToCurrentThread()) { |
752 io_thread_->DeleteSoon(FROM_HERE, this); | 798 io_thread_->DeleteSoon(FROM_HERE, this); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 | 886 |
841 QuotaManagerProxy::QuotaManagerProxy( | 887 QuotaManagerProxy::QuotaManagerProxy( |
842 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 888 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
843 : manager_(manager), io_thread_(io_thread) { | 889 : manager_(manager), io_thread_(io_thread) { |
844 } | 890 } |
845 | 891 |
846 QuotaManagerProxy::~QuotaManagerProxy() { | 892 QuotaManagerProxy::~QuotaManagerProxy() { |
847 } | 893 } |
848 | 894 |
849 } // namespace quota | 895 } // namespace quota |
OLD | NEW |