Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Unified Diff: content/browser/service_worker/service_worker_provider_host.cc

Issue 2958753003: Revert "Create ServiceWorkerProviderHost before starting worker" (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_provider_host.cc
diff --git a/content/browser/service_worker/service_worker_provider_host.cc b/content/browser/service_worker/service_worker_provider_host.cc
index 5de525ed8bfb4792d6524130978924009f09fb2a..34be8dd0c8f7916e44abfbc074dc82f235056dd3 100644
--- a/content/browser/service_worker/service_worker_provider_host.cc
+++ b/content/browser/service_worker/service_worker_provider_host.cc
@@ -36,13 +36,10 @@ namespace content {
namespace {
-// Provider host for navigation with PlzNavigate or when service worker's
-// context is created on the browser side. This function provides the next
-// ServiceWorkerProviderHost ID for them, starts at -2 and keeps going down.
-int NextBrowserProvidedProviderId() {
- static int g_next_browser_provided_provider_id = -2;
- return g_next_browser_provided_provider_id--;
-}
+// PlzNavigate
+// Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps
+// going down.
+int g_next_navigation_provider_id = -2;
// A request handler derivative used to handle navigation requests when
// skip_service_worker flag is set. It tracks the document URL and sets the url
@@ -62,9 +59,10 @@ class ServiceWorkerURLTrackingRequestHandler
~ServiceWorkerURLTrackingRequestHandler() override {}
// Called via custom URLRequestJobFactory.
- net::URLRequestJob* MaybeCreateJob(net::URLRequest* request,
- net::NetworkDelegate*,
- ResourceContext*) override {
+ net::URLRequestJob* MaybeCreateJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* /* network_delegate */,
+ ResourceContext* /* resource_context */) override {
// |provider_host_| may have been deleted when the request is resumed.
if (!provider_host_)
return nullptr;
@@ -116,30 +114,18 @@ ServiceWorkerProviderHost::PreCreateNavigationHost(
bool are_ancestors_secure,
const WebContentsGetter& web_contents_getter) {
CHECK(IsBrowserSideNavigationEnabled());
+ // Generate a new browser-assigned id for the host.
+ int provider_id = g_next_navigation_provider_id--;
auto host = base::WrapUnique(new ServiceWorkerProviderHost(
ChildProcessHost::kInvalidUniqueID,
- ServiceWorkerProviderHostInfo(
- NextBrowserProvidedProviderId(), MSG_ROUTING_NONE,
- SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure),
+ ServiceWorkerProviderHostInfo(provider_id, MSG_ROUTING_NONE,
+ SERVICE_WORKER_PROVIDER_FOR_WINDOW,
+ are_ancestors_secure),
context, nullptr));
host->web_contents_getter_ = web_contents_getter;
return host;
}
-// static
-std::unique_ptr<ServiceWorkerProviderHost>
-ServiceWorkerProviderHost::PreCreateForController(
- base::WeakPtr<ServiceWorkerContextCore> context) {
- auto host = base::WrapUnique(new ServiceWorkerProviderHost(
- ChildProcessHost::kInvalidUniqueID,
- ServiceWorkerProviderHostInfo(NextBrowserProvidedProviderId(),
- MSG_ROUTING_NONE,
- SERVICE_WORKER_PROVIDER_FOR_CONTROLLER,
- true /* is_parent_frame_secure */),
- std::move(context), nullptr));
- return host;
-}
-
// static
std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create(
int process_id,
@@ -191,27 +177,20 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost(
binding_(this) {
DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type);
+ // PlzNavigate
+ CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID ||
+ IsBrowserSideNavigationEnabled());
if (info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) {
- // Actual |render_process_id| will be set after choosing a process for the
- // controller, and |render_thread id| will be set when the service worker
- // context gets started.
- DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id);
+ // Actual thread id is set when the service worker context gets started.
render_thread_id_ = kInvalidEmbeddedWorkerThreadId;
- } else {
- // PlzNavigate
- DCHECK(render_process_id != ChildProcessHost::kInvalidUniqueID ||
- IsBrowserSideNavigationEnabled());
}
-
context_->RegisterProviderHostByClientID(client_uuid_, this);
- // |client_| and |binding_| will be bound on CompleteNavigationInitialized
- // (PlzNavigate) or on CompleteStartWorkerPreparation (providers for
- // controller).
- if (!info_.client_ptr_info.is_valid() && !info_.host_request.is_pending()) {
- DCHECK(IsBrowserSideNavigationEnabled() ||
- info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER);
+ // PlzNavigate
+ // |provider_| and |binding_| will be bound on CompleteNavigationInitialized.
+ if (IsBrowserSideNavigationEnabled()) {
+ DCHECK(!info.client_ptr_info.is_valid() && !info.host_request.is_pending());
return;
}
@@ -345,6 +324,14 @@ void ServiceWorkerProviderHost::SetControllerVersionAttribute(
version ? version->used_features() : std::set<uint32_t>()));
}
+void ServiceWorkerProviderHost::SetHostedVersion(
+ ServiceWorkerVersion* version) {
+ DCHECK(!IsProviderForClient());
+ DCHECK_EQ(EmbeddedWorkerStatus::STARTING, version->running_status());
+ DCHECK_EQ(render_process_id_, version->embedded_worker()->process_id());
+ running_hosted_version_ = version;
+}
+
bool ServiceWorkerProviderHost::IsProviderForClient() const {
switch (info_.type) {
case SERVICE_WORKER_PROVIDER_FOR_WINDOW:
@@ -672,54 +659,6 @@ void ServiceWorkerProviderHost::CompleteNavigationInitialized(
NotifyControllerToAssociatedProvider();
}
-mojom::ServiceWorkerProviderInfoForStartWorkerPtr
-ServiceWorkerProviderHost::CompleteStartWorkerPreparation(
- int process_id,
- scoped_refptr<ServiceWorkerVersion> hosted_version) {
- DCHECK(context_);
- DCHECK_EQ(kInvalidEmbeddedWorkerThreadId, render_thread_id_);
- DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
- DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type());
- DCHECK(!running_hosted_version_);
-
- DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id);
-
- running_hosted_version_ = std::move(hosted_version);
-
- ServiceWorkerDispatcherHost* dispatcher_host =
- context_->GetDispatcherHost(process_id);
- DCHECK(dispatcher_host);
- render_process_id_ = process_id;
- dispatcher_host_ = dispatcher_host;
-
- // Retrieve the registration associated with |version|. The registration
- // must be alive because the version keeps it during starting worker.
- ServiceWorkerRegistration* registration = context_->GetLiveRegistration(
- running_hosted_version()->registration_id());
- DCHECK(registration);
- ServiceWorkerRegistrationObjectInfo info;
- ServiceWorkerVersionAttributes attrs;
- dispatcher_host->GetRegistrationObjectInfoAndVersionAttributes(
- AsWeakPtr(), registration, &info, &attrs);
-
- // Initialize provider_info.
- mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info =
- mojom::ServiceWorkerProviderInfoForStartWorker::New();
- provider_info->provider_id = provider_id();
- provider_info->attributes = std::move(attrs);
- provider_info->registration = std::move(info);
- provider_info->client_request = mojo::MakeRequest(&provider_);
- binding_.Bind(mojo::MakeRequest(&provider_info->host_ptr_info));
- binding_.set_connection_error_handler(
- base::Bind(&RemoveProviderHost, context_, process_id, provider_id()));
-
- // Set the document URL to the script url in order to allow
- // register/unregister/getRegistration on ServiceWorkerGlobalScope.
- SetDocumentUrl(running_hosted_version()->script_url());
-
- return provider_info;
-}
-
void ServiceWorkerProviderHost::SendUpdateFoundMessage(
int registration_handle_id) {
if (!dispatcher_host_)

Powered by Google App Engine
This is Rietveld 408576698