Commit 40666cfd authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

Prepare BrowsingDataServiceWorkerHelper for UI thread core.

The thread ServiceWorkerContextCore lives on (the "core thread") will
move from the IO thread to the UI thread when ServiceWorkerOnUI is
enabled.

This makes BrowsingDataServiceWorkerHelper aware of the core thread
rather than assuming the IO thread. This enables unit_test
"CannedBrowsingDataServiceWorkerHelperTest.*" to pass.

Bug: 824858
Change-Id: I6c7e7db1bb0c5f7b9691fef51947304280ad3143
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1795528Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695141}
parent 332f6d3f
...@@ -27,7 +27,7 @@ namespace { ...@@ -27,7 +27,7 @@ namespace {
void GetAllOriginsInfoForServiceWorkerCallback( void GetAllOriginsInfoForServiceWorkerCallback(
BrowsingDataServiceWorkerHelper::FetchCallback callback, BrowsingDataServiceWorkerHelper::FetchCallback callback,
const std::vector<StorageUsageInfo>& origins) { const std::vector<StorageUsageInfo>& origins) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
std::list<StorageUsageInfo> result; std::list<StorageUsageInfo> result;
...@@ -37,8 +37,8 @@ void GetAllOriginsInfoForServiceWorkerCallback( ...@@ -37,8 +37,8 @@ void GetAllOriginsInfoForServiceWorkerCallback(
result.push_back(origin); result.push_back(origin);
} }
base::PostTask(FROM_HERE, {BrowserThread::UI}, content::RunOrPostTaskOnThread(FROM_HERE, BrowserThread::UI,
base::BindOnce(std::move(callback), result)); base::BindOnce(std::move(callback), result));
} }
} // namespace } // namespace
...@@ -54,33 +54,34 @@ BrowsingDataServiceWorkerHelper::~BrowsingDataServiceWorkerHelper() {} ...@@ -54,33 +54,34 @@ BrowsingDataServiceWorkerHelper::~BrowsingDataServiceWorkerHelper() {}
void BrowsingDataServiceWorkerHelper::StartFetching(FetchCallback callback) { void BrowsingDataServiceWorkerHelper::StartFetching(FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
base::PostTask(FROM_HERE, {BrowserThread::IO}, content::RunOrPostTaskOnThread(
base::BindOnce(&BrowsingDataServiceWorkerHelper:: FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
FetchServiceWorkerUsageInfoOnIOThread, base::BindOnce(&BrowsingDataServiceWorkerHelper::
this, std::move(callback))); FetchServiceWorkerUsageInfoOnCoreThread,
this, std::move(callback)));
} }
void BrowsingDataServiceWorkerHelper::DeleteServiceWorkers(const GURL& origin) { void BrowsingDataServiceWorkerHelper::DeleteServiceWorkers(const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::PostTask( content::RunOrPostTaskOnThread(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce( base::BindOnce(
&BrowsingDataServiceWorkerHelper::DeleteServiceWorkersOnIOThread, &BrowsingDataServiceWorkerHelper::DeleteServiceWorkersOnCoreThread,
this, origin)); this, origin));
} }
void BrowsingDataServiceWorkerHelper::FetchServiceWorkerUsageInfoOnIOThread( void BrowsingDataServiceWorkerHelper::FetchServiceWorkerUsageInfoOnCoreThread(
FetchCallback callback) { FetchCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
service_worker_context_->GetAllOriginsInfo(base::BindOnce( service_worker_context_->GetAllOriginsInfo(base::BindOnce(
&GetAllOriginsInfoForServiceWorkerCallback, std::move(callback))); &GetAllOriginsInfoForServiceWorkerCallback, std::move(callback)));
} }
void BrowsingDataServiceWorkerHelper::DeleteServiceWorkersOnIOThread( void BrowsingDataServiceWorkerHelper::DeleteServiceWorkersOnCoreThread(
const GURL& origin) { const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
service_worker_context_->DeleteForOrigin(origin, base::DoNothing()); service_worker_context_->DeleteForOrigin(origin, base::DoNothing());
} }
......
...@@ -54,11 +54,11 @@ class BrowsingDataServiceWorkerHelper ...@@ -54,11 +54,11 @@ class BrowsingDataServiceWorkerHelper
private: private:
friend class base::RefCountedThreadSafe<BrowsingDataServiceWorkerHelper>; friend class base::RefCountedThreadSafe<BrowsingDataServiceWorkerHelper>;
// Enumerates all Service Worker instances on the IO thread. // Enumerates all Service Worker instances on the service worker core thread.
void FetchServiceWorkerUsageInfoOnIOThread(FetchCallback callback); void FetchServiceWorkerUsageInfoOnCoreThread(FetchCallback callback);
// Deletes Service Workers for an origin the IO thread. // Deletes Service Workers for an origin on the service worker core thread.
void DeleteServiceWorkersOnIOThread(const GURL& origin); void DeleteServiceWorkersOnCoreThread(const GURL& origin);
DISALLOW_COPY_AND_ASSIGN(BrowsingDataServiceWorkerHelper); DISALLOW_COPY_AND_ASSIGN(BrowsingDataServiceWorkerHelper);
}; };
......
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