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

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

Issue 702843004: Transfer serviceworker state during cross site navigations too. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "content/browser/message_port_message_filter.h" 8 #include "content/browser/message_port_message_filter.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_context_request_handler. h" 10 #include "content/browser/service_worker/service_worker_context_request_handler. h"
11 #include "content/browser/service_worker/service_worker_controllee_request_handl er.h" 11 #include "content/browser/service_worker/service_worker_controllee_request_handl er.h"
12 #include "content/browser/service_worker/service_worker_dispatcher_host.h" 12 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
13 #include "content/browser/service_worker/service_worker_handle.h" 13 #include "content/browser/service_worker/service_worker_handle.h"
14 #include "content/browser/service_worker/service_worker_registration_handle.h" 14 #include "content/browser/service_worker/service_worker_registration_handle.h"
15 #include "content/browser/service_worker/service_worker_utils.h" 15 #include "content/browser/service_worker/service_worker_utils.h"
16 #include "content/browser/service_worker/service_worker_version.h" 16 #include "content/browser/service_worker/service_worker_version.h"
17 #include "content/common/resource_request_body.h" 17 #include "content/common/resource_request_body.h"
18 #include "content/common/service_worker/service_worker_messages.h" 18 #include "content/common/service_worker/service_worker_messages.h"
19 #include "content/common/service_worker/service_worker_types.h" 19 #include "content/common/service_worker/service_worker_types.h"
20 #include "content/public/common/child_process_host.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 static const int kDocumentMainThreadId = 0; 24 static const int kDocumentMainThreadId = 0;
24 25
25 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 26 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
26 int process_id, int provider_id, 27 int process_id, int provider_id,
27 base::WeakPtr<ServiceWorkerContextCore> context, 28 base::WeakPtr<ServiceWorkerContextCore> context,
28 ServiceWorkerDispatcherHost* dispatcher_host) 29 ServiceWorkerDispatcherHost* dispatcher_host)
29 : process_id_(process_id), 30 : process_id_(process_id),
30 provider_id_(provider_id), 31 provider_id_(provider_id),
31 context_(context), 32 context_(context),
32 dispatcher_host_(dispatcher_host), 33 dispatcher_host_(dispatcher_host),
33 allow_association_(true) { 34 allow_association_(true) {
35 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id_);
34 } 36 }
35 37
36 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { 38 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
37 // Clear docurl so the deferred activation of a waiting worker 39 // Clear docurl so the deferred activation of a waiting worker
38 // won't associate the new version with a provider being destroyed. 40 // won't associate the new version with a provider being destroyed.
39 document_url_ = GURL(); 41 document_url_ = GURL();
40 if (controlling_version_.get()) 42 if (controlling_version_.get())
41 controlling_version_->RemoveControllee(this); 43 controlling_version_->RemoveControllee(this);
42 if (associated_registration_.get()) { 44 if (associated_registration_.get()) {
43 DecreaseProcessReference(associated_registration_->pattern()); 45 DecreaseProcessReference(associated_registration_->pattern());
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 sent_message_port_ids, 209 sent_message_port_ids,
208 new_routing_ids)); 210 new_routing_ids));
209 } 211 }
210 212
211 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( 213 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern(
212 const GURL& pattern) { 214 const GURL& pattern) {
213 associated_patterns_.push_back(pattern); 215 associated_patterns_.push_back(pattern);
214 IncreaseProcessReference(pattern); 216 IncreaseProcessReference(pattern);
215 } 217 }
216 218
219 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() {
220 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id_);
221
222 for (std::vector<GURL>::iterator it = associated_patterns_.begin();
223 it != associated_patterns_.end(); ++it) {
224 DecreaseProcessReference(*it);
225 }
226
227 if (associated_registration_.get()) {
228 scoped_refptr<ServiceWorkerRegistration> registration =
229 associated_registration_;
230 DisassociateRegistration();
231 associated_registration_ = registration;
232 }
233
234 process_id_ = ChildProcessHost::kInvalidUniqueID;
235 provider_id_ = kInvalidServiceWorkerProviderId;
236 dispatcher_host_ = nullptr;
237 }
238
239 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer(
240 int new_process_id,
241 int new_provider_id,
242 ServiceWorkerDispatcherHost* new_dispatcher_host) {
243 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, process_id_);
244 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id);
245
246 process_id_ = new_process_id;
247 provider_id_ = new_provider_id;
248 dispatcher_host_ = new_dispatcher_host;
249
250 for (std::vector<GURL>::iterator it = associated_patterns_.begin();
251 it != associated_patterns_.end(); ++it) {
252 IncreaseProcessReference(*it);
253 }
254
255 if (associated_registration_.get()) {
256 scoped_refptr<ServiceWorkerRegistration> registration;
257 registration.swap(associated_registration_);
258 AssociateRegistration(registration);
259 }
260 }
261
217 ServiceWorkerObjectInfo ServiceWorkerProviderHost::CreateHandleAndPass( 262 ServiceWorkerObjectInfo ServiceWorkerProviderHost::CreateHandleAndPass(
218 ServiceWorkerVersion* version) { 263 ServiceWorkerVersion* version) {
219 ServiceWorkerObjectInfo info; 264 ServiceWorkerObjectInfo info;
220 if (context_ && version) { 265 if (context_ && version) {
221 scoped_ptr<ServiceWorkerHandle> handle = 266 scoped_ptr<ServiceWorkerHandle> handle =
222 ServiceWorkerHandle::Create(context_, 267 ServiceWorkerHandle::Create(context_,
223 dispatcher_host_, 268 dispatcher_host_,
224 kDocumentMainThreadId, 269 kDocumentMainThreadId,
225 provider_id_, 270 provider_id_,
226 version); 271 version);
(...skipping 17 matching lines...) Expand all
244 context_->process_manager()->RemoveProcessReferenceFromPattern( 289 context_->process_manager()->RemoveProcessReferenceFromPattern(
245 pattern, process_id_); 290 pattern, process_id_);
246 } 291 }
247 } 292 }
248 293
249 bool ServiceWorkerProviderHost::IsContextAlive() { 294 bool ServiceWorkerProviderHost::IsContextAlive() {
250 return context_ != NULL; 295 return context_ != NULL;
251 } 296 }
252 297
253 } // namespace content 298 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698