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

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

Issue 1050733002: ServiceWorker: Clean up ServiceWorkerVersion::OnGetClients (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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/guid.h" 7 #include "base/guid.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/browser/frame_host/frame_tree.h" 9 #include "content/browser/frame_host/frame_tree.h"
10 #include "content/browser/frame_host/frame_tree_node.h" 10 #include "content/browser/frame_host/frame_tree_node.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 controlling_version_ = version; 173 controlling_version_ = version;
174 if (version) 174 if (version)
175 version->AddControllee(this); 175 version->AddControllee(this);
176 if (previous_version.get()) 176 if (previous_version.get())
177 previous_version->RemoveControllee(this); 177 previous_version->RemoveControllee(this);
178 178
179 if (!dispatcher_host_) 179 if (!dispatcher_host_)
180 return; // Could be NULL in some tests. 180 return; // Could be NULL in some tests.
181 181
182 // SetController message should be sent only for controllees. 182 // SetController message should be sent only for controllees.
183 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); 183 DCHECK(IsProviderForClient());
184 Send(new ServiceWorkerMsg_SetControllerServiceWorker( 184 Send(new ServiceWorkerMsg_SetControllerServiceWorker(
185 render_thread_id_, provider_id(), 185 render_thread_id_, provider_id(),
186 CreateAndRegisterServiceWorkerHandle(version), notify_controllerchange)); 186 CreateAndRegisterServiceWorkerHandle(version), notify_controllerchange));
187 } 187 }
188 188
189 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 189 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
190 if (!context_) 190 if (!context_)
191 return true; // System is shutting down. 191 return true; // System is shutting down.
192 if (active_version()) 192 if (active_version())
193 return false; // Unexpected bad message. 193 return false; // Unexpected bad message.
194 194
195 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); 195 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id);
196 if (!live_version) 196 if (!live_version)
197 return true; // Was deleted before it got started. 197 return true; // Was deleted before it got started.
198 198
199 ServiceWorkerVersionInfo info = live_version->GetInfo(); 199 ServiceWorkerVersionInfo info = live_version->GetInfo();
200 if (info.running_status != ServiceWorkerVersion::STARTING || 200 if (info.running_status != ServiceWorkerVersion::STARTING ||
201 info.process_id != render_process_id_) { 201 info.process_id != render_process_id_) {
202 // If we aren't trying to start this version in our process 202 // If we aren't trying to start this version in our process
203 // something is amiss. 203 // something is amiss.
204 return false; 204 return false;
205 } 205 }
206 206
207 running_hosted_version_ = live_version; 207 running_hosted_version_ = live_version;
208 return true; 208 return true;
209 } 209 }
210 210
211 bool ServiceWorkerProviderHost::IsProviderForClient() const {
212 switch (provider_type_) {
213 case SERVICE_WORKER_PROVIDER_FOR_WINDOW:
214 case SERVICE_WORKER_PROVIDER_FOR_WORKER:
215 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER:
216 return true;
217 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER:
218 case SERVICE_WORKER_PROVIDER_UNKNOWN:
219 return false;
220 }
221 NOTREACHED() << provider_type_;
222 return false;
223 }
224
211 blink::WebServiceWorkerClientType ServiceWorkerProviderHost::client_type() 225 blink::WebServiceWorkerClientType ServiceWorkerProviderHost::client_type()
212 const { 226 const {
213 switch (provider_type_) { 227 switch (provider_type_) {
214 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: 228 case SERVICE_WORKER_PROVIDER_FOR_WINDOW:
215 return blink::WebServiceWorkerClientTypeWindow; 229 return blink::WebServiceWorkerClientTypeWindow;
216 case SERVICE_WORKER_PROVIDER_FOR_WORKER: 230 case SERVICE_WORKER_PROVIDER_FOR_WORKER:
217 return blink::WebServiceWorkerClientTypeWorker; 231 return blink::WebServiceWorkerClientTypeWorker;
218 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: 232 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER:
219 return blink::WebServiceWorkerClientTypeSharedWorker; 233 return blink::WebServiceWorkerClientTypeSharedWorker;
220 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: 234 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER:
(...skipping 19 matching lines...) Expand all
240 queued_events_.clear(); 254 queued_events_.clear();
241 if (!associated_registration_.get()) 255 if (!associated_registration_.get())
242 return; 256 return;
243 associated_registration_ = NULL; 257 associated_registration_ = NULL;
244 SetControllerVersionAttribute(NULL, false /* notify_controllerchange */); 258 SetControllerVersionAttribute(NULL, false /* notify_controllerchange */);
245 259
246 if (!dispatcher_host_) 260 if (!dispatcher_host_)
247 return; 261 return;
248 262
249 // Disassociation message should be sent only for controllees. 263 // Disassociation message should be sent only for controllees.
250 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); 264 DCHECK(IsProviderForClient());
251 Send(new ServiceWorkerMsg_DisassociateRegistration( 265 Send(new ServiceWorkerMsg_DisassociateRegistration(
252 render_thread_id_, provider_id())); 266 render_thread_id_, provider_id()));
253 } 267 }
254 268
255 void ServiceWorkerProviderHost::AddMatchingRegistration( 269 void ServiceWorkerProviderHost::AddMatchingRegistration(
256 ServiceWorkerRegistration* registration) { 270 ServiceWorkerRegistration* registration) {
257 DCHECK(ServiceWorkerUtils::ScopeMatches( 271 DCHECK(ServiceWorkerUtils::ScopeMatches(
258 registration->pattern(), document_url_)); 272 registration->pattern(), document_url_));
259 size_t key = registration->pattern().spec().size(); 273 size_t key = registration->pattern().spec().size();
260 if (ContainsKey(matching_registrations_, key)) 274 if (ContainsKey(matching_registrations_, key))
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 594
581 ServiceWorkerVersionAttributes attrs; 595 ServiceWorkerVersionAttributes attrs;
582 attrs.installing = CreateAndRegisterServiceWorkerHandle( 596 attrs.installing = CreateAndRegisterServiceWorkerHandle(
583 associated_registration_->installing_version()); 597 associated_registration_->installing_version());
584 attrs.waiting = CreateAndRegisterServiceWorkerHandle( 598 attrs.waiting = CreateAndRegisterServiceWorkerHandle(
585 associated_registration_->waiting_version()); 599 associated_registration_->waiting_version());
586 attrs.active = CreateAndRegisterServiceWorkerHandle( 600 attrs.active = CreateAndRegisterServiceWorkerHandle(
587 associated_registration_->active_version()); 601 associated_registration_->active_version());
588 602
589 // Association message should be sent only for controllees. 603 // Association message should be sent only for controllees.
590 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); 604 DCHECK(IsProviderForClient());
591 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( 605 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration(
592 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); 606 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs));
593 } 607 }
594 608
595 void ServiceWorkerProviderHost::IncreaseProcessReference( 609 void ServiceWorkerProviderHost::IncreaseProcessReference(
596 const GURL& pattern) { 610 const GURL& pattern) {
597 if (context_ && context_->process_manager()) { 611 if (context_ && context_->process_manager()) {
598 context_->process_manager()->AddProcessReferenceToPattern( 612 context_->process_manager()->AddProcessReferenceToPattern(
599 pattern, render_process_id_); 613 pattern, render_process_id_);
600 } 614 }
(...skipping 29 matching lines...) Expand all
630 return context_ != NULL; 644 return context_ != NULL;
631 } 645 }
632 646
633 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { 647 void ServiceWorkerProviderHost::Send(IPC::Message* message) const {
634 DCHECK(dispatcher_host_); 648 DCHECK(dispatcher_host_);
635 DCHECK(IsReadyToSendMessages()); 649 DCHECK(IsReadyToSendMessages());
636 dispatcher_host_->Send(message); 650 dispatcher_host_->Send(message);
637 } 651 }
638 652
639 } // namespace content 653 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_provider_host.h ('k') | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698