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

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

Issue 2653493009: Add two interfaces for ServiceWorkerProviderContext/ProviderHost (Closed)
Patch Set: Skip unittest for CrossSiteTransfer when PlzNavigate 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 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(
552 render_thread_id_, provider_id())); 588 render_thread_id_, provider_id()));
553 } 589 }
554 } 590 }
555 591
556 render_process_id_ = ChildProcessHost::kInvalidUniqueID; 592 render_process_id_ = ChildProcessHost::kInvalidUniqueID;
557 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; 593 render_thread_id_ = kInvalidEmbeddedWorkerThreadId;
558 dispatcher_host_ = nullptr; 594 dispatcher_host_ = nullptr;
559 return provisional_host; 595 return provisional_host;
560 } 596 }
561 597
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_ = std::move(provisional_host->info_); 605 info_ = std::move(provisional_host->info_);
570 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 provider_id()));
615
571 FinalizeInitialization(provisional_host->process_id(), 616 FinalizeInitialization(provisional_host->process_id(),
572 provisional_host->dispatcher_host()); 617 provisional_host->dispatcher_host());
573 } 618 }
574 619
575 // PlzNavigate 620 // PlzNavigate
576 void ServiceWorkerProviderHost::CompleteNavigationInitialized( 621 void ServiceWorkerProviderHost::CompleteNavigationInitialized(
577 int process_id, 622 int process_id,
578 int frame_routing_id, 623 ServiceWorkerProviderHostInfo info,
579 ServiceWorkerDispatcherHost* dispatcher_host) { 624 ServiceWorkerDispatcherHost* dispatcher_host) {
580 CHECK(IsBrowserSideNavigationEnabled()); 625 CHECK(IsBrowserSideNavigationEnabled());
581 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 626 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
582 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, info_.type); 627 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, info_.type);
583 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 628 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
584 629
585 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id); 630 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id);
586 DCHECK_NE(MSG_ROUTING_NONE, frame_routing_id); 631 DCHECK_EQ(info_.provider_id, info.provider_id);
632 DCHECK_NE(MSG_ROUTING_NONE, info.route_id);
587 633
588 info_.route_id = frame_routing_id; 634 // Connect with the provider on the renderer.
635 DCHECK(!provider_.is_bound());
636 DCHECK(!binding_.is_bound());
637 provider_.Bind(std::move(info.client_ptr_info));
638 binding_.Bind(std::move(info.host_request));
639 binding_.set_connection_error_handler(
640 base::Bind(&RemoveProviderHost, context_, process_id, provider_id()));
641 info_.route_id = info.route_id;
642
589 FinalizeInitialization(process_id, dispatcher_host); 643 FinalizeInitialization(process_id, dispatcher_host);
590 } 644 }
591 645
592 void ServiceWorkerProviderHost::SendUpdateFoundMessage( 646 void ServiceWorkerProviderHost::SendUpdateFoundMessage(
593 int registration_handle_id) { 647 int registration_handle_id) {
594 if (!dispatcher_host_) 648 if (!dispatcher_host_)
595 return; // Could be nullptr in some tests. 649 return; // Could be nullptr in some tests.
596 650
597 if (!IsReadyToSendMessages()) { 651 if (!IsReadyToSendMessages()) {
598 queued_events_.push_back( 652 queued_events_.push_back(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 render_thread_id_, provider_id(), 826 render_thread_id_, provider_id(),
773 GetOrCreateServiceWorkerHandle( 827 GetOrCreateServiceWorkerHandle(
774 associated_registration_->active_version()), 828 associated_registration_->active_version()),
775 false /* shouldNotifyControllerChange */, 829 false /* shouldNotifyControllerChange */,
776 associated_registration_->active_version()->used_features())); 830 associated_registration_->active_version()->used_features()));
777 } 831 }
778 } 832 }
779 } 833 }
780 834
781 } // namespace content 835 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698