Commit 29144d27 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Prepare navigation for UI thread core.

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

This makes some code used in navigation be core thread-aware instead
of assuming the IO thread. This allows many content_browsertests
for ServiceWorker to pass when ServiceWorkerOnUI is enabled.

Bug: 824858
Change-Id: I3e70cf88f615e77a8f45370eea002b6b344e1511
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760829
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688284}
parent f4b2516e
...@@ -101,6 +101,7 @@ ...@@ -101,6 +101,7 @@
#include "content/browser/renderer_host/render_widget_host_view_child_frame.h" #include "content/browser/renderer_host/render_widget_host_view_child_frame.h"
#include "content/browser/renderer_interface_binders.h" #include "content/browser/renderer_interface_binders.h"
#include "content/browser/scoped_active_url.h" #include "content/browser/scoped_active_url.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/sms/sms_service.h" #include "content/browser/sms/sms_service.h"
#include "content/browser/speech/speech_recognition_dispatcher_host.h" #include "content/browser/speech/speech_recognition_dispatcher_host.h"
#include "content/browser/storage_partition_impl.h" #include "content/browser/storage_partition_impl.h"
...@@ -5311,8 +5312,8 @@ void RenderFrameHostImpl::CommitNavigation( ...@@ -5311,8 +5312,8 @@ void RenderFrameHostImpl::CommitNavigation(
// it until its request endpoint is sent. Now that the request endpoint was // it until its request endpoint is sent. Now that the request endpoint was
// sent, it can be used, so add it to ServiceWorkerObjectHost. // sent, it can be used, so add it to ServiceWorkerObjectHost.
if (remote_object.is_valid()) { if (remote_object.is_valid()) {
base::PostTask( RunOrPostTaskOnThread(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce( base::BindOnce(
&ServiceWorkerObjectHost::AddRemoteObjectPtrAndUpdateState, &ServiceWorkerObjectHost::AddRemoteObjectPtrAndUpdateState,
subresource_loader_params->controller_service_worker_object_host, subresource_loader_params->controller_service_worker_object_host,
......
...@@ -1029,8 +1029,8 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -1029,8 +1029,8 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
// TODO(crbug/898733): Support SignedExchange loading and Service // TODO(crbug/898733): Support SignedExchange loading and Service
// Worker integration. // Worker integration.
if (service_worker_navigation_handle_) { if (service_worker_navigation_handle_) {
base::PostTask( RunOrPostTaskOnThread(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, ServiceWorkerContextWrapper::GetCoreThreadId(),
base::BindOnce( base::BindOnce(
[](ServiceWorkerNavigationHandleCore* core) { [](ServiceWorkerNavigationHandleCore* core) {
base::WeakPtr<ServiceWorkerProviderHost> host = base::WeakPtr<ServiceWorkerProviderHost> host =
...@@ -1042,7 +1042,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -1042,7 +1042,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
} }
}, },
// Unretained() is safe because the handle owns the core, // Unretained() is safe because the handle owns the core,
// and core gets deleted on the IO thread in a task that // and core gets deleted on the core thread in a task that
// must occur after this task. // must occur after this task.
base::Unretained( base::Unretained(
service_worker_navigation_handle_->core()))); service_worker_navigation_handle_->core())));
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "content/browser/devtools/devtools_url_loader_interceptor.h" #include "content/browser/devtools/devtools_url_loader_interceptor.h"
#include "content/browser/frame_host/frame_tree_node.h" #include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/loader/webrtc_connections_observer.h" #include "content/browser/loader/webrtc_connections_observer.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/ssl/ssl_client_auth_handler.h" #include "content/browser/ssl/ssl_client_auth_handler.h"
#include "content/browser/ssl/ssl_error_handler.h" #include "content/browser/ssl/ssl_error_handler.h"
#include "content/browser/ssl/ssl_manager.h" #include "content/browser/ssl/ssl_manager.h"
...@@ -364,12 +365,21 @@ void OnAuthRequiredContinuationForWindowId( ...@@ -364,12 +365,21 @@ void OnAuthRequiredContinuationForWindowId(
std::move(auth_challenge_responder)->OnAuthCredentials(base::nullopt); std::move(auth_challenge_responder)->OnAuthCredentials(base::nullopt);
return; return;
} }
base::PostTaskAndReplyWithResult(
FROM_HERE, {BrowserThread::IO}, if (ServiceWorkerContextWrapper::IsServiceWorkerOnUIEnabled()) {
base::BindOnce(&GetWebContentsFromRegistry, window_id), OnAuthRequiredContinuation(process_id, routing_id, request_id, url,
base::BindOnce(&OnAuthRequiredContinuation, process_id, routing_id, *is_main_frame_opt, first_auth_attempt,
request_id, url, *is_main_frame_opt, first_auth_attempt, auth_info, head,
auth_info, head, std::move(auth_challenge_responder))); std::move(auth_challenge_responder),
GetWebContentsFromRegistry(window_id));
} else {
base::PostTaskAndReplyWithResult(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&GetWebContentsFromRegistry, window_id),
base::BindOnce(&OnAuthRequiredContinuation, process_id, routing_id,
request_id, url, *is_main_frame_opt, first_auth_attempt,
auth_info, head, std::move(auth_challenge_responder)));
}
} }
void CreateSSLClientAuthDelegateOnIO( void CreateSSLClientAuthDelegateOnIO(
...@@ -488,13 +498,21 @@ void NetworkServiceClient::OnAuthRequired( ...@@ -488,13 +498,21 @@ void NetworkServiceClient::OnAuthRequired(
const base::Optional<network::ResourceResponseHead>& head, const base::Optional<network::ResourceResponseHead>& head,
network::mojom::AuthChallengeResponderPtr auth_challenge_responder) { network::mojom::AuthChallengeResponderPtr auth_challenge_responder) {
if (window_id) { if (window_id) {
base::PostTaskAndReplyWithResult( if (ServiceWorkerContextWrapper::IsServiceWorkerOnUIEnabled()) {
FROM_HERE, {BrowserThread::IO}, OnAuthRequiredContinuationForWindowId(
base::BindOnce(&GetIsMainFrameFromRegistry, *window_id), *window_id, process_id, routing_id, request_id, url,
base::BindOnce(&OnAuthRequiredContinuationForWindowId, *window_id, first_auth_attempt, auth_info, head,
process_id, routing_id, request_id, url, std::move(auth_challenge_responder),
first_auth_attempt, auth_info, head, GetIsMainFrameFromRegistry(*window_id));
std::move(auth_challenge_responder))); } else {
base::PostTaskAndReplyWithResult(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&GetIsMainFrameFromRegistry, *window_id),
base::BindOnce(&OnAuthRequiredContinuationForWindowId, *window_id,
process_id, routing_id, request_id, url,
first_auth_attempt, auth_info, head,
std::move(auth_challenge_responder)));
}
return; return;
} }
OnAuthRequiredContinuation(process_id, routing_id, request_id, url, OnAuthRequiredContinuation(process_id, routing_id, request_id, url,
...@@ -512,12 +530,19 @@ void NetworkServiceClient::OnCertificateRequested( ...@@ -512,12 +530,19 @@ void NetworkServiceClient::OnCertificateRequested(
network::mojom::ClientCertificateResponderPtr cert_responder) { network::mojom::ClientCertificateResponderPtr cert_responder) {
// Use |window_id| if it's provided. // Use |window_id| if it's provided.
if (window_id) { if (window_id) {
base::PostTaskAndReplyWithResult( if (ServiceWorkerContextWrapper::IsServiceWorkerOnUIEnabled()) {
FROM_HERE, {BrowserThread::IO}, OnCertificateRequestedContinuation(
base::BindOnce(&GetWebContentsFromRegistry, *window_id), process_id, routing_id, request_id, cert_info,
base::BindOnce(&OnCertificateRequestedContinuation, process_id, cert_responder.PassInterface(),
routing_id, request_id, cert_info, GetWebContentsFromRegistry(*window_id));
cert_responder.PassInterface())); } else {
base::PostTaskAndReplyWithResult(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&GetWebContentsFromRegistry, *window_id),
base::BindOnce(&OnCertificateRequestedContinuation, process_id,
routing_id, request_id, cert_info,
cert_responder.PassInterface()));
}
return; return;
} }
......
...@@ -17,10 +17,14 @@ namespace content { ...@@ -17,10 +17,14 @@ namespace content {
class WebContents; class WebContents;
// A global map of UnguessableToken to FrameTreeNode id. This registry lives // A global map of UnguessableToken to FrameTreeNode id. This registry lives and
// and is used only on the IO thread, as it's convenient for the current user // is used only on the thread identified by
// of the class (ServiceWorkerProviderHost, which should move to the UI thread // ServiceWorkerContextWrapper::GetCoreThreadId(), as that's the thread the
// eventually). This is currently used to map a network request to a frame so // class that adds/removes from this registry is on (ServiceWorkerProviderHost).
// TODO(crbug.com/824858): Make this live on the UI thread once the service
// worker core thread moves to the UI thread.
//
// This is currently used to map a network request to a frame so
// that the network service can tell the browser to display tab-level UI // that the network service can tell the browser to display tab-level UI
// required for the request in certain cases, including client certificates and // required for the request in certain cases, including client certificates and
// basic HTTP authentication. // basic HTTP authentication.
......
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