Commit b9e16d2b authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

devtools: Prepare for service worker UI thread core.

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

This CL makes DevTools aware of the core thread instead of assuming the IO
thread. This makes https/tests/devtools web_tests pass when the feature is
enabled.

Bug: 824858
Change-Id: I20e38f50998f4b0cd9d8b8cc43526665d92dbf94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775655
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691689}
parent de38afe4
......@@ -218,7 +218,7 @@ void DevToolsBackgroundServicesContextImpl::ClearLoggedBackgroundServiceEvents(
void DevToolsBackgroundServicesContextImpl::
ClearLoggedBackgroundServiceEventsOnCoreThread(
devtools::proto::BackgroundService service) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
service_worker_context_->ClearUserDataForAllRegistrationsByKeyPrefix(
CreateEntryKeyPrefix(service), base::BindOnce(&DidClearServiceEvents));
......
......@@ -28,6 +28,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "third_party/blink/public/mojom/push_messaging/push_messaging_status.mojom.h"
......@@ -78,22 +79,23 @@ const std::string GetVersionStatusString(
return std::string();
}
void StopServiceWorkerOnIO(scoped_refptr<ServiceWorkerContextWrapper> context,
int64_t version_id) {
void StopServiceWorkerOnCoreThread(
scoped_refptr<ServiceWorkerContextWrapper> context,
int64_t version_id) {
if (content::ServiceWorkerVersion* version =
context->GetLiveVersion(version_id)) {
version->StopWorker(base::DoNothing());
}
}
void GetDevToolsRouteInfoOnIO(
void GetDevToolsRouteInfoOnCoreThread(
scoped_refptr<ServiceWorkerContextWrapper> context,
int64_t version_id,
const base::Callback<void(int, int)>& callback) {
if (content::ServiceWorkerVersion* version =
context->GetLiveVersion(version_id)) {
base::PostTask(
FROM_HERE, {BrowserThread::UI},
RunOrPostTaskOnThread(
FROM_HERE, BrowserThread::UI,
base::BindOnce(
callback, version->embedded_worker()->process_id(),
version->embedded_worker()->worker_devtools_agent_route_id()));
......@@ -112,7 +114,7 @@ Response CreateInvalidVersionIdErrorResponse() {
return Response::InvalidParams("Invalid version ID");
}
void DidFindRegistrationForDispatchSyncEventOnIO(
void DidFindRegistrationForDispatchSyncEventOnCoreThread(
scoped_refptr<BackgroundSyncContextImpl> sync_context,
const std::string& tag,
bool last_chance,
......@@ -130,7 +132,7 @@ void DidFindRegistrationForDispatchSyncEventOnIO(
tag, std::move(version), last_chance, base::DoNothing());
}
void DidFindRegistrationForDispatchPeriodicSyncEventOnIO(
void DidFindRegistrationForDispatchPeriodicSyncEventOnCoreThread(
scoped_refptr<BackgroundSyncContextImpl> sync_context,
const std::string& tag,
blink::ServiceWorkerStatusCode status,
......@@ -149,7 +151,7 @@ void DidFindRegistrationForDispatchPeriodicSyncEventOnIO(
tag, std::move(version), base::DoNothing());
}
void DispatchSyncEventOnIO(
void DispatchSyncEventOnCoreThread(
scoped_refptr<ServiceWorkerContextWrapper> context,
scoped_refptr<BackgroundSyncContextImpl> sync_context,
const GURL& origin,
......@@ -158,11 +160,11 @@ void DispatchSyncEventOnIO(
bool last_chance) {
context->FindReadyRegistrationForId(
registration_id, origin,
base::BindOnce(&DidFindRegistrationForDispatchSyncEventOnIO, sync_context,
tag, last_chance));
base::BindOnce(&DidFindRegistrationForDispatchSyncEventOnCoreThread,
sync_context, tag, last_chance));
}
void DispatchPeriodicSyncEventOnIO(
void DispatchPeriodicSyncEventOnCoreThread(
scoped_refptr<ServiceWorkerContextWrapper> context,
scoped_refptr<BackgroundSyncContextImpl> sync_context,
const GURL& origin,
......@@ -170,8 +172,9 @@ void DispatchPeriodicSyncEventOnIO(
const std::string& tag) {
context->FindReadyRegistrationForId(
registration_id, origin,
base::BindOnce(&DidFindRegistrationForDispatchPeriodicSyncEventOnIO,
sync_context, tag));
base::BindOnce(
&DidFindRegistrationForDispatchPeriodicSyncEventOnCoreThread,
sync_context, tag));
}
} // namespace
......@@ -274,8 +277,9 @@ Response ServiceWorkerHandler::StopWorker(const std::string& version_id) {
int64_t id = 0;
if (!base::StringToInt64(version_id, &id))
return CreateInvalidVersionIdErrorResponse();
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::BindOnce(&StopServiceWorkerOnIO, context_, id));
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce(&StopServiceWorkerOnCoreThread, context_, id));
return Response::OK();
}
......@@ -312,9 +316,9 @@ Response ServiceWorkerHandler::InspectWorker(const std::string& version_id) {
int64_t id = blink::mojom::kInvalidServiceWorkerVersionId;
if (!base::StringToInt64(version_id, &id))
return CreateInvalidVersionIdErrorResponse();
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&GetDevToolsRouteInfoOnIO, context_, id,
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce(&GetDevToolsRouteInfoOnCoreThread, context_, id,
base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow,
weak_factory_.GetWeakPtr())));
return Response::OK();
......@@ -366,10 +370,10 @@ Response ServiceWorkerHandler::DispatchSyncEvent(
BackgroundSyncContextImpl* sync_context =
storage_partition_->GetBackgroundSyncContext();
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::BindOnce(&DispatchSyncEventOnIO, context_,
base::WrapRefCounted(sync_context),
GURL(origin), id, tag, last_chance));
RunOrPostTaskOnThread(FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce(&DispatchSyncEventOnCoreThread, context_,
base::WrapRefCounted(sync_context),
GURL(origin), id, tag, last_chance));
return Response::OK();
}
......@@ -388,9 +392,9 @@ Response ServiceWorkerHandler::DispatchPeriodicSyncEvent(
BackgroundSyncContextImpl* sync_context =
storage_partition_->GetBackgroundSyncContext();
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&DispatchPeriodicSyncEventOnIO, context_,
RunOrPostTaskOnThread(
FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce(&DispatchPeriodicSyncEventOnCoreThread, context_,
base::WrapRefCounted(sync_context), GURL(origin), id,
tag));
return Response::OK();
......
......@@ -27,7 +27,7 @@ namespace content {
namespace {
void TerminateServiceWorkerOnIO(
void TerminateServiceWorkerOnCoreThread(
base::WeakPtr<ServiceWorkerContextCore> context_weak,
int64_t version_id) {
if (ServiceWorkerContextCore* context = context_weak.get()) {
......@@ -36,7 +36,7 @@ void TerminateServiceWorkerOnIO(
}
}
void SetDevToolsAttachedOnIO(
void SetDevToolsAttachedOnCoreThread(
base::WeakPtr<ServiceWorkerContextCore> context_weak,
int64_t version_id,
bool attached) {
......@@ -46,7 +46,7 @@ void SetDevToolsAttachedOnIO(
}
}
void UpdateLoaderFactoriesOnIO(
void UpdateLoaderFactoriesOnCoreThread(
base::WeakPtr<ServiceWorkerContextCore> context_weak,
int64_t version_id,
std::unique_ptr<blink::URLLoaderFactoryBundleInfo> script_bundle,
......@@ -111,9 +111,9 @@ void ServiceWorkerDevToolsAgentHost::Reload() {
}
bool ServiceWorkerDevToolsAgentHost::Close() {
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&TerminateServiceWorkerOnIO, context_weak_, version_id_));
RunOrPostTaskOnThread(FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce(&TerminateServiceWorkerOnCoreThread,
context_weak_, version_id_));
return true;
}
......@@ -192,9 +192,9 @@ void ServiceWorkerDevToolsAgentHost::WorkerDestroyed() {
}
void ServiceWorkerDevToolsAgentHost::UpdateIsAttached(bool attached) {
base::PostTask(FROM_HERE, {BrowserThread::IO},
base::BindOnce(&SetDevToolsAttachedOnIO, context_weak_,
version_id_, attached));
RunOrPostTaskOnThread(FROM_HERE, ServiceWorkerContext::GetCoreThreadId(),
base::BindOnce(&SetDevToolsAttachedOnCoreThread,
context_weak_, version_id_, attached));
}
void ServiceWorkerDevToolsAgentHost::UpdateLoaderFactories(
......@@ -211,11 +211,20 @@ void ServiceWorkerDevToolsAgentHost::UpdateLoaderFactories(
auto subresource_bundle = EmbeddedWorkerInstance::CreateFactoryBundleOnUI(
rph, worker_route_id_, origin,
ContentBrowserClient::URLLoaderFactoryType::kServiceWorkerSubResource);
base::PostTaskAndReply(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&UpdateLoaderFactoriesOnIO, context_weak_, version_id_,
std::move(script_bundle), std::move(subresource_bundle)),
std::move(callback));
if (ServiceWorkerContext::IsServiceWorkerOnUIEnabled()) {
UpdateLoaderFactoriesOnCoreThread(context_weak_, version_id_,
std::move(script_bundle),
std::move(subresource_bundle));
std::move(callback).Run();
} else {
base::PostTaskAndReply(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&UpdateLoaderFactoriesOnCoreThread, context_weak_,
version_id_, std::move(script_bundle),
std::move(subresource_bundle)),
std::move(callback));
}
}
} // namespace content
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