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 12 matching lines...) Expand all Loading... |
23 int process_id, int provider_id, | 23 int process_id, int provider_id, |
24 base::WeakPtr<ServiceWorkerContextCore> context, | 24 base::WeakPtr<ServiceWorkerContextCore> context, |
25 ServiceWorkerDispatcherHost* dispatcher_host) | 25 ServiceWorkerDispatcherHost* dispatcher_host) |
26 : process_id_(process_id), | 26 : process_id_(process_id), |
27 provider_id_(provider_id), | 27 provider_id_(provider_id), |
28 context_(context), | 28 context_(context), |
29 dispatcher_host_(dispatcher_host) { | 29 dispatcher_host_(dispatcher_host) { |
30 } | 30 } |
31 | 31 |
32 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 32 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
| 33 if (controlling_version_) |
| 34 controlling_version_->RemoveControllee(this); |
33 if (active_version_) | 35 if (active_version_) |
34 active_version_->RemoveControllee(this); | 36 active_version_->RemovePotentialControllee(this); |
35 if (waiting_version_) | 37 if (waiting_version_) |
36 waiting_version_->RemovePotentialControllee(this); | 38 waiting_version_->RemovePotentialControllee(this); |
37 if (installing_version_) | 39 if (installing_version_) |
38 installing_version_->RemovePotentialControllee(this); | 40 installing_version_->RemovePotentialControllee(this); |
39 } | 41 } |
40 | 42 |
41 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { | 43 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
42 DCHECK(!url.has_ref()); | 44 DCHECK(!url.has_ref()); |
43 document_url_ = url; | 45 document_url_ = url; |
44 } | 46 } |
45 | 47 |
| 48 void ServiceWorkerProviderHost::SetControllerVersion( |
| 49 ServiceWorkerVersion* version) { |
| 50 DCHECK(CanAssociateVersion(version)); |
| 51 if (version == controlling_version_) |
| 52 return; |
| 53 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
| 54 controlling_version_ = version; |
| 55 if (version) |
| 56 version->AddControllee(this); |
| 57 if (previous_version) |
| 58 previous_version->RemoveControllee(this); |
| 59 |
| 60 if (!dispatcher_host_) |
| 61 return; // Could be NULL in some tests. |
| 62 |
| 63 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 64 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); |
| 65 } |
| 66 |
46 void ServiceWorkerProviderHost::SetActiveVersion( | 67 void ServiceWorkerProviderHost::SetActiveVersion( |
47 ServiceWorkerVersion* version) { | 68 ServiceWorkerVersion* version) { |
48 DCHECK(CanAssociateVersion(version)); | 69 DCHECK(CanAssociateVersion(version)); |
49 if (version == active_version_) | 70 if (version == active_version_) |
50 return; | 71 return; |
51 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; | 72 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; |
52 active_version_ = version; | 73 active_version_ = version; |
53 if (version) | 74 if (version) |
54 version->AddControllee(this); | 75 version->AddPotentialControllee(this); |
55 if (previous_version) | 76 if (previous_version) |
56 previous_version->RemoveControllee(this); | 77 previous_version->RemovePotentialControllee(this); |
57 | 78 |
58 if (!dispatcher_host_) | 79 if (!dispatcher_host_) |
59 return; // Could be NULL in some tests. | 80 return; // Could be NULL in some tests. |
60 | 81 |
61 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 82 dispatcher_host_->Send(new ServiceWorkerMsg_SetActiveServiceWorker( |
62 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); | 83 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); |
63 } | 84 } |
64 | 85 |
65 void ServiceWorkerProviderHost::SetWaitingVersion( | 86 void ServiceWorkerProviderHost::SetWaitingVersion( |
66 ServiceWorkerVersion* version) { | 87 ServiceWorkerVersion* version) { |
67 DCHECK(CanAssociateVersion(version)); | 88 DCHECK(CanAssociateVersion(version)); |
68 if (version == waiting_version_) | 89 if (version == waiting_version_) |
69 return; | 90 return; |
70 scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_; | 91 scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_; |
71 waiting_version_ = version; | 92 waiting_version_ = version; |
(...skipping 30 matching lines...) Expand all Loading... |
102 | 123 |
103 void ServiceWorkerProviderHost::UnsetVersion(ServiceWorkerVersion* version) { | 124 void ServiceWorkerProviderHost::UnsetVersion(ServiceWorkerVersion* version) { |
104 if (!version) | 125 if (!version) |
105 return; | 126 return; |
106 if (installing_version_ == version) | 127 if (installing_version_ == version) |
107 SetInstallingVersion(NULL); | 128 SetInstallingVersion(NULL); |
108 else if (waiting_version_ == version) | 129 else if (waiting_version_ == version) |
109 SetWaitingVersion(NULL); | 130 SetWaitingVersion(NULL); |
110 else if (active_version_ == version) | 131 else if (active_version_ == version) |
111 SetActiveVersion(NULL); | 132 SetActiveVersion(NULL); |
| 133 else if (controlling_version_ == version) |
| 134 SetControllerVersion(NULL); |
112 } | 135 } |
113 | 136 |
114 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 137 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
115 if (!context_) | 138 if (!context_) |
116 return true; // System is shutting down. | 139 return true; // System is shutting down. |
117 if (active_version_) | 140 if (active_version_) |
118 return false; // Unexpected bad message. | 141 return false; // Unexpected bad message. |
119 | 142 |
120 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); | 143 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); |
121 if (!live_version) | 144 if (!live_version) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 bool ServiceWorkerProviderHost::CanAssociateVersion( | 177 bool ServiceWorkerProviderHost::CanAssociateVersion( |
155 ServiceWorkerVersion* version) { | 178 ServiceWorkerVersion* version) { |
156 if (!context_) | 179 if (!context_) |
157 return false; | 180 return false; |
158 if (running_hosted_version_) | 181 if (running_hosted_version_) |
159 return false; | 182 return false; |
160 if (!version) | 183 if (!version) |
161 return true; | 184 return true; |
162 | 185 |
163 ServiceWorkerVersion* already_associated_version = NULL; | 186 ServiceWorkerVersion* already_associated_version = NULL; |
| 187 if (controlling_version_) |
| 188 already_associated_version = controlling_version_; |
164 if (active_version_) | 189 if (active_version_) |
165 already_associated_version = active_version_; | 190 already_associated_version = active_version_; |
166 else if (waiting_version_) | 191 else if (waiting_version_) |
167 already_associated_version = waiting_version_; | 192 already_associated_version = waiting_version_; |
168 else if (installing_version_) | 193 else if (installing_version_) |
169 already_associated_version = installing_version_; | 194 already_associated_version = installing_version_; |
170 | 195 |
171 return !already_associated_version || | 196 return !already_associated_version || |
172 already_associated_version->registration_id() == | 197 already_associated_version->registration_id() == |
173 version->registration_id(); | 198 version->registration_id(); |
(...skipping 29 matching lines...) Expand all Loading... |
203 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); | 228 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); |
204 } | 229 } |
205 return info; | 230 return info; |
206 } | 231 } |
207 | 232 |
208 bool ServiceWorkerProviderHost::IsContextAlive() { | 233 bool ServiceWorkerProviderHost::IsContextAlive() { |
209 return context_ != NULL; | 234 return context_ != NULL; |
210 } | 235 } |
211 | 236 |
212 } // namespace content | 237 } // namespace content |
OLD | NEW |