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

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

Issue 871853002: ServiceWorker: add ServiceWorkerClients.claim() support (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change error type Created 5 years, 11 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 "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"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 void ServiceWorkerProviderHost::OnSkippedWaiting( 82 void ServiceWorkerProviderHost::OnSkippedWaiting(
83 ServiceWorkerRegistration* registration) { 83 ServiceWorkerRegistration* registration) {
84 DCHECK_EQ(associated_registration_.get(), registration); 84 DCHECK_EQ(associated_registration_.get(), registration);
85 // A client is "using" a registration if it is controlled by the active 85 // A client is "using" a registration if it is controlled by the active
86 // worker of the registration. skipWaiting doesn't cause a client to start 86 // worker of the registration. skipWaiting doesn't cause a client to start
87 // using the registration. 87 // using the registration.
88 if (!controlling_version_) 88 if (!controlling_version_)
89 return; 89 return;
90 ServiceWorkerVersion* active_version = registration->active_version(); 90 ServiceWorkerVersion* active_version = registration->active_version();
91 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); 91 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING);
92 SetControllerVersionAttribute(active_version); 92 SetControllerVersionAttribute(active_version, true);
falken 2015/01/26 08:45:13 nit: can you add /* should_notify_controller_chang
xiang 2015/01/28 05:38:35 Done.
93 } 93 }
94 94
95 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { 95 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) {
96 DCHECK(!url.has_ref()); 96 DCHECK(!url.has_ref());
97 document_url_ = url; 97 document_url_ = url;
98 } 98 }
99 99
100 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { 100 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) {
101 topmost_frame_url_ = url; 101 topmost_frame_url_ = url;
102 } 102 }
103 103
104 void ServiceWorkerProviderHost::SetControllerVersionAttribute( 104 void ServiceWorkerProviderHost::SetControllerVersionAttribute(
105 ServiceWorkerVersion* version) { 105 ServiceWorkerVersion* version,
106 bool should_notify_controllerchange) {
106 if (version == controlling_version_.get()) 107 if (version == controlling_version_.get())
107 return; 108 return;
108 109
109 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; 110 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_;
110 controlling_version_ = version; 111 controlling_version_ = version;
111 if (version) 112 if (version)
112 version->AddControllee(this); 113 version->AddControllee(this);
113 if (previous_version.get()) 114 if (previous_version.get())
114 previous_version->RemoveControllee(this); 115 previous_version->RemoveControllee(this);
115 116
116 if (!dispatcher_host_) 117 if (!dispatcher_host_)
117 return; // Could be NULL in some tests. 118 return; // Could be NULL in some tests.
118 119
119 bool should_notify_controllerchange =
120 previous_version && version && version->skip_waiting();
121
122 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( 120 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker(
123 kDocumentMainThreadId, provider_id(), 121 kDocumentMainThreadId, provider_id(),
124 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version), 122 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version),
125 should_notify_controllerchange)); 123 should_notify_controllerchange));
126 } 124 }
127 125
128 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 126 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
129 if (!context_) 127 if (!context_)
130 return true; // System is shutting down. 128 return true; // System is shutting down.
131 if (active_version()) 129 if (active_version())
132 return false; // Unexpected bad message. 130 return false; // Unexpected bad message.
133 131
134 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); 132 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id);
135 if (!live_version) 133 if (!live_version)
136 return true; // Was deleted before it got started. 134 return true; // Was deleted before it got started.
137 135
138 ServiceWorkerVersionInfo info = live_version->GetInfo(); 136 ServiceWorkerVersionInfo info = live_version->GetInfo();
139 if (info.running_status != ServiceWorkerVersion::STARTING || 137 if (info.running_status != ServiceWorkerVersion::STARTING ||
140 info.process_id != render_process_id_) { 138 info.process_id != render_process_id_) {
141 // If we aren't trying to start this version in our process 139 // If we aren't trying to start this version in our process
142 // something is amiss. 140 // something is amiss.
143 return false; 141 return false;
144 } 142 }
145 143
146 running_hosted_version_ = live_version; 144 running_hosted_version_ = live_version;
147 return true; 145 return true;
148 } 146 }
149 147
150 void ServiceWorkerProviderHost::AssociateRegistration( 148 void ServiceWorkerProviderHost::AssociateRegistration(
151 ServiceWorkerRegistration* registration) { 149 ServiceWorkerRegistration* registration,
150 bool should_notify_controllerchange) {
152 DCHECK(CanAssociateRegistration(registration)); 151 DCHECK(CanAssociateRegistration(registration));
153 if (associated_registration_.get())
154 DecreaseProcessReference(associated_registration_->pattern());
155 IncreaseProcessReference(registration->pattern()); 152 IncreaseProcessReference(registration->pattern());
156 153
157 associated_registration_ = registration; 154 associated_registration_ = registration;
158 associated_registration_->AddListener(this); 155 associated_registration_->AddListener(this);
159 SendAssociateRegistrationMessage(); 156 SendAssociateRegistrationMessage();
160 SetControllerVersionAttribute(registration->active_version()); 157 SetControllerVersionAttribute(registration->active_version(),
158 should_notify_controllerchange);
161 } 159 }
162 160
163 void ServiceWorkerProviderHost::DisassociateRegistration() { 161 void ServiceWorkerProviderHost::DisassociateRegistration() {
164 if (!associated_registration_.get()) 162 if (!associated_registration_.get())
165 return; 163 return;
166 DecreaseProcessReference(associated_registration_->pattern()); 164 DecreaseProcessReference(associated_registration_->pattern());
167 associated_registration_->RemoveListener(this); 165 associated_registration_->RemoveListener(this);
168 associated_registration_ = NULL; 166 associated_registration_ = NULL;
169 SetControllerVersionAttribute(NULL); 167 SetControllerVersionAttribute(NULL, false);
170 168
171 if (dispatcher_host_) { 169 if (dispatcher_host_) {
172 dispatcher_host_->Send(new ServiceWorkerMsg_DisassociateRegistration( 170 dispatcher_host_->Send(new ServiceWorkerMsg_DisassociateRegistration(
173 kDocumentMainThreadId, provider_id())); 171 kDocumentMainThreadId, provider_id()));
174 } 172 }
175 } 173 }
176 174
177 scoped_ptr<ServiceWorkerRequestHandler> 175 scoped_ptr<ServiceWorkerRequestHandler>
178 ServiceWorkerProviderHost::CreateRequestHandler( 176 ServiceWorkerProviderHost::CreateRequestHandler(
179 FetchRequestMode request_mode, 177 FetchRequestMode request_mode,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 callback)); 241 callback));
244 } 242 }
245 243
246 void ServiceWorkerProviderHost::GetClientInfo( 244 void ServiceWorkerProviderHost::GetClientInfo(
247 int embedded_worker_id, 245 int embedded_worker_id,
248 int request_id) { 246 int request_id) {
249 dispatcher_host_->Send(new ServiceWorkerMsg_GetClientInfo( 247 dispatcher_host_->Send(new ServiceWorkerMsg_GetClientInfo(
250 kDocumentMainThreadId, embedded_worker_id, request_id, provider_id())); 248 kDocumentMainThreadId, embedded_worker_id, request_id, provider_id()));
251 } 249 }
252 250
251 void ServiceWorkerProviderHost::SetController(
252 ServiceWorkerRegistration* registration) {
253 DCHECK(registration->active_version());
254 if (associated_registration_ == registration) {
falken 2015/01/26 08:45:12 when does this happen? if this provider host is as
xiang 2015/01/28 05:38:35 This could happen when a registration associated t
falken 2015/01/28 08:59:49 I see, I was confused and thought SWProviderHost l
255 SetControllerVersionAttribute(registration->active_version(), true);
256 return;
257 }
258 DisassociateRegistration();
259 AssociateRegistration(registration, true);
falken 2015/01/26 08:45:12 /* should_notify_controller_change */
xiang 2015/01/28 05:38:35 Done. We don't need the flags now.
260 }
261
253 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( 262 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern(
254 const GURL& pattern) { 263 const GURL& pattern) {
255 associated_patterns_.push_back(pattern); 264 associated_patterns_.push_back(pattern);
256 IncreaseProcessReference(pattern); 265 IncreaseProcessReference(pattern);
257 } 266 }
258 267
259 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { 268 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() {
260 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); 269 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_);
261 270
262 for (const GURL& pattern : associated_patterns_) 271 for (const GURL& pattern : associated_patterns_)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 context_->process_manager()->RemoveProcessReferenceFromPattern( 348 context_->process_manager()->RemoveProcessReferenceFromPattern(
340 pattern, render_process_id_); 349 pattern, render_process_id_);
341 } 350 }
342 } 351 }
343 352
344 bool ServiceWorkerProviderHost::IsContextAlive() { 353 bool ServiceWorkerProviderHost::IsContextAlive() {
345 return context_ != NULL; 354 return context_ != NULL;
346 } 355 }
347 356
348 } // namespace content 357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698