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 19 matching lines...) Expand all Loading... |
30 context_(context), | 30 context_(context), |
31 dispatcher_host_(dispatcher_host) { | 31 dispatcher_host_(dispatcher_host) { |
32 } | 32 } |
33 | 33 |
34 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 34 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
35 // Clear docurl so the deferred activation of a waiting worker | 35 // Clear docurl so the deferred activation of a waiting worker |
36 // won't associate the new version with a provider being destroyed. | 36 // won't associate the new version with a provider being destroyed. |
37 document_url_ = GURL(); | 37 document_url_ = GURL(); |
38 if (controlling_version_.get()) | 38 if (controlling_version_.get()) |
39 controlling_version_->RemoveControllee(this); | 39 controlling_version_->RemoveControllee(this); |
40 if (active_version_.get()) | 40 if (associated_registration_.get()) { |
41 active_version_->RemovePotentialControllee(this); | 41 DecreaseProcessReference(associated_registration_); |
42 if (waiting_version_.get()) | |
43 waiting_version_->RemovePotentialControllee(this); | |
44 if (installing_version_.get()) | |
45 installing_version_->RemovePotentialControllee(this); | |
46 if (associated_registration_.get()) | |
47 associated_registration_->RemoveListener(this); | 42 associated_registration_->RemoveListener(this); |
| 43 } |
| 44 for (std::vector<scoped_refptr<ServiceWorkerRegistration> >::iterator it = |
| 45 pending_registrations_.begin(); |
| 46 it != pending_registrations_.end(); ++it) { |
| 47 DecreaseProcessReference(it->get()); |
| 48 } |
48 } | 49 } |
49 | 50 |
50 void ServiceWorkerProviderHost::OnVersionAttributesChanged( | 51 void ServiceWorkerProviderHost::OnVersionAttributesChanged( |
51 ServiceWorkerRegistration* registration, | 52 ServiceWorkerRegistration* registration, |
52 ChangedVersionAttributesMask changed_mask, | 53 ChangedVersionAttributesMask changed_mask, |
53 const ServiceWorkerRegistrationInfo& info) { | 54 const ServiceWorkerRegistrationInfo& info) { |
54 DCHECK_EQ(associated_registration_.get(), registration); | 55 DCHECK_EQ(associated_registration_.get(), registration); |
55 UpdatePotentialControllees(registration->installing_version(), | 56 installing_version_ = registration->installing_version(); |
56 registration->waiting_version(), | 57 waiting_version_ = registration->waiting_version(); |
57 registration->active_version()); | 58 active_version_ = registration->active_version(); |
58 } | 59 } |
59 | 60 |
60 void ServiceWorkerProviderHost::OnRegistrationFailed( | 61 void ServiceWorkerProviderHost::OnRegistrationFailed( |
61 ServiceWorkerRegistration* registration) { | 62 ServiceWorkerRegistration* registration) { |
62 DCHECK_EQ(associated_registration_.get(), registration); | 63 DCHECK_EQ(associated_registration_.get(), registration); |
63 UnassociateRegistration(); | 64 UnassociateRegistration(); |
64 } | 65 } |
65 | 66 |
66 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { | 67 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
67 DCHECK(!url.has_ref()); | 68 DCHECK(!url.has_ref()); |
68 document_url_ = url; | 69 document_url_ = url; |
69 } | 70 } |
70 | 71 |
71 void ServiceWorkerProviderHost::UpdatePotentialControllees( | |
72 ServiceWorkerVersion* installing_version, | |
73 ServiceWorkerVersion* waiting_version, | |
74 ServiceWorkerVersion* active_version) { | |
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 } | |
83 | |
84 if (waiting_version != waiting_version_.get()) { | |
85 scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_; | |
86 if (previous_version) | |
87 previous_version->RemovePotentialControllee(this); | |
88 if (waiting_version) | |
89 waiting_version->AddPotentialControllee(this); | |
90 waiting_version_ = waiting_version; | |
91 } | |
92 | |
93 if (active_version != active_version_.get()) { | |
94 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; | |
95 if (previous_version) | |
96 previous_version->RemovePotentialControllee(this); | |
97 if (active_version) | |
98 active_version->AddPotentialControllee(this); | |
99 active_version_ = active_version; | |
100 } | |
101 } | |
102 | |
103 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 72 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
104 ServiceWorkerVersion* version) { | 73 ServiceWorkerVersion* version) { |
105 if (version == controlling_version_.get()) | 74 if (version == controlling_version_.get()) |
106 return; | 75 return; |
107 | 76 |
108 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; | 77 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
109 controlling_version_ = version; | 78 controlling_version_ = version; |
110 if (version) | 79 if (version) |
111 version->AddControllee(this); | 80 version->AddControllee(this); |
112 if (previous_version.get()) | 81 if (previous_version.get()) |
(...skipping 24 matching lines...) Expand all Loading... |
137 return false; | 106 return false; |
138 } | 107 } |
139 | 108 |
140 running_hosted_version_ = live_version; | 109 running_hosted_version_ = live_version; |
141 return true; | 110 return true; |
142 } | 111 } |
143 | 112 |
144 void ServiceWorkerProviderHost::AssociateRegistration( | 113 void ServiceWorkerProviderHost::AssociateRegistration( |
145 ServiceWorkerRegistration* registration) { | 114 ServiceWorkerRegistration* registration) { |
146 DCHECK(CanAssociateRegistration(registration)); | 115 DCHECK(CanAssociateRegistration(registration)); |
| 116 if (associated_registration_.get()) |
| 117 DecreaseProcessReference(associated_registration_); |
| 118 IncreaseProcessReference(registration); |
| 119 |
147 associated_registration_ = registration; | 120 associated_registration_ = registration; |
148 registration->AddListener(this); | 121 registration->AddListener(this); |
149 UpdatePotentialControllees(registration->installing_version(), | 122 installing_version_ = registration->installing_version(); |
150 registration->waiting_version(), | 123 waiting_version_ = registration->waiting_version(); |
151 registration->active_version()); | 124 active_version_ = registration->active_version(); |
152 SetControllerVersionAttribute(registration->active_version()); | 125 SetControllerVersionAttribute(registration->active_version()); |
153 } | 126 } |
154 | 127 |
155 void ServiceWorkerProviderHost::UnassociateRegistration() { | 128 void ServiceWorkerProviderHost::UnassociateRegistration() { |
156 if (!associated_registration_.get()) | 129 if (!associated_registration_.get()) |
157 return; | 130 return; |
| 131 DecreaseProcessReference(associated_registration_); |
158 associated_registration_->RemoveListener(this); | 132 associated_registration_->RemoveListener(this); |
159 associated_registration_ = NULL; | 133 associated_registration_ = NULL; |
160 UpdatePotentialControllees(NULL, NULL, NULL); | 134 installing_version_ = NULL; |
| 135 waiting_version_ = NULL; |
| 136 active_version_ = NULL; |
161 SetControllerVersionAttribute(NULL); | 137 SetControllerVersionAttribute(NULL); |
162 } | 138 } |
163 | 139 |
| 140 void ServiceWorkerProviderHost::AssociatePendingRegistration( |
| 141 ServiceWorkerRegistration* registration) { |
| 142 pending_registrations_.push_back(registration); |
| 143 IncreaseProcessReference(registration); |
| 144 } |
| 145 |
164 scoped_ptr<ServiceWorkerRequestHandler> | 146 scoped_ptr<ServiceWorkerRequestHandler> |
165 ServiceWorkerProviderHost::CreateRequestHandler( | 147 ServiceWorkerProviderHost::CreateRequestHandler( |
166 ResourceType resource_type, | 148 ResourceType resource_type, |
167 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 149 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
168 scoped_refptr<ResourceRequestBody> body) { | 150 scoped_refptr<ResourceRequestBody> body) { |
169 if (IsHostToRunningServiceWorker()) { | 151 if (IsHostToRunningServiceWorker()) { |
170 return scoped_ptr<ServiceWorkerRequestHandler>( | 152 return scoped_ptr<ServiceWorkerRequestHandler>( |
171 new ServiceWorkerContextRequestHandler( | 153 new ServiceWorkerContextRequestHandler( |
172 context_, AsWeakPtr(), blob_storage_context, resource_type)); | 154 context_, AsWeakPtr(), blob_storage_context, resource_type)); |
173 } | 155 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 dispatcher_host_, | 201 dispatcher_host_, |
220 kDocumentMainThreadId, | 202 kDocumentMainThreadId, |
221 provider_id_, | 203 provider_id_, |
222 version); | 204 version); |
223 info = handle->GetObjectInfo(); | 205 info = handle->GetObjectInfo(); |
224 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); | 206 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); |
225 } | 207 } |
226 return info; | 208 return info; |
227 } | 209 } |
228 | 210 |
| 211 void ServiceWorkerProviderHost::IncreaseProcessReference( |
| 212 ServiceWorkerRegistration* registration) { |
| 213 if (context_ && context_->process_manager()) { |
| 214 context_->process_manager()->AddProcessReferenceToPattern( |
| 215 registration->pattern(), process_id_); |
| 216 } |
| 217 } |
| 218 |
| 219 void ServiceWorkerProviderHost::DecreaseProcessReference( |
| 220 ServiceWorkerRegistration* registration) { |
| 221 if (context_ && context_->process_manager()) { |
| 222 context_->process_manager()->RemoveProcessReferenceFromPattern( |
| 223 registration->pattern(), process_id_); |
| 224 } |
| 225 } |
| 226 |
229 bool ServiceWorkerProviderHost::IsContextAlive() { | 227 bool ServiceWorkerProviderHost::IsContextAlive() { |
230 return context_ != NULL; | 228 return context_ != NULL; |
231 } | 229 } |
232 | 230 |
233 } // namespace content | 231 } // namespace content |
OLD | NEW |