OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shared_worker/shared_worker_service_impl.h" | 5 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void SharedWorkerServiceImpl::CreateWorker( | 122 void SharedWorkerServiceImpl::CreateWorker( |
123 const ViewHostMsg_CreateWorker_Params& params, | 123 const ViewHostMsg_CreateWorker_Params& params, |
124 int route_id, | 124 int route_id, |
125 SharedWorkerMessageFilter* filter, | 125 SharedWorkerMessageFilter* filter, |
126 ResourceContext* resource_context, | 126 ResourceContext* resource_context, |
127 const WorkerStoragePartition& partition, | 127 const WorkerStoragePartition& partition, |
128 bool* url_mismatch) { | 128 bool* url_mismatch) { |
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
130 ScopedWorkerDependencyChecker checker(this); | 130 ScopedWorkerDependencyChecker checker(this); |
131 *url_mismatch = false; | 131 *url_mismatch = false; |
132 SharedWorkerInstance* existing_instance = | 132 SharedWorkerHost* existing_host = FindSharedWorkerHost( |
133 FindSharedWorkerInstance( | 133 params.url, params.name, partition, resource_context); |
134 params.url, params.name, partition, resource_context); | 134 if (existing_host) { |
135 if (existing_instance) { | 135 if (params.url != existing_host->instance()->url()) { |
136 if (params.url != existing_instance->url()) { | |
137 *url_mismatch = true; | 136 *url_mismatch = true; |
138 return; | 137 return; |
139 } | 138 } |
140 if (existing_instance->load_failed()) { | 139 if (existing_host->load_failed()) { |
141 filter->Send(new ViewMsg_WorkerScriptLoadFailed(route_id)); | 140 filter->Send(new ViewMsg_WorkerScriptLoadFailed(route_id)); |
142 return; | 141 return; |
143 } | 142 } |
144 existing_instance->AddFilter(filter, route_id); | 143 existing_host->AddFilter(filter, route_id); |
145 existing_instance->worker_document_set()->Add( | 144 existing_host->worker_document_set()->Add(filter, |
146 filter, params.document_id, filter->render_process_id(), | 145 params.document_id, |
147 params.render_frame_route_id); | 146 filter->render_process_id(), |
| 147 params.render_frame_route_id); |
148 filter->Send(new ViewMsg_WorkerCreated(route_id)); | 148 filter->Send(new ViewMsg_WorkerCreated(route_id)); |
149 return; | 149 return; |
150 } | 150 } |
151 | 151 |
152 scoped_ptr<SharedWorkerInstance> instance(new SharedWorkerInstance( | 152 scoped_ptr<SharedWorkerInstance> instance(new SharedWorkerInstance( |
153 params.url, | 153 params.url, |
154 params.name, | 154 params.name, |
155 params.content_security_policy, | 155 params.content_security_policy, |
156 params.security_policy_type, | 156 params.security_policy_type, |
157 resource_context, | 157 resource_context, |
158 partition)); | 158 partition)); |
159 instance->AddFilter(filter, route_id); | 159 scoped_ptr<SharedWorkerHost> host(new SharedWorkerHost(instance.release())); |
160 instance->worker_document_set()->Add( | 160 host->AddFilter(filter, route_id); |
161 filter, params.document_id, filter->render_process_id(), | 161 host->worker_document_set()->Add(filter, |
162 params.render_frame_route_id); | 162 params.document_id, |
| 163 filter->render_process_id(), |
| 164 params.render_frame_route_id); |
163 | 165 |
164 scoped_ptr<SharedWorkerHost> host(new SharedWorkerHost(instance.release())); | |
165 host->Init(filter); | 166 host->Init(filter); |
166 const int worker_route_id = host->worker_route_id(); | 167 const int worker_route_id = host->worker_route_id(); |
167 worker_hosts_.set(std::make_pair(filter->render_process_id(), | 168 worker_hosts_.set(std::make_pair(filter->render_process_id(), |
168 worker_route_id), | 169 worker_route_id), |
169 host.Pass()); | 170 host.Pass()); |
170 | 171 |
171 FOR_EACH_OBSERVER( | 172 FOR_EACH_OBSERVER( |
172 WorkerServiceObserver, observers_, | 173 WorkerServiceObserver, observers_, |
173 WorkerCreated(params.url, | 174 WorkerCreated(params.url, |
174 params.name, | 175 params.name, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 worker_hosts_.erase(remove_list[i]); | 292 worker_hosts_.erase(remove_list[i]); |
292 } | 293 } |
293 | 294 |
294 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( | 295 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( |
295 SharedWorkerMessageFilter* filter, | 296 SharedWorkerMessageFilter* filter, |
296 int worker_route_id) { | 297 int worker_route_id) { |
297 return worker_hosts_.get(std::make_pair(filter->render_process_id(), | 298 return worker_hosts_.get(std::make_pair(filter->render_process_id(), |
298 worker_route_id)); | 299 worker_route_id)); |
299 } | 300 } |
300 | 301 |
301 SharedWorkerInstance* SharedWorkerServiceImpl::FindSharedWorkerInstance( | 302 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( |
302 const GURL& url, | 303 const GURL& url, |
303 const base::string16& name, | 304 const base::string16& name, |
304 const WorkerStoragePartition& partition, | 305 const WorkerStoragePartition& partition, |
305 ResourceContext* resource_context) { | 306 ResourceContext* resource_context) { |
306 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); | 307 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); |
307 iter != worker_hosts_.end(); | 308 iter != worker_hosts_.end(); |
308 ++iter) { | 309 ++iter) { |
309 SharedWorkerInstance* instance = iter->second->instance(); | 310 SharedWorkerInstance* instance = iter->second->instance(); |
310 if (instance && instance->Matches(url, name, partition, resource_context)) | 311 if (instance && !iter->second->closed() && |
311 return instance; | 312 instance->Matches(url, name, partition, resource_context)) |
| 313 return iter->second; |
312 } | 314 } |
313 return NULL; | 315 return NULL; |
314 } | 316 } |
315 | 317 |
316 const std::set<int> | 318 const std::set<int> |
317 SharedWorkerServiceImpl::GetRenderersWithWorkerDependency() { | 319 SharedWorkerServiceImpl::GetRenderersWithWorkerDependency() { |
318 std::set<int> dependent_renderers; | 320 std::set<int> dependent_renderers; |
319 for (WorkerHostMap::iterator host_iter = worker_hosts_.begin(); | 321 for (WorkerHostMap::iterator host_iter = worker_hosts_.begin(); |
320 host_iter != worker_hosts_.end(); | 322 host_iter != worker_hosts_.end(); |
321 ++host_iter) { | 323 ++host_iter) { |
322 const int process_id = host_iter->first.first; | 324 const int process_id = host_iter->first.first; |
323 if (dependent_renderers.count(process_id)) | 325 if (dependent_renderers.count(process_id)) |
324 continue; | 326 continue; |
325 SharedWorkerInstance* instance = host_iter->second->instance(); | 327 if (host_iter->second->instance() && |
326 if (instance && | 328 host_iter->second->worker_document_set()->ContainsExternalRenderer( |
327 instance->worker_document_set()->ContainsExternalRenderer(process_id)) { | 329 process_id)) { |
328 dependent_renderers.insert(process_id); | 330 dependent_renderers.insert(process_id); |
329 } | 331 } |
330 } | 332 } |
331 return dependent_renderers; | 333 return dependent_renderers; |
332 } | 334 } |
333 | 335 |
334 void SharedWorkerServiceImpl::CheckWorkerDependency() { | 336 void SharedWorkerServiceImpl::CheckWorkerDependency() { |
335 const std::set<int> current_worker_depended_renderers = | 337 const std::set<int> current_worker_depended_renderers = |
336 GetRenderersWithWorkerDependency(); | 338 GetRenderersWithWorkerDependency(); |
337 std::vector<int> added_items; | 339 std::vector<int> added_items; |
(...skipping 13 matching lines...) Expand all Loading... |
351 update_worker_dependency_(added_items, removed_items); | 353 update_worker_dependency_(added_items, removed_items); |
352 } | 354 } |
353 } | 355 } |
354 | 356 |
355 void SharedWorkerServiceImpl::ChangeUpdateWorkerDependencyFuncForTesting( | 357 void SharedWorkerServiceImpl::ChangeUpdateWorkerDependencyFuncForTesting( |
356 UpdateWorkerDependencyFunc new_func) { | 358 UpdateWorkerDependencyFunc new_func) { |
357 update_worker_dependency_ = new_func; | 359 update_worker_dependency_ = new_func; |
358 } | 360 } |
359 | 361 |
360 } // namespace content | 362 } // namespace content |
OLD | NEW |