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

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

Issue 477593007: ServiceWorker: Make '.ready' return a promise to be resolved with ServiceWorkerRegistration (2/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 3 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 const ServiceWorkerRegistrationInfo& info) { 53 const ServiceWorkerRegistrationInfo& info) {
54 DCHECK_EQ(associated_registration_.get(), registration); 54 DCHECK_EQ(associated_registration_.get(), registration);
55 installing_version_ = registration->installing_version(); 55 installing_version_ = registration->installing_version();
56 waiting_version_ = registration->waiting_version(); 56 waiting_version_ = registration->waiting_version();
57 active_version_ = registration->active_version(); 57 active_version_ = registration->active_version();
58 } 58 }
59 59
60 void ServiceWorkerProviderHost::OnRegistrationFailed( 60 void ServiceWorkerProviderHost::OnRegistrationFailed(
61 ServiceWorkerRegistration* registration) { 61 ServiceWorkerRegistration* registration) {
62 DCHECK_EQ(associated_registration_.get(), registration); 62 DCHECK_EQ(associated_registration_.get(), registration);
63 UnassociateRegistration(); 63 DisassociateRegistration();
64 } 64 }
65 65
66 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { 66 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) {
67 DCHECK(!url.has_ref()); 67 DCHECK(!url.has_ref());
68 document_url_ = url; 68 document_url_ = url;
69 } 69 }
70 70
71 void ServiceWorkerProviderHost::SetControllerVersionAttribute( 71 void ServiceWorkerProviderHost::SetControllerVersionAttribute(
72 ServiceWorkerVersion* version) { 72 ServiceWorkerVersion* version) {
73 if (version == controlling_version_.get()) 73 if (version == controlling_version_.get())
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return true; 109 return true;
110 } 110 }
111 111
112 void ServiceWorkerProviderHost::AssociateRegistration( 112 void ServiceWorkerProviderHost::AssociateRegistration(
113 ServiceWorkerRegistration* registration) { 113 ServiceWorkerRegistration* registration) {
114 DCHECK(CanAssociateRegistration(registration)); 114 DCHECK(CanAssociateRegistration(registration));
115 if (associated_registration_.get()) 115 if (associated_registration_.get())
116 DecreaseProcessReference(associated_registration_->pattern()); 116 DecreaseProcessReference(associated_registration_->pattern());
117 IncreaseProcessReference(registration->pattern()); 117 IncreaseProcessReference(registration->pattern());
118 118
119 if (dispatcher_host_) {
120 ServiceWorkerRegistrationHandle* handle =
121 dispatcher_host_->GetOrCreateRegistrationHandle(
122 provider_id(), registration);
123
124 ServiceWorkerVersionAttributes attrs;
125 attrs.installing = handle->CreateServiceWorkerHandleAndPass(
126 registration->installing_version());
127 attrs.waiting = handle->CreateServiceWorkerHandleAndPass(
128 registration->waiting_version());
129 attrs.active = handle->CreateServiceWorkerHandleAndPass(
130 registration->active_version());
131
132 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration(
133 kDocumentMainThreadId, provider_id(), handle->GetObjectInfo(), attrs));
134 }
135
119 associated_registration_ = registration; 136 associated_registration_ = registration;
120 registration->AddListener(this); 137 associated_registration_->AddListener(this);
121 installing_version_ = registration->installing_version(); 138 installing_version_ = registration->installing_version();
122 waiting_version_ = registration->waiting_version(); 139 waiting_version_ = registration->waiting_version();
123 active_version_ = registration->active_version(); 140 active_version_ = registration->active_version();
124 SetControllerVersionAttribute(registration->active_version()); 141 SetControllerVersionAttribute(registration->active_version());
125 } 142 }
126 143
127 void ServiceWorkerProviderHost::UnassociateRegistration() { 144 void ServiceWorkerProviderHost::DisassociateRegistration() {
128 if (!associated_registration_.get()) 145 if (!associated_registration_.get())
129 return; 146 return;
130 DecreaseProcessReference(associated_registration_->pattern()); 147 DecreaseProcessReference(associated_registration_->pattern());
131 associated_registration_->RemoveListener(this); 148 associated_registration_->RemoveListener(this);
132 associated_registration_ = NULL; 149 associated_registration_ = NULL;
133 installing_version_ = NULL; 150 installing_version_ = NULL;
134 waiting_version_ = NULL; 151 waiting_version_ = NULL;
135 active_version_ = NULL; 152 active_version_ = NULL;
136 SetControllerVersionAttribute(NULL); 153 SetControllerVersionAttribute(NULL);
154
155 if (dispatcher_host_) {
156 dispatcher_host_->Send(new ServiceWorkerMsg_DisassociateRegistration(
157 kDocumentMainThreadId, provider_id()));
158 }
137 } 159 }
138 160
139 scoped_ptr<ServiceWorkerRequestHandler> 161 scoped_ptr<ServiceWorkerRequestHandler>
140 ServiceWorkerProviderHost::CreateRequestHandler( 162 ServiceWorkerProviderHost::CreateRequestHandler(
141 ResourceType resource_type, 163 ResourceType resource_type,
142 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 164 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
143 scoped_refptr<ResourceRequestBody> body) { 165 scoped_refptr<ResourceRequestBody> body) {
144 if (IsHostToRunningServiceWorker()) { 166 if (IsHostToRunningServiceWorker()) {
145 return scoped_ptr<ServiceWorkerRequestHandler>( 167 return scoped_ptr<ServiceWorkerRequestHandler>(
146 new ServiceWorkerContextRequestHandler( 168 new ServiceWorkerContextRequestHandler(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 context_->process_manager()->RemoveProcessReferenceFromPattern( 243 context_->process_manager()->RemoveProcessReferenceFromPattern(
222 pattern, process_id_); 244 pattern, process_id_);
223 } 245 }
224 } 246 }
225 247
226 bool ServiceWorkerProviderHost::IsContextAlive() { 248 bool ServiceWorkerProviderHost::IsContextAlive() {
227 return context_ != NULL; 249 return context_ != NULL;
228 } 250 }
229 251
230 } // namespace content 252 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698