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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 int render_frame_id, | 50 int render_frame_id, |
51 int provider_id, | 51 int provider_id, |
52 base::WeakPtr<ServiceWorkerContextCore> context, | 52 base::WeakPtr<ServiceWorkerContextCore> context, |
53 ServiceWorkerDispatcherHost* dispatcher_host) | 53 ServiceWorkerDispatcherHost* dispatcher_host) |
54 : render_process_id_(render_process_id), | 54 : render_process_id_(render_process_id), |
55 render_frame_id_(render_frame_id), | 55 render_frame_id_(render_frame_id), |
56 render_thread_id_(kDocumentMainThreadId), | 56 render_thread_id_(kDocumentMainThreadId), |
57 provider_id_(provider_id), | 57 provider_id_(provider_id), |
58 context_(context), | 58 context_(context), |
59 dispatcher_host_(dispatcher_host), | 59 dispatcher_host_(dispatcher_host), |
60 allow_association_(true) { | 60 allow_association_(true), |
| 61 is_claiming_(false) { |
61 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 62 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
62 if (render_frame_id == MSG_ROUTING_NONE) { | 63 if (render_frame_id == MSG_ROUTING_NONE) { |
63 // Actual thread id is set when the worker context gets started. | 64 // Actual thread id is set when the worker context gets started. |
64 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 65 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
65 } | 66 } |
66 } | 67 } |
67 | 68 |
68 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 69 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
69 // Clear docurl so the deferred activation of a waiting worker | 70 // Clear docurl so the deferred activation of a waiting worker |
70 // won't associate the new version with a provider being destroyed. | 71 // won't associate the new version with a provider being destroyed. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 controlling_version_ = version; | 118 controlling_version_ = version; |
118 if (version) | 119 if (version) |
119 version->AddControllee(this); | 120 version->AddControllee(this); |
120 if (previous_version.get()) | 121 if (previous_version.get()) |
121 previous_version->RemoveControllee(this); | 122 previous_version->RemoveControllee(this); |
122 | 123 |
123 if (!dispatcher_host_) | 124 if (!dispatcher_host_) |
124 return; // Could be NULL in some tests. | 125 return; // Could be NULL in some tests. |
125 | 126 |
126 bool should_notify_controllerchange = | 127 bool should_notify_controllerchange = |
127 previous_version && version && version->skip_waiting(); | 128 is_claiming_ || (previous_version && version && version->skip_waiting()); |
128 | 129 |
129 // SetController message should be sent only for the document context. | 130 // SetController message should be sent only for the document context. |
130 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); | 131 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
131 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 132 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
132 render_thread_id_, provider_id(), | 133 render_thread_id_, provider_id(), |
133 CreateAndRegisterServiceWorkerHandle(version), | 134 CreateAndRegisterServiceWorkerHandle(version), |
134 should_notify_controllerchange)); | 135 should_notify_controllerchange)); |
135 } | 136 } |
136 | 137 |
137 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 138 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
(...skipping 14 matching lines...) Expand all Loading... |
152 return false; | 153 return false; |
153 } | 154 } |
154 | 155 |
155 running_hosted_version_ = live_version; | 156 running_hosted_version_ = live_version; |
156 return true; | 157 return true; |
157 } | 158 } |
158 | 159 |
159 void ServiceWorkerProviderHost::AssociateRegistration( | 160 void ServiceWorkerProviderHost::AssociateRegistration( |
160 ServiceWorkerRegistration* registration) { | 161 ServiceWorkerRegistration* registration) { |
161 DCHECK(CanAssociateRegistration(registration)); | 162 DCHECK(CanAssociateRegistration(registration)); |
162 if (associated_registration_.get()) | |
163 DecreaseProcessReference(associated_registration_->pattern()); | |
164 IncreaseProcessReference(registration->pattern()); | 163 IncreaseProcessReference(registration->pattern()); |
165 | |
166 associated_registration_ = registration; | 164 associated_registration_ = registration; |
167 associated_registration_->AddListener(this); | 165 associated_registration_->AddListener(this); |
168 SendAssociateRegistrationMessage(); | 166 SendAssociateRegistrationMessage(); |
169 SetControllerVersionAttribute(registration->active_version()); | 167 SetControllerVersionAttribute(registration->active_version()); |
170 } | 168 } |
171 | 169 |
172 void ServiceWorkerProviderHost::DisassociateRegistration() { | 170 void ServiceWorkerProviderHost::DisassociateRegistration() { |
173 queued_events_.clear(); | 171 queued_events_.clear(); |
174 if (!associated_registration_.get()) | 172 if (!associated_registration_.get()) |
175 return; | 173 return; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 Send(new ServiceWorkerMsg_GetClientInfo( | 273 Send(new ServiceWorkerMsg_GetClientInfo( |
276 kDocumentMainThreadId, embedded_worker_id, request_id, provider_id())); | 274 kDocumentMainThreadId, embedded_worker_id, request_id, provider_id())); |
277 } | 275 } |
278 | 276 |
279 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( | 277 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( |
280 const GURL& pattern) { | 278 const GURL& pattern) { |
281 associated_patterns_.push_back(pattern); | 279 associated_patterns_.push_back(pattern); |
282 IncreaseProcessReference(pattern); | 280 IncreaseProcessReference(pattern); |
283 } | 281 } |
284 | 282 |
| 283 void ServiceWorkerProviderHost::ClaimedByRegistration( |
| 284 ServiceWorkerRegistration* registration) { |
| 285 DCHECK(registration->active_version()); |
| 286 is_claiming_ = true; |
| 287 if (registration == associated_registration_) { |
| 288 SetControllerVersionAttribute(registration->active_version()); |
| 289 } else if (allow_association_) { |
| 290 DisassociateRegistration(); |
| 291 AssociateRegistration(registration); |
| 292 } |
| 293 is_claiming_ = false; |
| 294 } |
| 295 |
285 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { | 296 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { |
286 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 297 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
287 DCHECK_NE(MSG_ROUTING_NONE, render_frame_id_); | 298 DCHECK_NE(MSG_ROUTING_NONE, render_frame_id_); |
288 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); | 299 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
289 | 300 |
290 for (const GURL& pattern : associated_patterns_) | 301 for (const GURL& pattern : associated_patterns_) |
291 DecreaseProcessReference(pattern); | 302 DecreaseProcessReference(pattern); |
292 | 303 |
293 if (associated_registration_.get()) { | 304 if (associated_registration_.get()) { |
294 DecreaseProcessReference(associated_registration_->pattern()); | 305 DecreaseProcessReference(associated_registration_->pattern()); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 return context_ != NULL; | 469 return context_ != NULL; |
459 } | 470 } |
460 | 471 |
461 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { | 472 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { |
462 DCHECK(dispatcher_host_); | 473 DCHECK(dispatcher_host_); |
463 DCHECK(IsReadyToSendMessages()); | 474 DCHECK(IsReadyToSendMessages()); |
464 dispatcher_host_->Send(message); | 475 dispatcher_host_->Send(message); |
465 } | 476 } |
466 | 477 |
467 } // namespace content | 478 } // namespace content |
OLD | NEW |