summaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authornhiroki <nhiroki@chromium.org>2014-11-24 21:40:09 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-25 05:40:42 +0000
commitbd0313bd88f53cd5124c8cb7bb66274febe7d1e5 (patch)
treea20b0d62406e062d7db90a06a917517a671cbf95 /storage
parentccb260bf740edb9d70a5c294fb9824e315f84064 (diff)
downloadchromium_src-bd0313bd88f53cd5124c8cb7bb66274febe7d1e5.zip
chromium_src-bd0313bd88f53cd5124c8cb7bb66274febe7d1e5.tar.gz
chromium_src-bd0313bd88f53cd5124c8cb7bb66274febe7d1e5.tar.bz2
Quota: Clean up CallbackQueue and CallbackQueueMap
To improve readability, this change replaces Tuple with Variadic Templates in CallbackQueue and CallbackQueueMap. BUG=432780 TEST=content_unittests --gtest_filter=Quota* Review URL: https://codereview.chromium.org/718103004 Cr-Commit-Position: refs/heads/master@{#305590}
Diffstat (limited to 'storage')
-rw-r--r--storage/browser/quota/client_usage_tracker.cc2
-rw-r--r--storage/browser/quota/client_usage_tracker.h5
-rw-r--r--storage/browser/quota/quota_callbacks.h58
-rw-r--r--storage/browser/quota/quota_manager.cc7
-rw-r--r--storage/browser/quota/quota_manager.h7
-rw-r--r--storage/browser/quota/usage_tracker.cc6
-rw-r--r--storage/browser/quota/usage_tracker.h6
7 files changed, 40 insertions, 51 deletions
diff --git a/storage/browser/quota/client_usage_tracker.cc b/storage/browser/quota/client_usage_tracker.cc
index 51549a9..968b351 100644
--- a/storage/browser/quota/client_usage_tracker.cc
+++ b/storage/browser/quota/client_usage_tracker.cc
@@ -331,7 +331,7 @@ void ClientUsageTracker::AccumulateOriginUsage(AccumulateInfo* info,
AddCachedHost(host);
host_usage_accumulators_.Run(
- host, MakeTuple(info->limited_usage, info->unlimited_usage));
+ host, info->limited_usage, info->unlimited_usage);
}
void ClientUsageTracker::DidGetHostUsageAfterUpdate(
diff --git a/storage/browser/quota/client_usage_tracker.h b/storage/browser/quota/client_usage_tracker.h
index dec4720..1c07dc8 100644
--- a/storage/browser/quota/client_usage_tracker.h
+++ b/storage/browser/quota/client_usage_tracker.h
@@ -58,8 +58,8 @@ class ClientUsageTracker : public SpecialStoragePolicy::Observer,
void SetUsageCacheEnabled(const GURL& origin, bool enabled);
private:
- typedef CallbackQueueMap<HostUsageAccumulator, std::string,
- Tuple2<int64, int64> > HostUsageAccumulatorMap;
+ typedef CallbackQueueMap<HostUsageAccumulator, std::string, int64, int64>
+ HostUsageAccumulatorMap;
typedef std::set<std::string> HostSet;
typedef std::map<GURL, int64> UsageMap;
@@ -126,7 +126,6 @@ class ClientUsageTracker : public SpecialStoragePolicy::Observer,
OriginSetByHost non_cached_limited_origins_by_host_;
OriginSetByHost non_cached_unlimited_origins_by_host_;
- GlobalUsageCallbackQueue global_usage_callback_;
HostUsageAccumulatorMap host_usage_accumulators_;
scoped_refptr<SpecialStoragePolicy> special_storage_policy_;
diff --git a/storage/browser/quota/quota_callbacks.h b/storage/browser/quota/quota_callbacks.h
index b499922..298f269 100644
--- a/storage/browser/quota/quota_callbacks.h
+++ b/storage/browser/quota/quota_callbacks.h
@@ -7,12 +7,10 @@
#include <map>
#include <set>
-#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
-#include "base/tuple.h"
#include "storage/common/quota/quota_status_code.h"
#include "storage/common/quota/quota_types.h"
@@ -34,14 +32,8 @@ typedef base::Callback<void(const std::set<GURL>& origins,
StorageType type)> GetOriginsCallback;
typedef base::Callback<void(const UsageInfoEntries&)> GetUsageInfoCallback;
-template<typename CallbackType, typename Args>
-void DispatchToCallback(const CallbackType& callback,
- const Args& args) {
- DispatchToMethod(&callback, &CallbackType::Run, args);
-}
-
// Simple template wrapper for a callback queue.
-template <typename CallbackType, typename Args>
+template <typename CallbackType, typename... Args>
class CallbackQueue {
public:
// Returns true if the given |callback| is the first one added to the queue.
@@ -55,35 +47,26 @@ class CallbackQueue {
}
// Runs the callbacks added to the queue and clears the queue.
- void Run(const Args& args) {
- typedef typename std::vector<CallbackType>::iterator iterator;
- for (iterator iter = callbacks_.begin();
- iter != callbacks_.end(); ++iter)
- DispatchToCallback(*iter, args);
- callbacks_.clear();
+ void Run(
+ typename base::internal::CallbackParamTraits<Args>::ForwardType... args) {
+ std::vector<CallbackType> callbacks;
+ callbacks.swap(callbacks_);
+ for (const auto& callback : callbacks)
+ callback.Run(base::internal::CallbackForward(args)...);
+ }
+
+ void Swap(CallbackQueue<CallbackType, Args...>* other) {
+ callbacks_.swap(other->callbacks_);
}
private:
std::vector<CallbackType> callbacks_;
};
-typedef CallbackQueue<GlobalUsageCallback,
- Tuple2<int64, int64> >
- GlobalUsageCallbackQueue;
-typedef CallbackQueue<UsageCallback, Tuple1<int64> >
- UsageCallbackQueue;
-typedef CallbackQueue<AvailableSpaceCallback,
- Tuple2<QuotaStatusCode, int64> >
- AvailableSpaceCallbackQueue;
-typedef CallbackQueue<QuotaCallback,
- Tuple2<QuotaStatusCode, int64> >
- GlobalQuotaCallbackQueue;
-typedef CallbackQueue<base::Closure, Tuple0> ClosureQueue;
-
-template <typename CallbackType, typename Key, typename Args>
+template <typename CallbackType, typename Key, typename... Args>
class CallbackQueueMap {
public:
- typedef CallbackQueue<CallbackType, Args> CallbackQueueType;
+ typedef CallbackQueue<CallbackType, Args...> CallbackQueueType;
typedef std::map<Key, CallbackQueueType> CallbackMap;
typedef typename CallbackMap::iterator iterator;
@@ -106,24 +89,21 @@ class CallbackQueueMap {
// Runs the callbacks added for the given |key| and clears the key
// from the map.
- void Run(const Key& key, const Args& args) {
+ void Run(
+ const Key& key,
+ typename base::internal::CallbackParamTraits<Args>::ForwardType... args) {
if (!this->HasCallbacks(key))
return;
- CallbackQueueType& queue = callback_map_[key];
- queue.Run(args);
+ CallbackQueueType queue;
+ queue.Swap(&callback_map_[key]);
callback_map_.erase(key);
+ queue.Run(base::internal::CallbackForward(args)...);
}
private:
CallbackMap callback_map_;
};
-typedef CallbackQueueMap<UsageCallback, std::string, Tuple1<int64> >
- HostUsageCallbackMap;
-typedef CallbackQueueMap<QuotaCallback, std::string,
- Tuple2<QuotaStatusCode, int64> >
- HostQuotaCallbackMap;
-
} // namespace storage
#endif // STORAGE_QUOTA_QUOTA_TYPES_H_
diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc
index a11ef08..b715f6b 100644
--- a/storage/browser/quota/quota_manager.cc
+++ b/storage/browser/quota/quota_manager.cc
@@ -1531,8 +1531,7 @@ void QuotaManager::DidGetPersistentHostQuota(const std::string& host,
const int64* quota,
bool success) {
DidDatabaseWork(success);
- persistent_host_quota_callbacks_.Run(
- host, MakeTuple(kQuotaStatusOk, *quota));
+ persistent_host_quota_callbacks_.Run(host, kQuotaStatusOk, *quota);
}
void QuotaManager::DidSetPersistentHostQuota(const std::string& host,
@@ -1556,7 +1555,7 @@ void QuotaManager::DidInitialize(int64* temporary_quota_override,
kReportHistogramInterval),
this, &QuotaManager::ReportHistogram);
- db_initialization_callbacks_.Run(MakeTuple());
+ db_initialization_callbacks_.Run();
GetTemporaryGlobalQuota(
base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota,
weak_factory_.GetWeakPtr()));
@@ -1600,7 +1599,7 @@ void QuotaManager::DidInitializeTemporaryOriginsInfo(bool success) {
}
void QuotaManager::DidGetAvailableSpace(int64 space) {
- available_space_callbacks_.Run(MakeTuple(kQuotaStatusOk, space));
+ available_space_callbacks_.Run(kQuotaStatusOk, space);
}
void QuotaManager::DidDatabaseWork(bool success) {
diff --git a/storage/browser/quota/quota_manager.h b/storage/browser/quota/quota_manager.h
index a61332f..07106df 100644
--- a/storage/browser/quota/quota_manager.h
+++ b/storage/browser/quota/quota_manager.h
@@ -298,6 +298,12 @@ class STORAGE_EXPORT QuotaManager
typedef base::Callback<void(const OriginInfoTableEntries&)>
DumpOriginInfoTableCallback;
+ typedef CallbackQueue<base::Closure> ClosureQueue;
+ typedef CallbackQueue<AvailableSpaceCallback, QuotaStatusCode, int64>
+ AvailableSpaceCallbackQueue;
+ typedef CallbackQueueMap<QuotaCallback, std::string, QuotaStatusCode, int64>
+ HostQuotaCallbackMap;
+
struct EvictionContext {
EvictionContext();
virtual ~EvictionContext();
@@ -418,7 +424,6 @@ class STORAGE_EXPORT QuotaManager
ClosureQueue db_initialization_callbacks_;
AvailableSpaceCallbackQueue available_space_callbacks_;
- GlobalQuotaCallbackQueue temporary_global_quota_callbacks_;
HostQuotaCallbackMap persistent_host_quota_callbacks_;
bool temporary_quota_initialized_;
diff --git a/storage/browser/quota/usage_tracker.cc b/storage/browser/quota/usage_tracker.cc
index 510fe86..528725d 100644
--- a/storage/browser/quota/usage_tracker.cc
+++ b/storage/browser/quota/usage_tracker.cc
@@ -168,7 +168,7 @@ void UsageTracker::AccumulateClientGlobalLimitedUsage(AccumulateInfo* info,
// All the clients have returned their usage data. Dispatch the
// pending callbacks.
- global_limited_usage_callbacks_.Run(MakeTuple(info->usage));
+ global_limited_usage_callbacks_.Run(info->usage);
}
void UsageTracker::AccumulateClientGlobalUsage(AccumulateInfo* info,
@@ -192,7 +192,7 @@ void UsageTracker::AccumulateClientGlobalUsage(AccumulateInfo* info,
// All the clients have returned their usage data. Dispatch the
// pending callbacks.
- global_usage_callbacks_.Run(MakeTuple(info->usage, info->unlimited_usage));
+ global_usage_callbacks_.Run(info->usage, info->unlimited_usage);
}
void UsageTracker::AccumulateClientHostUsage(AccumulateInfo* info,
@@ -208,7 +208,7 @@ void UsageTracker::AccumulateClientHostUsage(AccumulateInfo* info,
// All the clients have returned their usage data. Dispatch the
// pending callbacks.
- host_usage_callbacks_.Run(host, MakeTuple(info->usage));
+ host_usage_callbacks_.Run(host, info->usage);
}
} // namespace storage
diff --git a/storage/browser/quota/usage_tracker.h b/storage/browser/quota/usage_tracker.h
index b3f6d7b..224faf8 100644
--- a/storage/browser/quota/usage_tracker.h
+++ b/storage/browser/quota/usage_tracker.h
@@ -66,6 +66,12 @@ class STORAGE_EXPORT UsageTracker : public QuotaTaskObserver {
typedef std::map<QuotaClient::ID, ClientUsageTracker*> ClientTrackerMap;
+ typedef CallbackQueue<UsageCallback, int64> UsageCallbackQueue;
+ typedef CallbackQueue<GlobalUsageCallback, int64, int64>
+ GlobalUsageCallbackQueue;
+ typedef CallbackQueueMap<UsageCallback, std::string, int64>
+ HostUsageCallbackMap;
+
friend class ClientUsageTracker;
void AccumulateClientGlobalLimitedUsage(AccumulateInfo* info,
int64 limited_usage);