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

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: remove should_notify_controllerchange flag 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 controlling_version_ = version; 110 controlling_version_ = version;
111 if (version) 111 if (version)
112 version->AddControllee(this); 112 version->AddControllee(this);
113 if (previous_version.get()) 113 if (previous_version.get())
114 previous_version->RemoveControllee(this); 114 previous_version->RemoveControllee(this);
115 115
116 if (!dispatcher_host_) 116 if (!dispatcher_host_)
117 return; // Could be NULL in some tests. 117 return; // Could be NULL in some tests.
118 118
119 bool should_notify_controllerchange = 119 bool should_notify_controllerchange =
120 previous_version && version && version->skip_waiting(); 120 (version && version->claiming_clients()) ||
121 (previous_version && version && version->skip_waiting());
121 122
122 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( 123 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker(
123 kDocumentMainThreadId, provider_id(), 124 kDocumentMainThreadId, provider_id(),
124 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version), 125 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version),
125 should_notify_controllerchange)); 126 should_notify_controllerchange));
126 } 127 }
127 128
128 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 129 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
129 if (!context_) 130 if (!context_)
130 return true; // System is shutting down. 131 return true; // System is shutting down.
131 if (active_version()) 132 if (active_version())
132 return false; // Unexpected bad message. 133 return false; // Unexpected bad message.
133 134
134 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); 135 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id);
135 if (!live_version) 136 if (!live_version)
136 return true; // Was deleted before it got started. 137 return true; // Was deleted before it got started.
137 138
138 ServiceWorkerVersionInfo info = live_version->GetInfo(); 139 ServiceWorkerVersionInfo info = live_version->GetInfo();
139 if (info.running_status != ServiceWorkerVersion::STARTING || 140 if (info.running_status != ServiceWorkerVersion::STARTING ||
140 info.process_id != render_process_id_) { 141 info.process_id != render_process_id_) {
141 // If we aren't trying to start this version in our process 142 // If we aren't trying to start this version in our process
142 // something is amiss. 143 // something is amiss.
143 return false; 144 return false;
144 } 145 }
145 146
146 running_hosted_version_ = live_version; 147 running_hosted_version_ = live_version;
147 return true; 148 return true;
148 } 149 }
149 150
151 void ServiceWorkerProviderHost::UseRegistration(
152 ServiceWorkerRegistration* registration) {
153 DCHECK(registration->active_version());
154 if (associated_registration_ != registration) {
155 if (associated_registration_) {
156 SetControllerVersionAttribute(NULL);
157 DisassociateRegistration();
158 }
159 AssociateRegistration(registration);
160 }
161 SetControllerVersionAttribute(registration->active_version());
162 }
163
150 void ServiceWorkerProviderHost::AssociateRegistration( 164 void ServiceWorkerProviderHost::AssociateRegistration(
151 ServiceWorkerRegistration* registration) { 165 ServiceWorkerRegistration* registration) {
152 DCHECK(CanAssociateRegistration(registration)); 166 DCHECK(CanAssociateRegistration(registration));
153 if (associated_registration_.get())
154 DecreaseProcessReference(associated_registration_->pattern());
155 IncreaseProcessReference(registration->pattern()); 167 IncreaseProcessReference(registration->pattern());
156 168
157 associated_registration_ = registration; 169 associated_registration_ = registration;
158 associated_registration_->AddListener(this); 170 associated_registration_->AddListener(this);
159 SendAssociateRegistrationMessage(); 171 SendAssociateRegistrationMessage();
160 SetControllerVersionAttribute(registration->active_version());
161 } 172 }
162 173
163 void ServiceWorkerProviderHost::DisassociateRegistration() { 174 void ServiceWorkerProviderHost::DisassociateRegistration() {
164 if (!associated_registration_.get()) 175 if (!associated_registration_.get())
165 return; 176 return;
166 DecreaseProcessReference(associated_registration_->pattern()); 177 DecreaseProcessReference(associated_registration_->pattern());
167 associated_registration_->RemoveListener(this); 178 associated_registration_->RemoveListener(this);
168 associated_registration_ = NULL; 179 associated_registration_ = NULL;
169 SetControllerVersionAttribute(NULL);
170 180
171 if (dispatcher_host_) { 181 if (dispatcher_host_) {
172 dispatcher_host_->Send(new ServiceWorkerMsg_DisassociateRegistration( 182 dispatcher_host_->Send(new ServiceWorkerMsg_DisassociateRegistration(
173 kDocumentMainThreadId, provider_id())); 183 kDocumentMainThreadId, provider_id()));
174 } 184 }
175 } 185 }
176 186
177 scoped_ptr<ServiceWorkerRequestHandler> 187 scoped_ptr<ServiceWorkerRequestHandler>
178 ServiceWorkerProviderHost::CreateRequestHandler( 188 ServiceWorkerProviderHost::CreateRequestHandler(
179 FetchRequestMode request_mode, 189 FetchRequestMode request_mode,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 context_->process_manager()->RemoveProcessReferenceFromPattern( 349 context_->process_manager()->RemoveProcessReferenceFromPattern(
340 pattern, render_process_id_); 350 pattern, render_process_id_);
341 } 351 }
342 } 352 }
343 353
344 bool ServiceWorkerProviderHost::IsContextAlive() { 354 bool ServiceWorkerProviderHost::IsContextAlive() {
345 return context_ != NULL; 355 return context_ != NULL;
346 } 356 }
347 357
348 } // namespace content 358 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698