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

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.cc

Issue 2653493009: Add two interfaces for ServiceWorkerProviderContext/ProviderHost (Closed)
Patch Set: Rebased Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_provider_host.h" 5 #include "content/browser/service_worker/service_worker_provider_host.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/feature_list.h" 9 #include "base/feature_list.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ResourceType resource_type) 54 ResourceType resource_type)
55 : ServiceWorkerRequestHandler(context, 55 : ServiceWorkerRequestHandler(context,
56 provider_host, 56 provider_host,
57 blob_storage_context, 57 blob_storage_context,
58 resource_type) {} 58 resource_type) {}
59 ~ServiceWorkerURLTrackingRequestHandler() override {} 59 ~ServiceWorkerURLTrackingRequestHandler() override {}
60 60
61 // Called via custom URLRequestJobFactory. 61 // Called via custom URLRequestJobFactory.
62 net::URLRequestJob* MaybeCreateJob( 62 net::URLRequestJob* MaybeCreateJob(
63 net::URLRequest* request, 63 net::URLRequest* request,
64 net::NetworkDelegate* network_delegate, 64 net::NetworkDelegate* /* network_delegate */,
65 ResourceContext* resource_context) override { 65 ResourceContext* /* resource_context */) override {
66 // |provider_host_| may have been deleted when the request is resumed. 66 // |provider_host_| may have been deleted when the request is resumed.
67 if (!provider_host_) 67 if (!provider_host_)
68 return nullptr; 68 return nullptr;
69 const GURL stripped_url = net::SimplifyUrlForRequest(request->url()); 69 const GURL stripped_url = net::SimplifyUrlForRequest(request->url());
70 provider_host_->SetDocumentUrl(stripped_url); 70 provider_host_->SetDocumentUrl(stripped_url);
71 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); 71 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies());
72 return nullptr; 72 return nullptr;
73 } 73 }
74 74
75 private: 75 private:
76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLTrackingRequestHandler); 76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLTrackingRequestHandler);
77 }; 77 };
78 78
79 void RemoveProviderHost(base::WeakPtr<ServiceWorkerContextCore> context,
80 int process_id,
81 int provider_id) {
82 TRACE_EVENT0("ServiceWorker",
83 "ServiceWorkerProviderHost::RemoveProviderHost");
84 if (!context)
85 return;
86 if (!context->GetProviderHost(process_id, provider_id)) {
87 // PlzNavigate: in some cancellation of navigation cases, it is possible
88 // for the pre-created host, whose |provider_id| is assigned by the browser
89 // process, to have been destroyed before being claimed by the renderer. The
90 // provider is then destroyed in the renderer, and no matching host will be
91 // found.
92 DCHECK(IsBrowserSideNavigationEnabled() &&
93 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id));
94 return;
95 }
96 context->RemoveProviderHost(process_id, provider_id);
97 }
98
79 } // anonymous namespace 99 } // anonymous namespace
80 100
81 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( 101 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback(
82 const GetRegistrationForReadyCallback& callback) 102 const GetRegistrationForReadyCallback& callback)
83 : callback(callback), 103 : callback(callback),
84 called(false) { 104 called(false) {
85 } 105 }
86 106
87 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { 107 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() {
88 } 108 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 int render_process_id, 165 int render_process_id,
146 ServiceWorkerProviderHostInfo info, 166 ServiceWorkerProviderHostInfo info,
147 base::WeakPtr<ServiceWorkerContextCore> context, 167 base::WeakPtr<ServiceWorkerContextCore> context,
148 ServiceWorkerDispatcherHost* dispatcher_host) 168 ServiceWorkerDispatcherHost* dispatcher_host)
149 : client_uuid_(base::GenerateGUID()), 169 : client_uuid_(base::GenerateGUID()),
150 render_process_id_(render_process_id), 170 render_process_id_(render_process_id),
151 render_thread_id_(kDocumentMainThreadId), 171 render_thread_id_(kDocumentMainThreadId),
152 info_(std::move(info)), 172 info_(std::move(info)),
153 context_(context), 173 context_(context),
154 dispatcher_host_(dispatcher_host), 174 dispatcher_host_(dispatcher_host),
155 allow_association_(true) { 175 allow_association_(true),
176 binding_(this) {
156 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type); 177 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type);
157 178
158 // PlzNavigate 179 // PlzNavigate
159 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || 180 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID ||
160 IsBrowserSideNavigationEnabled()); 181 IsBrowserSideNavigationEnabled());
161 182
162 if (info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { 183 if (info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) {
163 // Actual thread id is set when the service worker context gets started. 184 // Actual thread id is set when the service worker context gets started.
164 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; 185 render_thread_id_ = kInvalidEmbeddedWorkerThreadId;
165 } 186 }
166 context_->RegisterProviderHostByClientID(client_uuid_, this); 187 context_->RegisterProviderHostByClientID(client_uuid_, this);
188
189 // PlzNavigate
190 // |provider_| and |binding_| will be bound on CompleteNavigationInitialized.
191 if (IsBrowserSideNavigationEnabled()) {
192 DCHECK(!info.client_ptr_info.is_valid() && !info.host_request.is_pending());
193 return;
194 }
195
196 provider_.Bind(std::move(info_.client_ptr_info));
197 binding_.Bind(std::move(info_.host_request));
198 binding_.set_connection_error_handler(base::Bind(
199 &RemoveProviderHost, context_, render_process_id, info_.provider_id));
167 } 200 }
168 201
169 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { 202 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
170 if (context_) 203 if (context_)
171 context_->UnregisterProviderHostByClientID(client_uuid_); 204 context_->UnregisterProviderHostByClientID(client_uuid_);
172 205
173 // Clear docurl so the deferred activation of a waiting worker 206 // Clear docurl so the deferred activation of a waiting worker
174 // won't associate the new version with a provider being destroyed. 207 // won't associate the new version with a provider being destroyed.
175 document_url_ = GURL(); 208 document_url_ = GURL();
176 if (controlling_version_.get()) 209 if (controlling_version_.get())
(...skipping 26 matching lines...) Expand all
203 236
204 std::set<std::string> schemes; 237 std::set<std::string> schemes;
205 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist( 238 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist(
206 &schemes); 239 &schemes);
207 return schemes.find(document_url().scheme()) != schemes.end(); 240 return schemes.find(document_url().scheme()) != schemes.end();
208 } 241 }
209 242
210 void ServiceWorkerProviderHost::OnVersionAttributesChanged( 243 void ServiceWorkerProviderHost::OnVersionAttributesChanged(
211 ServiceWorkerRegistration* registration, 244 ServiceWorkerRegistration* registration,
212 ChangedVersionAttributesMask changed_mask, 245 ChangedVersionAttributesMask changed_mask,
213 const ServiceWorkerRegistrationInfo& info) { 246 const ServiceWorkerRegistrationInfo& /* info */) {
214 if (!get_ready_callback_ || get_ready_callback_->called) 247 if (!get_ready_callback_ || get_ready_callback_->called)
215 return; 248 return;
216 if (changed_mask.active_changed() && registration->active_version()) { 249 if (changed_mask.active_changed() && registration->active_version()) {
217 // Wait until the state change so we don't send the get for ready 250 // Wait until the state change so we don't send the get for ready
218 // registration complete message before set version attributes message. 251 // registration complete message before set version attributes message.
219 registration->active_version()->RegisterStatusChangeCallback(base::Bind( 252 registration->active_version()->RegisterStatusChangeCallback(base::Bind(
220 &ServiceWorkerProviderHost::ReturnRegistrationForReadyIfNeeded, 253 &ServiceWorkerProviderHost::ReturnRegistrationForReadyIfNeeded,
221 AsWeakPtr())); 254 AsWeakPtr()));
222 } 255 }
223 } 256 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 564
532 std::unique_ptr<ServiceWorkerProviderHost> 565 std::unique_ptr<ServiceWorkerProviderHost>
533 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { 566 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() {
534 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); 567 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_);
535 DCHECK_NE(MSG_ROUTING_NONE, info_.route_id); 568 DCHECK_NE(MSG_ROUTING_NONE, info_.route_id);
536 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 569 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
537 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type); 570 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type);
538 571
539 std::unique_ptr<ServiceWorkerProviderHost> provisional_host = 572 std::unique_ptr<ServiceWorkerProviderHost> provisional_host =
540 base::WrapUnique(new ServiceWorkerProviderHost( 573 base::WrapUnique(new ServiceWorkerProviderHost(
541 process_id(), std::move(info_), context_, dispatcher_host())); 574 process_id(),
575 ServiceWorkerProviderHostInfo(std::move(info_), binding_.Unbind(),
576 provider_.PassInterface()),
577 context_, dispatcher_host()));
542 578
543 for (const GURL& pattern : associated_patterns_) 579 for (const GURL& pattern : associated_patterns_)
544 DecreaseProcessReference(pattern); 580 DecreaseProcessReference(pattern);
545 581
546 for (auto& key_registration : matching_registrations_) 582 for (auto& key_registration : matching_registrations_)
547 DecreaseProcessReference(key_registration.second->pattern()); 583 DecreaseProcessReference(key_registration.second->pattern());
548 584
549 if (associated_registration_.get()) { 585 if (associated_registration_.get()) {
550 if (dispatcher_host_) { 586 if (dispatcher_host_) {
551 Send(new ServiceWorkerMsg_DisassociateRegistration( 587 Send(new ServiceWorkerMsg_DisassociateRegistration(
(...skipping 10 matching lines...) Expand all
562 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( 598 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer(
563 ServiceWorkerProviderHost* provisional_host) { 599 ServiceWorkerProviderHost* provisional_host) {
564 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 600 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
565 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, provisional_host->process_id()); 601 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, provisional_host->process_id());
566 DCHECK_NE(MSG_ROUTING_NONE, provisional_host->frame_id()); 602 DCHECK_NE(MSG_ROUTING_NONE, provisional_host->frame_id());
567 603
568 render_thread_id_ = kDocumentMainThreadId; 604 render_thread_id_ = kDocumentMainThreadId;
569 info_.provider_id = provisional_host->provider_id(); 605 info_.provider_id = provisional_host->provider_id();
570 info_.type = provisional_host->provider_type(); 606 info_.type = provisional_host->provider_type();
571 607
608 // Take the connection over from the provisional host.
609 DCHECK(!provider_.is_bound());
610 DCHECK(!binding_.is_bound());
611 provider_.Bind(provisional_host->provider_.PassInterface());
612 binding_.Bind(provisional_host->binding_.Unbind());
613 binding_.set_connection_error_handler(
614 base::Bind(&RemoveProviderHost, context_, provisional_host->process_id(),
615 provisional_host->provider_id()));
616
572 FinalizeInitialization(provisional_host->process_id(), 617 FinalizeInitialization(provisional_host->process_id(),
573 provisional_host->frame_id(), 618 provisional_host->frame_id(),
574 provisional_host->dispatcher_host()); 619 provisional_host->dispatcher_host());
575 } 620 }
576 621
577 // PlzNavigate 622 // PlzNavigate
578 void ServiceWorkerProviderHost::CompleteNavigationInitialized( 623 void ServiceWorkerProviderHost::CompleteNavigationInitialized(
579 int process_id, 624 int process_id,
580 int frame_routing_id, 625 ServiceWorkerProviderHostInfo info,
581 ServiceWorkerDispatcherHost* dispatcher_host) { 626 ServiceWorkerDispatcherHost* dispatcher_host) {
582 CHECK(IsBrowserSideNavigationEnabled()); 627 CHECK(IsBrowserSideNavigationEnabled());
583 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 628 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
584 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, info_.type); 629 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, info_.type);
585 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 630 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
586 631
587 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id); 632 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id);
588 DCHECK_NE(MSG_ROUTING_NONE, frame_routing_id); 633 DCHECK_EQ(info_.provider_id, info.provider_id);
634 DCHECK_NE(MSG_ROUTING_NONE, info.route_id);
589 635
590 FinalizeInitialization(process_id, frame_routing_id, dispatcher_host); 636 // Connect with the provider on the renderer.
637 DCHECK(!provider_.is_bound());
638 DCHECK(!binding_.is_bound());
639 provider_.Bind(std::move(info.client_ptr_info));
640 binding_.Bind(std::move(info.host_request));
641 binding_.set_connection_error_handler(
642 base::Bind(&RemoveProviderHost, context_, process_id, provider_id()));
643
644 FinalizeInitialization(process_id, info.route_id, dispatcher_host);
591 } 645 }
592 646
593 void ServiceWorkerProviderHost::SendUpdateFoundMessage( 647 void ServiceWorkerProviderHost::SendUpdateFoundMessage(
594 int registration_handle_id) { 648 int registration_handle_id) {
595 if (!dispatcher_host_) 649 if (!dispatcher_host_)
596 return; // Could be nullptr in some tests. 650 return; // Could be nullptr in some tests.
597 651
598 if (!IsReadyToSendMessages()) { 652 if (!IsReadyToSendMessages()) {
599 queued_events_.push_back( 653 queued_events_.push_back(
600 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, 654 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 render_thread_id_, provider_id(), 829 render_thread_id_, provider_id(),
776 GetOrCreateServiceWorkerHandle( 830 GetOrCreateServiceWorkerHandle(
777 associated_registration_->active_version()), 831 associated_registration_->active_version()),
778 false /* shouldNotifyControllerChange */, 832 false /* shouldNotifyControllerChange */,
779 associated_registration_->active_version()->used_features())); 833 associated_registration_->active_version()->used_features()));
780 } 834 }
781 } 835 }
782 } 836 }
783 837
784 } // namespace content 838 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698