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

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

Issue 2653493009: Add two interfaces for ServiceWorkerProviderContext/ProviderHost (Closed)
Patch Set: Addressed comments from falken 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 to have been destroyed before being claimed by
89 // the renderer. The provider is then destroyed in the renderer, and no
90 // matching host will be found.
falken 2017/05/22 08:28:12 "pre-created host" means ServiceWorkerUtils::IsBro
shimazu 2017/05/23 06:29:34 Done.
91 CHECK(IsBrowserSideNavigationEnabled() &&
92 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id));
falken 2017/05/22 08:28:12 Why a CHECK here? From the style guide: "Use CHECK
shimazu 2017/05/23 06:29:34 Thanks, it's just inherited from the previous impl
93 return;
94 }
95 context->RemoveProviderHost(process_id, provider_id);
96 }
97
79 } // anonymous namespace 98 } // anonymous namespace
80 99
81 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( 100 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback(
82 const GetRegistrationForReadyCallback& callback) 101 const GetRegistrationForReadyCallback& callback)
83 : callback(callback), 102 : callback(callback),
84 called(false) { 103 called(false) {
85 } 104 }
86 105
87 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { 106 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() {
88 } 107 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 int render_process_id, 164 int render_process_id,
146 ServiceWorkerProviderHostInfo info, 165 ServiceWorkerProviderHostInfo info,
147 base::WeakPtr<ServiceWorkerContextCore> context, 166 base::WeakPtr<ServiceWorkerContextCore> context,
148 ServiceWorkerDispatcherHost* dispatcher_host) 167 ServiceWorkerDispatcherHost* dispatcher_host)
149 : client_uuid_(base::GenerateGUID()), 168 : client_uuid_(base::GenerateGUID()),
150 render_process_id_(render_process_id), 169 render_process_id_(render_process_id),
151 render_thread_id_(kDocumentMainThreadId), 170 render_thread_id_(kDocumentMainThreadId),
152 info_(std::move(info)), 171 info_(std::move(info)),
153 context_(context), 172 context_(context),
154 dispatcher_host_(dispatcher_host), 173 dispatcher_host_(dispatcher_host),
155 allow_association_(true) { 174 allow_association_(true),
175 binding_(this) {
156 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type); 176 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type);
157 177
158 // PlzNavigate 178 // PlzNavigate
159 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || 179 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID ||
160 IsBrowserSideNavigationEnabled()); 180 IsBrowserSideNavigationEnabled());
161 181
162 if (info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { 182 if (info_.type == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) {
163 // Actual thread id is set when the service worker context gets started. 183 // Actual thread id is set when the service worker context gets started.
164 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; 184 render_thread_id_ = kInvalidEmbeddedWorkerThreadId;
165 } 185 }
166 context_->RegisterProviderHostByClientID(client_uuid_, this); 186 context_->RegisterProviderHostByClientID(client_uuid_, this);
187
188 // PlzNavigate
189 // |provider_| and |binding_| will be bound on CompleteNavigationInitialized.
190 if (IsBrowserSideNavigationEnabled()) {
191 DCHECK(!info.client_ptr_info.is_valid() && !info.host_request.is_pending());
192 return;
193 }
194
195 provider_.Bind(std::move(info_.client_ptr_info));
196 binding_.Bind(std::move(info_.host_request));
197 binding_.set_connection_error_handler(base::Bind(
198 &RemoveProviderHost, context_, render_process_id, info_.provider_id));
167 } 199 }
168 200
169 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { 201 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
170 if (context_) 202 if (context_)
171 context_->UnregisterProviderHostByClientID(client_uuid_); 203 context_->UnregisterProviderHostByClientID(client_uuid_);
172 204
173 // Clear docurl so the deferred activation of a waiting worker 205 // Clear docurl so the deferred activation of a waiting worker
174 // won't associate the new version with a provider being destroyed. 206 // won't associate the new version with a provider being destroyed.
175 document_url_ = GURL(); 207 document_url_ = GURL();
176 if (controlling_version_.get()) 208 if (controlling_version_.get())
(...skipping 26 matching lines...) Expand all
203 235
204 std::set<std::string> schemes; 236 std::set<std::string> schemes;
205 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist( 237 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist(
206 &schemes); 238 &schemes);
207 return schemes.find(document_url().scheme()) != schemes.end(); 239 return schemes.find(document_url().scheme()) != schemes.end();
208 } 240 }
209 241
210 void ServiceWorkerProviderHost::OnVersionAttributesChanged( 242 void ServiceWorkerProviderHost::OnVersionAttributesChanged(
211 ServiceWorkerRegistration* registration, 243 ServiceWorkerRegistration* registration,
212 ChangedVersionAttributesMask changed_mask, 244 ChangedVersionAttributesMask changed_mask,
213 const ServiceWorkerRegistrationInfo& info) { 245 const ServiceWorkerRegistrationInfo& /* info */) {
214 if (!get_ready_callback_ || get_ready_callback_->called) 246 if (!get_ready_callback_ || get_ready_callback_->called)
215 return; 247 return;
216 if (changed_mask.active_changed() && registration->active_version()) { 248 if (changed_mask.active_changed() && registration->active_version()) {
217 // Wait until the state change so we don't send the get for ready 249 // Wait until the state change so we don't send the get for ready
218 // registration complete message before set version attributes message. 250 // registration complete message before set version attributes message.
219 registration->active_version()->RegisterStatusChangeCallback(base::Bind( 251 registration->active_version()->RegisterStatusChangeCallback(base::Bind(
220 &ServiceWorkerProviderHost::ReturnRegistrationForReadyIfNeeded, 252 &ServiceWorkerProviderHost::ReturnRegistrationForReadyIfNeeded,
221 AsWeakPtr())); 253 AsWeakPtr()));
222 } 254 }
223 } 255 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 563
532 std::unique_ptr<ServiceWorkerProviderHost> 564 std::unique_ptr<ServiceWorkerProviderHost>
533 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { 565 ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() {
534 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); 566 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_);
535 DCHECK_NE(MSG_ROUTING_NONE, info_.route_id); 567 DCHECK_NE(MSG_ROUTING_NONE, info_.route_id);
536 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 568 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
537 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type); 569 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, info_.type);
538 570
539 std::unique_ptr<ServiceWorkerProviderHost> provisional_host = 571 std::unique_ptr<ServiceWorkerProviderHost> provisional_host =
540 base::WrapUnique(new ServiceWorkerProviderHost( 572 base::WrapUnique(new ServiceWorkerProviderHost(
541 process_id(), std::move(info_), context_, dispatcher_host())); 573 process_id(),
574 ServiceWorkerProviderHostInfo(std::move(info_), binding_.Unbind(),
575 provider_.PassInterface()),
576 context_, dispatcher_host()));
542 577
543 for (const GURL& pattern : associated_patterns_) 578 for (const GURL& pattern : associated_patterns_)
544 DecreaseProcessReference(pattern); 579 DecreaseProcessReference(pattern);
545 580
546 for (auto& key_registration : matching_registrations_) 581 for (auto& key_registration : matching_registrations_)
547 DecreaseProcessReference(key_registration.second->pattern()); 582 DecreaseProcessReference(key_registration.second->pattern());
548 583
549 if (associated_registration_.get()) { 584 if (associated_registration_.get()) {
550 if (dispatcher_host_) { 585 if (dispatcher_host_) {
551 Send(new ServiceWorkerMsg_DisassociateRegistration( 586 Send(new ServiceWorkerMsg_DisassociateRegistration(
(...skipping 10 matching lines...) Expand all
562 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( 597 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer(
563 ServiceWorkerProviderHost* provisional_host) { 598 ServiceWorkerProviderHost* provisional_host) {
564 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 599 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
565 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, provisional_host->process_id()); 600 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, provisional_host->process_id());
566 DCHECK_NE(MSG_ROUTING_NONE, provisional_host->frame_id()); 601 DCHECK_NE(MSG_ROUTING_NONE, provisional_host->frame_id());
567 602
568 render_thread_id_ = kDocumentMainThreadId; 603 render_thread_id_ = kDocumentMainThreadId;
569 info_.provider_id = provisional_host->provider_id(); 604 info_.provider_id = provisional_host->provider_id();
570 info_.type = provisional_host->provider_type(); 605 info_.type = provisional_host->provider_type();
571 606
607 // Take the connection over from the provisional host.
608 DCHECK(!provider_.is_bound());
609 DCHECK(!binding_.is_bound());
610 provider_.Bind(provisional_host->provider_.PassInterface());
611 binding_.Bind(provisional_host->binding_.Unbind());
612 binding_.set_connection_error_handler(
613 base::Bind(&RemoveProviderHost, context_, provisional_host->process_id(),
614 provisional_host->provider_id()));
615
572 FinalizeInitialization(provisional_host->process_id(), 616 FinalizeInitialization(provisional_host->process_id(),
573 provisional_host->frame_id(), 617 provisional_host->frame_id(),
574 provisional_host->dispatcher_host()); 618 provisional_host->dispatcher_host());
575 } 619 }
576 620
577 // PlzNavigate 621 // PlzNavigate
578 void ServiceWorkerProviderHost::CompleteNavigationInitialized( 622 void ServiceWorkerProviderHost::CompleteNavigationInitialized(
579 int process_id, 623 int process_id,
580 int frame_routing_id, 624 ServiceWorkerProviderHostInfo info,
581 ServiceWorkerDispatcherHost* dispatcher_host) { 625 ServiceWorkerDispatcherHost* dispatcher_host) {
582 CHECK(IsBrowserSideNavigationEnabled()); 626 CHECK(IsBrowserSideNavigationEnabled());
583 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 627 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
584 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, info_.type); 628 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, info_.type);
585 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 629 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
586 630
587 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id); 631 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id);
588 DCHECK_NE(MSG_ROUTING_NONE, frame_routing_id); 632 DCHECK_EQ(info_.provider_id, info.provider_id);
633 DCHECK_NE(MSG_ROUTING_NONE, info.route_id);
589 634
590 FinalizeInitialization(process_id, frame_routing_id, dispatcher_host); 635 // Connect with the provider on the renderer.
636 DCHECK(!provider_.is_bound());
637 DCHECK(!binding_.is_bound());
638 provider_.Bind(std::move(info.client_ptr_info));
639 binding_.Bind(std::move(info.host_request));
640 binding_.set_connection_error_handler(
641 base::Bind(&RemoveProviderHost, context_, process_id, provider_id()));
642
643 FinalizeInitialization(process_id, info.route_id, dispatcher_host);
591 } 644 }
592 645
593 void ServiceWorkerProviderHost::SendUpdateFoundMessage( 646 void ServiceWorkerProviderHost::SendUpdateFoundMessage(
594 int registration_handle_id) { 647 int registration_handle_id) {
595 if (!dispatcher_host_) 648 if (!dispatcher_host_)
596 return; // Could be nullptr in some tests. 649 return; // Could be nullptr in some tests.
597 650
598 if (!IsReadyToSendMessages()) { 651 if (!IsReadyToSendMessages()) {
599 queued_events_.push_back( 652 queued_events_.push_back(
600 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, 653 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 render_thread_id_, provider_id(), 828 render_thread_id_, provider_id(),
776 GetOrCreateServiceWorkerHandle( 829 GetOrCreateServiceWorkerHandle(
777 associated_registration_->active_version()), 830 associated_registration_->active_version()),
778 false /* shouldNotifyControllerChange */, 831 false /* shouldNotifyControllerChange */,
779 associated_registration_->active_version()->used_features())); 832 associated_registration_->active_version()->used_features()));
780 } 833 }
781 } 834 }
782 } 835 }
783 836
784 } // namespace content 837 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698