Chromium Code Reviews| 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 40a00374088869c3373f2ca7191e02ab95b7275f..5e33153dca4f8de89073c2033414a31d2d4cb9c5 100644 |
| --- a/content/browser/service_worker/service_worker_provider_host.cc |
| +++ b/content/browser/service_worker/service_worker_provider_host.cc |
| @@ -58,8 +58,8 @@ class ServiceWorkerURLTrackingRequestHandler |
| // Called via custom URLRequestJobFactory. |
| net::URLRequestJob* MaybeCreateJob( |
| net::URLRequest* request, |
| - net::NetworkDelegate* network_delegate, |
| - ResourceContext* resource_context) override { |
| + net::NetworkDelegate* /* network_delegate */, |
| + ResourceContext* /* resource_context */) override { |
|
falken
2017/03/28 06:29:43
You can just omit the names when they don't add ne
shimazu
2017/05/08 08:34:29
Done.
|
| const GURL stripped_url = net::SimplifyUrlForRequest(request->url()); |
| provider_host_->SetDocumentUrl(stripped_url); |
| provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); |
| @@ -70,6 +70,24 @@ class ServiceWorkerURLTrackingRequestHandler |
| DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLTrackingRequestHandler); |
| }; |
| +void RemoveProviderHost(base::WeakPtr<ServiceWorkerContextCore> context, |
| + int process_id, |
| + int provider_id) { |
| + TRACE_EVENT0("ServiceWorker", "ServiceWorkerProviderHost::ProviderDestroyed"); |
|
falken
2017/03/28 06:29:42
Trace event is using the old name.
shimazu
2017/05/08 08:34:28
Done.
|
| + if (!context) |
| + return; |
| + if (!context->GetProviderHost(process_id, provider_id)) { |
| + // PlzNavigate: in some cancellation of navigation cases, it is possible |
| + // for the pre-created host to have been destroyed before being claimed by |
| + // the renderer. The provider is then destroyed in the renderer, and no |
| + // matching host will be found. |
| + CHECK(IsBrowserSideNavigationEnabled() && |
| + ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)); |
| + return; |
| + } |
| + context->RemoveProviderHost(process_id, provider_id); |
| +} |
| + |
| } // anonymous namespace |
| ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( |
| @@ -92,8 +110,9 @@ ServiceWorkerProviderHost::PreCreateNavigationHost( |
| int provider_id = g_next_navigation_provider_id--; |
| auto host = base::WrapUnique(new ServiceWorkerProviderHost( |
| ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, |
| - SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure, context, |
| - nullptr)); |
| + SERVICE_WORKER_PROVIDER_FOR_WINDOW, are_ancestors_secure, |
| + mojom::ServiceWorkerProviderAssociatedPtrInfo(), |
| + mojom::ServiceWorkerProviderHostAssociatedRequest(), context, nullptr)); |
| host->web_contents_getter_ = web_contents_getter; |
| return host; |
| } |
| @@ -106,7 +125,8 @@ std::unique_ptr<ServiceWorkerProviderHost> ServiceWorkerProviderHost::Create( |
| ServiceWorkerDispatcherHost* dispatcher_host) { |
| return base::WrapUnique(new ServiceWorkerProviderHost( |
| process_id, info.route_id, info.provider_id, info.type, |
| - info.is_parent_frame_secure, context, dispatcher_host)); |
| + info.is_parent_frame_secure, std::move(info.client_ptr_info), |
| + std::move(info.host_request), context, dispatcher_host)); |
| } |
| ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
| @@ -115,6 +135,8 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
| int provider_id, |
| ServiceWorkerProviderType provider_type, |
| bool is_parent_frame_secure, |
| + mojom::ServiceWorkerProviderAssociatedPtrInfo client_info, |
| + mojom::ServiceWorkerProviderHostAssociatedRequest request, |
| base::WeakPtr<ServiceWorkerContextCore> context, |
| ServiceWorkerDispatcherHost* dispatcher_host) |
| : client_uuid_(base::GenerateGUID()), |
| @@ -126,7 +148,8 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
| is_parent_frame_secure_(is_parent_frame_secure), |
| context_(context), |
| dispatcher_host_(dispatcher_host), |
| - allow_association_(true) { |
| + allow_association_(true), |
| + binding_(this, std::move(request)) { |
| DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
| // PlzNavigate |
| @@ -138,6 +161,13 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
| render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
| } |
| context_->RegisterProviderHostByClientID(client_uuid_, this); |
| + |
| + // Mojo pile is possible to be null when testing. |
|
falken
2017/03/28 06:29:43
Can we instead fix the tests?
shimazu
2017/05/08 08:34:28
Yes, I agree with avoiding testing code in product
|
| + if (client_info.is_valid() && binding_.is_bound()) { |
| + client_.Bind(std::move(client_info)); |
| + binding_.set_connection_error_handler(base::Bind( |
| + &RemoveProviderHost, context_, render_process_id, provider_id)); |
| + } |
| } |
| ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
| @@ -184,7 +214,7 @@ bool ServiceWorkerProviderHost::IsContextSecureForServiceWorker() const { |
| void ServiceWorkerProviderHost::OnVersionAttributesChanged( |
| ServiceWorkerRegistration* registration, |
| ChangedVersionAttributesMask changed_mask, |
| - const ServiceWorkerRegistrationInfo& info) { |
| + const ServiceWorkerRegistrationInfo& /* info */) { |
| if (!get_ready_callback_ || get_ready_callback_->called) |
| return; |
| if (changed_mask.active_changed() && registration->active_version()) { |
| @@ -509,7 +539,10 @@ ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { |
| std::unique_ptr<ServiceWorkerProviderHost> new_provider_host = |
| base::WrapUnique(new ServiceWorkerProviderHost( |
| process_id(), frame_id(), provider_id(), provider_type(), |
| - is_parent_frame_secure(), context_, dispatcher_host())); |
| + is_parent_frame_secure(), |
| + mojom::ServiceWorkerProviderAssociatedPtrInfo(), |
| + mojom::ServiceWorkerProviderHostAssociatedRequest(), context_, |
| + dispatcher_host())); |
| for (const GURL& pattern : associated_patterns_) |
| DecreaseProcessReference(pattern); |