Commit c5c90f88 authored by Ben Kelly's avatar Ben Kelly Committed by Commit Bot

CacheStorage: Make CacheStorageContext API usable from UI thread.

In order to support moving CacheStorage off the IO thread and on to
a separate SequencedTaskRunner, we are encapsulating the threading
requirements.  This CL does this by removing the requirement that
external clients of CacheStorageContext must be on the IO thread.
Instead the API can be accessed directly on the UI thread and
CacheStorageContextImpl will handle executing the code on the correct
sequence.

Bug: 960012
Change-Id: I7d576a7deb484113cff0e9454b038f7b87c5e503
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1625971Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662961}
parent d0e97e23
......@@ -25,7 +25,7 @@ namespace {
void GetAllOriginsInfoForCacheStorageCallback(
BrowsingDataCacheStorageHelper::FetchCallback callback,
const std::vector<StorageUsageInfo>& origins) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null());
std::list<content::StorageUsageInfo> result;
......@@ -35,8 +35,7 @@ void GetAllOriginsInfoForCacheStorageCallback(
result.push_back(origin);
}
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
base::BindOnce(std::move(callback), result));
std::move(callback).Run(result);
}
} // namespace
......@@ -52,33 +51,12 @@ BrowsingDataCacheStorageHelper::~BrowsingDataCacheStorageHelper() {}
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, std::move(callback)));
}
void BrowsingDataCacheStorageHelper::DeleteCacheStorage(const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(
&BrowsingDataCacheStorageHelper::DeleteCacheStorageOnIOThread, this,
origin));
}
void BrowsingDataCacheStorageHelper::FetchCacheStorageUsageInfoOnIOThread(
FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!callback.is_null());
cache_storage_context_->GetAllOriginsInfo(base::BindOnce(
&GetAllOriginsInfoForCacheStorageCallback, std::move(callback)));
}
void BrowsingDataCacheStorageHelper::DeleteCacheStorageOnIOThread(
const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
void BrowsingDataCacheStorageHelper::DeleteCacheStorage(const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
cache_storage_context_->DeleteForOrigin(origin);
}
......
......@@ -54,12 +54,6 @@ class BrowsingDataCacheStorageHelper
private:
friend class base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper>;
// Deletes Cache Storages for an origin the IO thread.
void DeleteCacheStorageOnIOThread(const GURL& origin);
// Enumerates all Cache Storage instances on the IO thread.
void FetchCacheStorageUsageInfoOnIOThread(FetchCallback callback);
DISALLOW_COPY_AND_ASSIGN(BrowsingDataCacheStorageHelper);
};
......
......@@ -93,24 +93,45 @@ void CacheStorageContextImpl::SetBlobParametersForCache(
void CacheStorageContextImpl::GetAllOriginsInfo(
CacheStorageContext::GetUsageInfoCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// Can be called on any sequence.
if (!cache_manager_) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(std::move(callback), std::vector<StorageUsageInfo>()));
return;
}
callback = base::BindOnce(
[](scoped_refptr<base::SequencedTaskRunner> reply_task_runner,
GetUsageInfoCallback inner,
const std::vector<StorageUsageInfo>& entries) {
reply_task_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(inner), entries));
},
base::SequencedTaskRunnerHandle::Get(), std::move(callback));
cache_manager_->GetAllOriginsUsage(CacheStorageOwner::kCacheAPI,
std::move(callback));
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
[](scoped_refptr<CacheStorageContextImpl> context,
GetUsageInfoCallback callback) {
if (!context->cache_manager()) {
std::move(callback).Run(std::vector<StorageUsageInfo>());
return;
}
context->cache_manager()->GetAllOriginsUsage(
CacheStorageOwner::kCacheAPI, std::move(callback));
},
base::RetainedRef(this), std::move(callback)));
}
void CacheStorageContextImpl::DeleteForOrigin(const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (cache_manager_)
cache_manager_->DeleteOriginData(url::Origin::Create(origin),
CacheStorageOwner::kCacheAPI);
// Can be called on any sequence.
task_runner_->PostTask(FROM_HERE,
base::BindOnce(
[](scoped_refptr<CacheStorageContextImpl> context,
const GURL& origin) {
if (!context->cache_manager())
return;
context->cache_manager()->DeleteOriginData(
url::Origin::Create(origin),
CacheStorageOwner::kCacheAPI);
},
base::RetainedRef(this), origin));
}
void CacheStorageContextImpl::AddObserver(
......
......@@ -24,7 +24,7 @@ class CacheStorageContext
base::OnceCallback<void(const std::vector<StorageUsageInfo>& usage_info)>;
// Methods used in response to browsing data and quota manager requests.
// Must be called on the IO thread.
// May be called on any sequence.
virtual void GetAllOriginsInfo(GetUsageInfoCallback callback) = 0;
virtual void DeleteForOrigin(const GURL& origin_url) = 0;
......
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