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

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

Issue 417043006: ServiceWorker: Make SWProviderHost listen to SWRegistration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address michael's comments Created 6 years, 4 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 | Annotate | Revision Log
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 23 matching lines...) Expand all
34 // won't associate the new version with a provider being destroyed. 34 // won't associate the new version with a provider being destroyed.
35 document_url_ = GURL(); 35 document_url_ = GURL();
36 if (controlling_version_) 36 if (controlling_version_)
37 controlling_version_->RemoveControllee(this); 37 controlling_version_->RemoveControllee(this);
38 if (active_version_) 38 if (active_version_)
39 active_version_->RemovePotentialControllee(this); 39 active_version_->RemovePotentialControllee(this);
40 if (waiting_version_) 40 if (waiting_version_)
41 waiting_version_->RemovePotentialControllee(this); 41 waiting_version_->RemovePotentialControllee(this);
42 if (installing_version_) 42 if (installing_version_)
43 installing_version_->RemovePotentialControllee(this); 43 installing_version_->RemovePotentialControllee(this);
44 if (associated_registration_)
45 associated_registration_->RemoveListener(this);
46 }
47
48 void ServiceWorkerProviderHost::OnVersionAttributesChanged(
49 ServiceWorkerRegistration* registration,
50 ChangedVersionAttributesMask changed_mask,
51 const ServiceWorkerRegistrationInfo& info) {
52 if (changed_mask.installing_changed())
53 SetInstallingVersion(registration->installing_version());
54 if (changed_mask.waiting_changed())
55 SetWaitingVersion(registration->waiting_version());
56 if (changed_mask.active_changed())
57 SetActiveVersion(registration->active_version());
58 }
59
60 void ServiceWorkerProviderHost::OnRegistrationFailed(
61 ServiceWorkerRegistration* registration) {
62 DCHECK(associated_registration_);
63 DCHECK_EQ(registration->id(), associated_registration_->id());
64 UnassociateRegistration();
44 } 65 }
45 66
46 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { 67 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) {
47 DCHECK(!url.has_ref()); 68 DCHECK(!url.has_ref());
48 document_url_ = url; 69 document_url_ = url;
49 } 70 }
50 71
51 void ServiceWorkerProviderHost::SetControllerVersion( 72 void ServiceWorkerProviderHost::SetControllerVersion(
52 ServiceWorkerVersion* version) { 73 ServiceWorkerVersion* version) {
53 DCHECK(CanAssociateVersion(version)); 74 DCHECK(CanAssociateVersion(version));
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 info.process_id != process_id_) { 173 info.process_id != process_id_) {
153 // If we aren't trying to start this version in our process 174 // If we aren't trying to start this version in our process
154 // something is amiss. 175 // something is amiss.
155 return false; 176 return false;
156 } 177 }
157 178
158 running_hosted_version_ = live_version; 179 running_hosted_version_ = live_version;
159 return true; 180 return true;
160 } 181 }
161 182
183 void ServiceWorkerProviderHost::AssociateRegistration(
184 ServiceWorkerRegistration* registration) {
185 DCHECK(CanAssociateRegistration(registration));
186 associated_registration_ = registration;
187 registration->AddListener(this);
188
189 SetActiveVersion(registration->active_version());
190 SetInstallingVersion(registration->installing_version());
191 SetWaitingVersion(registration->waiting_version());
192 }
193
194 void ServiceWorkerProviderHost::UnassociateRegistration() {
195 if (!associated_registration_)
196 return;
197 associated_registration_->RemoveListener(this);
198 associated_registration_ = NULL;
199
200 SetActiveVersion(NULL);
201 SetInstallingVersion(NULL);
202 SetWaitingVersion(NULL);
203 SetControllerVersion(NULL);
204 }
205
162 scoped_ptr<ServiceWorkerRequestHandler> 206 scoped_ptr<ServiceWorkerRequestHandler>
163 ServiceWorkerProviderHost::CreateRequestHandler( 207 ServiceWorkerProviderHost::CreateRequestHandler(
164 ResourceType resource_type, 208 ResourceType resource_type,
165 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context) { 209 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context) {
166 if (IsHostToRunningServiceWorker()) { 210 if (IsHostToRunningServiceWorker()) {
167 return scoped_ptr<ServiceWorkerRequestHandler>( 211 return scoped_ptr<ServiceWorkerRequestHandler>(
168 new ServiceWorkerContextRequestHandler( 212 new ServiceWorkerContextRequestHandler(
169 context_, AsWeakPtr(), blob_storage_context, resource_type)); 213 context_, AsWeakPtr(), blob_storage_context, resource_type));
170 } 214 }
171 if (ServiceWorkerUtils::IsMainResourceType(resource_type) || 215 if (ServiceWorkerUtils::IsMainResourceType(resource_type) ||
(...skipping 22 matching lines...) Expand all
194 else if (waiting_version_) 238 else if (waiting_version_)
195 already_associated_version = waiting_version_; 239 already_associated_version = waiting_version_;
196 else if (installing_version_) 240 else if (installing_version_)
197 already_associated_version = installing_version_; 241 already_associated_version = installing_version_;
198 242
199 return !already_associated_version || 243 return !already_associated_version ||
200 already_associated_version->registration_id() == 244 already_associated_version->registration_id() ==
201 version->registration_id(); 245 version->registration_id();
202 } 246 }
203 247
248 bool ServiceWorkerProviderHost::CanAssociateRegistration(
249 ServiceWorkerRegistration* registration) {
250 if (!context_)
251 return false;
252 if (running_hosted_version_)
253 return false;
254 if (!registration || associated_registration_)
255 return false;
256 return true;
257 }
258
204 void ServiceWorkerProviderHost::PostMessage( 259 void ServiceWorkerProviderHost::PostMessage(
205 const base::string16& message, 260 const base::string16& message,
206 const std::vector<int>& sent_message_port_ids) { 261 const std::vector<int>& sent_message_port_ids) {
207 if (!dispatcher_host_) 262 if (!dispatcher_host_)
208 return; // Could be NULL in some tests. 263 return; // Could be NULL in some tests.
209 264
210 std::vector<int> new_routing_ids; 265 std::vector<int> new_routing_ids;
211 dispatcher_host_->message_port_message_filter()-> 266 dispatcher_host_->message_port_message_filter()->
212 UpdateMessagePortsWithNewRoutes(sent_message_port_ids, 267 UpdateMessagePortsWithNewRoutes(sent_message_port_ids,
213 &new_routing_ids); 268 &new_routing_ids);
(...skipping 20 matching lines...) Expand all
234 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); 289 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass());
235 } 290 }
236 return info; 291 return info;
237 } 292 }
238 293
239 bool ServiceWorkerProviderHost::IsContextAlive() { 294 bool ServiceWorkerProviderHost::IsContextAlive() {
240 return context_ != NULL; 295 return context_ != NULL;
241 } 296 }
242 297
243 } // namespace content 298 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698