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

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

Issue 496983002: ServiceWorker: Stop sending the SetVersionAttributes message from SWProviderHost (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
« no previous file with comments | « content/browser/service_worker/service_worker_provider_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 installing_version_->RemovePotentialControllee(this); 45 installing_version_->RemovePotentialControllee(this);
46 if (associated_registration_.get()) 46 if (associated_registration_.get())
47 associated_registration_->RemoveListener(this); 47 associated_registration_->RemoveListener(this);
48 } 48 }
49 49
50 void ServiceWorkerProviderHost::OnVersionAttributesChanged( 50 void ServiceWorkerProviderHost::OnVersionAttributesChanged(
51 ServiceWorkerRegistration* registration, 51 ServiceWorkerRegistration* registration,
52 ChangedVersionAttributesMask changed_mask, 52 ChangedVersionAttributesMask changed_mask,
53 const ServiceWorkerRegistrationInfo& info) { 53 const ServiceWorkerRegistrationInfo& info) {
54 DCHECK_EQ(associated_registration_.get(), registration); 54 DCHECK_EQ(associated_registration_.get(), registration);
55 SetVersionAttributes(registration->installing_version(), 55 UpdatePotentialControllees(registration->installing_version(),
56 registration->waiting_version(), 56 registration->waiting_version(),
57 registration->active_version()); 57 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 UnassociateRegistration();
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::SetVersionAttributes( 71 void ServiceWorkerProviderHost::UpdatePotentialControllees(
72 ServiceWorkerVersion* installing_version, 72 ServiceWorkerVersion* installing_version,
73 ServiceWorkerVersion* waiting_version, 73 ServiceWorkerVersion* waiting_version,
74 ServiceWorkerVersion* active_version) { 74 ServiceWorkerVersion* active_version) {
75 ChangedVersionAttributesMask mask; 75 if (installing_version != installing_version_.get()) {
76 scoped_refptr<ServiceWorkerVersion> previous_version = installing_version_;
77 if (previous_version)
78 previous_version->RemovePotentialControllee(this);
79 if (installing_version)
80 installing_version->AddPotentialControllee(this);
81 installing_version_ = installing_version;
82 }
76 83
77 if (installing_version != installing_version_.get()) { 84 if (waiting_version != waiting_version_.get()) {
78 SetVersionAttributesInternal(installing_version, &installing_version_); 85 scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_;
79 mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); 86 if (previous_version)
80 } 87 previous_version->RemovePotentialControllee(this);
81 if (waiting_version != waiting_version_.get()) { 88 if (waiting_version)
82 SetVersionAttributesInternal(waiting_version, &waiting_version_); 89 waiting_version->AddPotentialControllee(this);
83 mask.add(ChangedVersionAttributesMask::WAITING_VERSION); 90 waiting_version_ = waiting_version;
84 } 91 }
85 if (active_version != active_version_.get()) {
86 SetVersionAttributesInternal(active_version, &active_version_);
87 mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION);
88 }
89 92
90 if (!dispatcher_host_) 93 if (active_version != active_version_.get()) {
91 return; // Could be NULL in some tests. 94 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_;
92 if (!mask.changed()) 95 if (previous_version)
93 return; 96 previous_version->RemovePotentialControllee(this);
94 97 if (active_version)
95 ServiceWorkerVersionAttributes attributes; 98 active_version->AddPotentialControllee(this);
96 if (mask.installing_changed()) 99 active_version_ = active_version;
97 attributes.installing = CreateHandleAndPass(installing_version); 100 }
98 if (mask.waiting_changed())
99 attributes.waiting = CreateHandleAndPass(waiting_version);
100 if (mask.active_changed())
101 attributes.active = CreateHandleAndPass(active_version);
102
103 dispatcher_host_->Send(new ServiceWorkerMsg_SetVersionAttributes(
104 kDocumentMainThreadId,
105 provider_id(),
106 kInvalidServiceWorkerRegistrationHandleId,
107 mask.changed(),
108 attributes));
109 }
110
111 void ServiceWorkerProviderHost::SetVersionAttributesInternal(
112 ServiceWorkerVersion* version,
113 scoped_refptr<ServiceWorkerVersion>* data_member) {
114 scoped_refptr<ServiceWorkerVersion> previous_version = *data_member;
115 *data_member = version;
116 if (version)
117 version->AddPotentialControllee(this);
118 if (previous_version.get())
119 previous_version->RemovePotentialControllee(this);
120 } 101 }
121 102
122 void ServiceWorkerProviderHost::SetControllerVersionAttribute( 103 void ServiceWorkerProviderHost::SetControllerVersionAttribute(
123 ServiceWorkerVersion* version) { 104 ServiceWorkerVersion* version) {
124 if (version == controlling_version_.get()) 105 if (version == controlling_version_.get())
125 return; 106 return;
126 107
127 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; 108 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_;
128 controlling_version_ = version; 109 controlling_version_ = version;
129 if (version) 110 if (version)
130 version->AddControllee(this); 111 version->AddControllee(this);
131 if (previous_version.get()) 112 if (previous_version.get())
132 previous_version->RemoveControllee(this); 113 previous_version->RemoveControllee(this);
133 114
134 if (!dispatcher_host_) 115 if (!dispatcher_host_)
135 return; // Could be NULL in some tests. 116 return; // Could be NULL in some tests.
136 117
137 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( 118 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker(
138 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); 119 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version)));
139 } 120 }
140 121
141 void ServiceWorkerProviderHost::ClearVersionAttributes() {
142 SetVersionAttributes(NULL, NULL, NULL);
143 SetControllerVersionAttribute(NULL);
144 }
145
146 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 122 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
147 if (!context_) 123 if (!context_)
148 return true; // System is shutting down. 124 return true; // System is shutting down.
149 if (active_version_.get()) 125 if (active_version_.get())
150 return false; // Unexpected bad message. 126 return false; // Unexpected bad message.
151 127
152 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); 128 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id);
153 if (!live_version) 129 if (!live_version)
154 return true; // Was deleted before it got started. 130 return true; // Was deleted before it got started.
155 131
156 ServiceWorkerVersionInfo info = live_version->GetInfo(); 132 ServiceWorkerVersionInfo info = live_version->GetInfo();
157 if (info.running_status != ServiceWorkerVersion::STARTING || 133 if (info.running_status != ServiceWorkerVersion::STARTING ||
158 info.process_id != process_id_) { 134 info.process_id != process_id_) {
159 // If we aren't trying to start this version in our process 135 // If we aren't trying to start this version in our process
160 // something is amiss. 136 // something is amiss.
161 return false; 137 return false;
162 } 138 }
163 139
164 running_hosted_version_ = live_version; 140 running_hosted_version_ = live_version;
165 return true; 141 return true;
166 } 142 }
167 143
168 void ServiceWorkerProviderHost::AssociateRegistration( 144 void ServiceWorkerProviderHost::AssociateRegistration(
169 ServiceWorkerRegistration* registration) { 145 ServiceWorkerRegistration* registration) {
170 DCHECK(CanAssociateRegistration(registration)); 146 DCHECK(CanAssociateRegistration(registration));
171 associated_registration_ = registration; 147 associated_registration_ = registration;
172 registration->AddListener(this); 148 registration->AddListener(this);
173 SetVersionAttributes(registration->installing_version(), 149 UpdatePotentialControllees(registration->installing_version(),
174 registration->waiting_version(), 150 registration->waiting_version(),
175 registration->active_version()); 151 registration->active_version());
176 SetControllerVersionAttribute(registration->active_version()); 152 SetControllerVersionAttribute(registration->active_version());
177 } 153 }
178 154
179 void ServiceWorkerProviderHost::UnassociateRegistration() { 155 void ServiceWorkerProviderHost::UnassociateRegistration() {
180 if (!associated_registration_.get()) 156 if (!associated_registration_.get())
181 return; 157 return;
182 associated_registration_->RemoveListener(this); 158 associated_registration_->RemoveListener(this);
183 associated_registration_ = NULL; 159 associated_registration_ = NULL;
184 ClearVersionAttributes(); 160 UpdatePotentialControllees(NULL, NULL, NULL);
161 SetControllerVersionAttribute(NULL);
185 } 162 }
186 163
187 scoped_ptr<ServiceWorkerRequestHandler> 164 scoped_ptr<ServiceWorkerRequestHandler>
188 ServiceWorkerProviderHost::CreateRequestHandler( 165 ServiceWorkerProviderHost::CreateRequestHandler(
189 ResourceType resource_type, 166 ResourceType resource_type,
190 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 167 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
191 scoped_refptr<ResourceRequestBody> body) { 168 scoped_refptr<ResourceRequestBody> body) {
192 if (IsHostToRunningServiceWorker()) { 169 if (IsHostToRunningServiceWorker()) {
193 return scoped_ptr<ServiceWorkerRequestHandler>( 170 return scoped_ptr<ServiceWorkerRequestHandler>(
194 new ServiceWorkerContextRequestHandler( 171 new ServiceWorkerContextRequestHandler(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); 224 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass());
248 } 225 }
249 return info; 226 return info;
250 } 227 }
251 228
252 bool ServiceWorkerProviderHost::IsContextAlive() { 229 bool ServiceWorkerProviderHost::IsContextAlive() {
253 return context_ != NULL; 230 return context_ != NULL;
254 } 231 }
255 232
256 } // namespace content 233 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_provider_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698