diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 10:08:15 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 10:08:15 +0000 |
commit | ef88ff7ec29aa48bd7529f4cc4e9c9ed87739539 (patch) | |
tree | 491ebe7a5625025e4efa6feffbd33a3028fbde7d /webkit/quota | |
parent | 148e5cbc8ef64ea0f24d7afa6198930b1934cbb9 (diff) | |
download | chromium_src-ef88ff7ec29aa48bd7529f4cc4e9c9ed87739539.zip chromium_src-ef88ff7ec29aa48bd7529f4cc4e9c9ed87739539.tar.gz chromium_src-ef88ff7ec29aa48bd7529f4cc4e9c9ed87739539.tar.bz2 |
Quota code cleanup
* Replace foo_usage_tracker_ with GetUsageTracker(type) in quota_manager.cc
* Killing unused template types in quota_types.h
* Adding parameter names in Callback typedefs in quota_types.h
BUG=none
TEST=green bots
Review URL: https://chromiumcodereview.appspot.com/10882009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153182 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/quota')
-rw-r--r-- | webkit/quota/quota_manager.cc | 31 | ||||
-rw-r--r-- | webkit/quota/quota_types.h | 79 |
2 files changed, 28 insertions, 82 deletions
diff --git a/webkit/quota/quota_manager.cc b/webkit/quota/quota_manager.cc index 0028cd3..9917846 100644 --- a/webkit/quota/quota_manager.cc +++ b/webkit/quota/quota_manager.cc @@ -126,6 +126,8 @@ class QuotaManager::UsageAndQuotaDispatcherTask : public QuotaTask { void DidGetHostUsage(const std::string& host, StorageType type, int64 usage) { DCHECK_EQ(this->host(), host); DCHECK_EQ(this->type(), type); + if (quota_status_ == kQuotaStatusUnknown) + quota_status_ = kQuotaStatusOk; host_usage_ = usage; CheckCompleted(); } @@ -368,9 +370,9 @@ class QuotaManager::UsageAndQuotaDispatcherTaskForTemporary protected: virtual void RunBody() OVERRIDE { - manager()->temporary_usage_tracker_->GetGlobalUsage( + manager()->GetUsageTracker(type())->GetGlobalUsage( NewWaitableGlobalUsageCallback()); - manager()->temporary_usage_tracker_->GetHostUsage( + manager()->GetUsageTracker(type())->GetHostUsage( host(), NewWaitableHostUsageCallback()); manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); } @@ -402,7 +404,7 @@ class QuotaManager::UsageAndQuotaDispatcherTaskForPersistent protected: virtual void RunBody() OVERRIDE { - manager()->persistent_usage_tracker_->GetHostUsage( + manager()->GetUsageTracker(type())->GetHostUsage( host(), NewWaitableHostUsageCallback()); manager()->GetPersistentHostQuota( host(), NewWaitableHostQuotaCallback()); @@ -424,7 +426,7 @@ class QuotaManager::UsageAndQuotaDispatcherTaskForTemporaryGlobal protected: virtual void RunBody() OVERRIDE { - manager()->temporary_usage_tracker_->GetGlobalUsage( + manager()->GetUsageTracker(type())->GetGlobalUsage( NewWaitableGlobalUsageCallback()); manager()->GetAvailableSpace(NewWaitableAvailableSpaceCallback()); } @@ -1432,17 +1434,16 @@ void QuotaManager::DeleteHostData(const std::string& host, } bool QuotaManager::ResetUsageTracker(StorageType type) { + DCHECK(GetUsageTracker(type)); + if (GetUsageTracker(type)->IsWorking()) + return false; switch (type) { case kStorageTypeTemporary: - if (temporary_usage_tracker_->IsWorking()) - return false; temporary_usage_tracker_.reset( new UsageTracker(clients_, kStorageTypeTemporary, special_storage_policy_)); return true; case kStorageTypePersistent: - if (persistent_usage_tracker_->IsWorking()) - return false; persistent_usage_tracker_.reset( new UsageTracker(clients_, kStorageTypePersistent, special_storage_policy_)); @@ -1469,18 +1470,8 @@ void QuotaManager::GetCachedOrigins( StorageType type, std::set<GURL>* origins) { DCHECK(origins); LazyInitialize(); - switch (type) { - case kStorageTypeTemporary: - DCHECK(temporary_usage_tracker_.get()); - temporary_usage_tracker_->GetCachedOrigins(origins); - return; - case kStorageTypePersistent: - DCHECK(persistent_usage_tracker_.get()); - persistent_usage_tracker_->GetCachedOrigins(origins); - return; - default: - NOTREACHED(); - } + DCHECK(GetUsageTracker(type)); + GetUsageTracker(type)->GetCachedOrigins(origins); } void QuotaManager::NotifyStorageAccessedInternal( diff --git a/webkit/quota/quota_types.h b/webkit/quota/quota_types.h index f93d665..a744b26 100644 --- a/webkit/quota/quota_types.h +++ b/webkit/quota/quota_types.h @@ -39,20 +39,25 @@ struct UsageInfo; typedef std::vector<UsageInfo> UsageInfoEntries; // Common callback types that are used throughout in the quota module. -typedef base::Callback<void(StorageType, int64)> UsageCallback; -typedef base::Callback<void(StorageType, int64, int64)> GlobalUsageCallback; -typedef base::Callback<void(QuotaStatusCode, StorageType, int64)> - QuotaCallback; -typedef base::Callback<void(const std::string&, StorageType, int64)> - HostUsageCallback; -typedef base::Callback<void(QuotaStatusCode, - const std::string&, - StorageType, - int64)> HostQuotaCallback; +typedef base::Callback<void(StorageType status, + int64 usage, + int64 unlimited_usage)> GlobalUsageCallback; +typedef base::Callback<void(QuotaStatusCode status, + StorageType type, + int64 quota)> QuotaCallback; +// TODO(kinuko,nhiroki): HostUsageCallback could be probably replaced with +// simple Callback<void(int64)> callback by binding host and type with Bind. +typedef base::Callback<void(const std::string& host, + StorageType type, + int64 host_usage)> HostUsageCallback; +typedef base::Callback<void(QuotaStatusCode status, + const std::string& host, + StorageType type, + int64 quota)> HostQuotaCallback; typedef base::Callback<void(QuotaStatusCode, int64)> AvailableSpaceCallback; typedef base::Callback<void(QuotaStatusCode)> StatusCallback; -typedef base::Callback<void(const std::set<GURL>&, StorageType)> - GetOriginsCallback; +typedef base::Callback<void(const std::set<GURL>& origins, + StorageType type)> GetOriginsCallback; typedef base::Callback<void(const UsageInfoEntries&)> GetUsageInfoCallback; // Simple template wrapper for a callback queue. @@ -121,28 +126,8 @@ class CallbackQueue3 : public CallbackQueueBase<CallbackType3> { } }; -template <typename CallbackType4, - typename A1, typename A2, typename A3, typename A4> -class CallbackQueue4 : public CallbackQueueBase<CallbackType4> { - public: - typedef typename CallbackQueueBase<CallbackType4>::Queue Queue; - // Runs the callbacks added to the queue and clears the queue. - void Run(A1 arg1, A2 arg2, A3 arg3, A4 arg4) { - for (typename Queue::iterator iter = this->callbacks_.begin(); - iter != this->callbacks_.end(); ++iter) { - iter->Run(arg1, arg2, arg3, arg4); - } - this->callbacks_.clear(); - } -}; - -typedef CallbackQueue2<UsageCallback, - StorageType, int64> UsageCallbackQueue; typedef CallbackQueue3<GlobalUsageCallback, StorageType, int64, int64> GlobalUsageCallbackQueue; -typedef CallbackQueue3<QuotaCallback, - QuotaStatusCode, - StorageType, int64> QuotaCallbackQueue; template <typename CallbackType, typename CallbackQueueType, typename KEY> class CallbackQueueMapBase { @@ -242,39 +227,9 @@ class CallbackQueueMap3 } }; -template <typename CallbackType4, typename KEY, - typename ARG1, typename ARG2, typename ARG3, typename ARG4> -class CallbackQueueMap4 - : public CallbackQueueMapBase<CallbackType4, - CallbackQueue4<CallbackType4, - ARG1, ARG2, ARG3, ARG4>, - KEY> { - public: - typedef typename CallbackQueueMapBase< - CallbackType4, - CallbackQueue4<CallbackType4, ARG1, ARG2, ARG3, ARG4>, - KEY>::iterator iterator; - typedef CallbackQueue4<CallbackType4, ARG1, ARG2, ARG3, ARG4> Queue; - - // Runs the callbacks added for the given |key| and clears the key - // from the map. - void Run(const KEY& key, ARG1 arg1, ARG2 arg2, ARG3 arg3, ARG4 arg4) { - if (!this->HasCallbacks(key)) - return; - Queue& queue = this->callback_map_[key]; - queue.Run(arg1, arg2, arg3, arg4); - this->callback_map_.erase(key); - } -}; - -typedef CallbackQueueMap1<UsageCallback, GURL, int64> OriginUsageCallbackMap; typedef CallbackQueueMap3<HostUsageCallback, std::string, const std::string&, StorageType, int64> HostUsageCallbackMap; -typedef CallbackQueueMap4<HostQuotaCallback, std::string, - QuotaStatusCode, - const std::string&, - StorageType, int64> HostQuotaCallbackMap; } // namespace quota |