OLD | NEW |
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // A client is "using" a registration if it is controlled by the active | 85 // A client is "using" a registration if it is controlled by the active |
86 // worker of the registration. skipWaiting doesn't cause a client to start | 86 // worker of the registration. skipWaiting doesn't cause a client to start |
87 // using the registration. | 87 // using the registration. |
88 if (!controlling_version_) | 88 if (!controlling_version_) |
89 return; | 89 return; |
90 ServiceWorkerVersion* active_version = registration->active_version(); | 90 ServiceWorkerVersion* active_version = registration->active_version(); |
91 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); | 91 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); |
92 SetControllerVersionAttribute(active_version); | 92 SetControllerVersionAttribute(active_version); |
93 } | 93 } |
94 | 94 |
| 95 void ServiceWorkerProviderHost::ClaimedByNewVersion() { |
| 96 DCHECK(controlling_version_ != associated_registration_->active_version()); |
| 97 SetControllerVersionAttribute(associated_registration_->active_version()); |
| 98 } |
| 99 |
95 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { | 100 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
96 DCHECK(!url.has_ref()); | 101 DCHECK(!url.has_ref()); |
97 document_url_ = url; | 102 document_url_ = url; |
98 } | 103 } |
99 | 104 |
100 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { | 105 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { |
101 topmost_frame_url_ = url; | 106 topmost_frame_url_ = url; |
102 } | 107 } |
103 | 108 |
104 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 109 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
105 ServiceWorkerVersion* version) { | 110 ServiceWorkerVersion* version) { |
106 if (version == controlling_version_.get()) | 111 if (version == controlling_version_.get()) |
107 return; | 112 return; |
108 | 113 |
109 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; | 114 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
110 controlling_version_ = version; | 115 controlling_version_ = version; |
111 if (version) | 116 if (version) |
112 version->AddControllee(this); | 117 version->AddControllee(this); |
113 if (previous_version.get()) | 118 if (previous_version.get()) |
114 previous_version->RemoveControllee(this); | 119 previous_version->RemoveControllee(this); |
115 | 120 |
116 if (!dispatcher_host_) | 121 if (!dispatcher_host_) |
117 return; // Could be NULL in some tests. | 122 return; // Could be NULL in some tests. |
118 | 123 |
119 bool should_notify_controllerchange = | 124 bool should_notify_controllerchange = |
120 previous_version && version && version->skip_waiting(); | 125 (version && version->claiming_clients()) || |
| 126 (previous_version && version && version->skip_waiting()); |
121 | 127 |
122 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 128 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
123 kDocumentMainThreadId, provider_id(), | 129 kDocumentMainThreadId, provider_id(), |
124 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version), | 130 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version), |
125 should_notify_controllerchange)); | 131 should_notify_controllerchange)); |
126 } | 132 } |
127 | 133 |
128 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 134 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
129 if (!context_) | 135 if (!context_) |
130 return true; // System is shutting down. | 136 return true; // System is shutting down. |
(...skipping 12 matching lines...) Expand all Loading... |
143 return false; | 149 return false; |
144 } | 150 } |
145 | 151 |
146 running_hosted_version_ = live_version; | 152 running_hosted_version_ = live_version; |
147 return true; | 153 return true; |
148 } | 154 } |
149 | 155 |
150 void ServiceWorkerProviderHost::AssociateRegistration( | 156 void ServiceWorkerProviderHost::AssociateRegistration( |
151 ServiceWorkerRegistration* registration) { | 157 ServiceWorkerRegistration* registration) { |
152 DCHECK(CanAssociateRegistration(registration)); | 158 DCHECK(CanAssociateRegistration(registration)); |
153 if (associated_registration_.get()) | |
154 DecreaseProcessReference(associated_registration_->pattern()); | |
155 IncreaseProcessReference(registration->pattern()); | 159 IncreaseProcessReference(registration->pattern()); |
156 | |
157 associated_registration_ = registration; | 160 associated_registration_ = registration; |
158 associated_registration_->AddListener(this); | 161 associated_registration_->AddListener(this); |
159 SendAssociateRegistrationMessage(); | 162 SendAssociateRegistrationMessage(); |
160 SetControllerVersionAttribute(registration->active_version()); | 163 SetControllerVersionAttribute(registration->active_version()); |
161 } | 164 } |
162 | 165 |
163 void ServiceWorkerProviderHost::DisassociateRegistration() { | 166 void ServiceWorkerProviderHost::DisassociateRegistration() { |
164 if (!associated_registration_.get()) | 167 if (!associated_registration_.get()) |
165 return; | 168 return; |
166 DecreaseProcessReference(associated_registration_->pattern()); | 169 DecreaseProcessReference(associated_registration_->pattern()); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 context_->process_manager()->RemoveProcessReferenceFromPattern( | 342 context_->process_manager()->RemoveProcessReferenceFromPattern( |
340 pattern, render_process_id_); | 343 pattern, render_process_id_); |
341 } | 344 } |
342 } | 345 } |
343 | 346 |
344 bool ServiceWorkerProviderHost::IsContextAlive() { | 347 bool ServiceWorkerProviderHost::IsContextAlive() { |
345 return context_ != NULL; | 348 return context_ != NULL; |
346 } | 349 } |
347 | 350 |
348 } // namespace content | 351 } // namespace content |
OLD | NEW |