Commit 82ace770 authored by Joshua Bell's avatar Joshua Bell Committed by Commit Bot

Cache Storage: BindOnce-ify CacheManager::GetAllOriginsUsage

Switch a few Cache Storage-related code paths from generic
Bind/Callback to BindOnce/OnceCallback.

Bug: 714018
Change-Id: I245cb56090228865cb0f4957caf8f704568eac39
Reviewed-on: https://chromium-review.googlesource.com/c/1289433Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602357}
parent c294aaed
......@@ -21,7 +21,7 @@ using content::CacheStorageUsageInfo;
namespace {
void GetAllOriginsInfoForCacheStorageCallback(
const BrowsingDataCacheStorageHelper::FetchCallback& callback,
BrowsingDataCacheStorageHelper::FetchCallback callback,
const std::vector<CacheStorageUsageInfo>& origins) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!callback.is_null());
......@@ -34,7 +34,7 @@ void GetAllOriginsInfoForCacheStorageCallback(
}
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
base::BindOnce(callback, result));
base::BindOnce(std::move(callback), result));
}
} // namespace
......@@ -47,15 +47,14 @@ BrowsingDataCacheStorageHelper::BrowsingDataCacheStorageHelper(
BrowsingDataCacheStorageHelper::~BrowsingDataCacheStorageHelper() {}
void BrowsingDataCacheStorageHelper::StartFetching(
const FetchCallback& callback) {
void BrowsingDataCacheStorageHelper::StartFetching(FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null());
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(
&BrowsingDataCacheStorageHelper::FetchCacheStorageUsageInfoOnIOThread,
this, callback));
this, std::move(callback)));
}
void BrowsingDataCacheStorageHelper::DeleteCacheStorage(const GURL& origin) {
......@@ -68,11 +67,11 @@ void BrowsingDataCacheStorageHelper::DeleteCacheStorage(const GURL& origin) {
}
void BrowsingDataCacheStorageHelper::FetchCacheStorageUsageInfoOnIOThread(
const FetchCallback& callback) {
FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!callback.is_null());
cache_storage_context_->GetAllOriginsInfo(
base::Bind(&GetAllOriginsInfoForCacheStorageCallback, callback));
cache_storage_context_->GetAllOriginsInfo(base::BindOnce(
&GetAllOriginsInfoForCacheStorageCallback, std::move(callback)));
}
void BrowsingDataCacheStorageHelper::DeleteCacheStorageOnIOThread(
......@@ -130,7 +129,7 @@ CannedBrowsingDataCacheStorageHelper::GetCacheStorageUsageInfo() const {
}
void CannedBrowsingDataCacheStorageHelper::StartFetching(
const FetchCallback& callback) {
FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null());
......@@ -144,7 +143,7 @@ void CannedBrowsingDataCacheStorageHelper::StartFetching(
}
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
base::BindOnce(callback, result));
base::BindOnce(std::move(callback), result));
}
void CannedBrowsingDataCacheStorageHelper::DeleteCacheStorage(
......
......@@ -27,8 +27,8 @@
class BrowsingDataCacheStorageHelper
: public base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper> {
public:
using FetchCallback =
base::Callback<void(const std::list<content::CacheStorageUsageInfo>&)>;
using FetchCallback = base::OnceCallback<void(
const std::list<content::CacheStorageUsageInfo>&)>;
// Create a BrowsingDataCacheStorageHelper instance for the Cache Storage
// stored in |context|'s associated profile's user data directory.
......@@ -37,7 +37,7 @@ class BrowsingDataCacheStorageHelper
// Starts the fetching process, which will notify its completion via
// |callback|. This must be called only in the UI thread.
virtual void StartFetching(const FetchCallback& callback);
virtual void StartFetching(FetchCallback callback);
// Requests the Cache Storage data for an origin be deleted.
virtual void DeleteCacheStorage(const GURL& origin);
......@@ -54,7 +54,7 @@ class BrowsingDataCacheStorageHelper
void DeleteCacheStorageOnIOThread(const GURL& origin);
// Enumerates all Cache Storage instances on the IO thread.
void FetchCacheStorageUsageInfoOnIOThread(const FetchCallback& callback);
void FetchCacheStorageUsageInfoOnIOThread(FetchCallback callback);
DISALLOW_COPY_AND_ASSIGN(BrowsingDataCacheStorageHelper);
};
......@@ -101,9 +101,7 @@ class CannedBrowsingDataCacheStorageHelper
GetCacheStorageUsageInfo() const;
// BrowsingDataCacheStorageHelper methods.
void StartFetching(const base::Callback<
void(const std::list<content::CacheStorageUsageInfo>&)>&
callback) override;
void StartFetching(FetchCallback callback) override;
void DeleteCacheStorage(const GURL& origin) override;
private:
......
......@@ -19,16 +19,16 @@ MockBrowsingDataCacheStorageHelper::MockBrowsingDataCacheStorageHelper(
MockBrowsingDataCacheStorageHelper::~MockBrowsingDataCacheStorageHelper() {}
void MockBrowsingDataCacheStorageHelper::StartFetching(
const FetchCallback& callback) {
void MockBrowsingDataCacheStorageHelper::StartFetching(FetchCallback callback) {
ASSERT_FALSE(callback.is_null());
ASSERT_TRUE(callback_.is_null());
callback_ = callback;
callback_ = std::move(callback);
fetched_ = true;
}
void MockBrowsingDataCacheStorageHelper::DeleteCacheStorage(
const GURL& origin) {
ASSERT_FALSE(callback_.is_null());
ASSERT_TRUE(fetched_);
ASSERT_TRUE(origins_.find(origin) != origins_.end());
origins_[origin] = false;
}
......@@ -45,7 +45,8 @@ void MockBrowsingDataCacheStorageHelper::AddCacheStorageSamples() {
}
void MockBrowsingDataCacheStorageHelper::Notify() {
callback_.Run(response_);
ASSERT_FALSE(callback_.is_null());
std::move(callback_).Run(response_);
}
void MockBrowsingDataCacheStorageHelper::Reset() {
......
......@@ -36,15 +36,14 @@ class MockBrowsingDataCacheStorageHelper
bool AllDeleted();
// BrowsingDataCacheStorageHelper.
void StartFetching(const base::Callback<
void(const std::list<content::CacheStorageUsageInfo>&)>&
callback) override;
void StartFetching(FetchCallback callback) override;
void DeleteCacheStorage(const GURL& origin) override;
private:
~MockBrowsingDataCacheStorageHelper() override;
FetchCallback callback_;
bool fetched_ = false;
std::map<GURL, bool> origins_;
std::list<content::CacheStorageUsageInfo> response_;
......
......@@ -82,17 +82,19 @@ void CacheStorageContextImpl::SetBlobParametersForCache(
}
void CacheStorageContextImpl::GetAllOriginsInfo(
const CacheStorageContext::GetUsageInfoCallback& callback) {
CacheStorageContext::GetUsageInfoCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!cache_manager_) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(callback, std::vector<CacheStorageUsageInfo>()));
base::BindOnce(std::move(callback),
std::vector<CacheStorageUsageInfo>()));
return;
}
cache_manager_->GetAllOriginsUsage(CacheStorageOwner::kCacheAPI, callback);
cache_manager_->GetAllOriginsUsage(CacheStorageOwner::kCacheAPI,
std::move(callback));
}
void CacheStorageContextImpl::DeleteForOrigin(const GURL& origin) {
......
......@@ -77,7 +77,7 @@ class CONTENT_EXPORT CacheStorageContextImpl : public CacheStorageContext {
ChromeBlobStorageContext* blob_storage_context);
// CacheStorageContext
void GetAllOriginsInfo(const GetUsageInfoCallback& callback) override;
void GetAllOriginsInfo(GetUsageInfoCallback callback) override;
void DeleteForOrigin(const GURL& origin) override;
// Only callable on the IO thread.
......
......@@ -17,12 +17,12 @@ namespace content {
class CacheStorageContext
: public base::RefCountedThreadSafe<CacheStorageContext> {
public:
using GetUsageInfoCallback = base::Callback<void(
using GetUsageInfoCallback = base::OnceCallback<void(
const std::vector<CacheStorageUsageInfo>& usage_info)>;
// Methods used in response to browsing data and quota manager requests.
// Must be called on the IO thread.
virtual void GetAllOriginsInfo(const GetUsageInfoCallback& callback) = 0;
virtual void GetAllOriginsInfo(GetUsageInfoCallback callback) = 0;
virtual void DeleteForOrigin(const GURL& origin_url) = 0;
protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment