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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 bool is_new_worker, | 183 bool is_new_worker, |
184 const SharedWorkerInstance& instance) | 184 const SharedWorkerInstance& instance) |
185 : worker_process_id_(worker_process_id), | 185 : worker_process_id_(worker_process_id), |
186 worker_route_id_(worker_route_id), | 186 worker_route_id_(worker_route_id), |
187 is_new_worker_(is_new_worker), | 187 is_new_worker_(is_new_worker), |
188 instance_(instance) {} | 188 instance_(instance) {} |
189 | 189 |
190 void TryReserve(const base::Callback<void(bool)>& success_cb, | 190 void TryReserve(const base::Callback<void(bool)>& success_cb, |
191 const base::Closure& failure_cb, | 191 const base::Closure& failure_cb, |
192 bool (*try_increment_worker_ref_count)(int)) { | 192 bool (*try_increment_worker_ref_count)(int)) { |
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
194 if (!try_increment_worker_ref_count(worker_process_id_)) { | 194 if (!try_increment_worker_ref_count(worker_process_id_)) { |
195 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, failure_cb); | 195 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, failure_cb); |
196 return; | 196 return; |
197 } | 197 } |
198 bool pause_on_start = false; | 198 bool pause_on_start = false; |
199 if (is_new_worker_) { | 199 if (is_new_worker_) { |
200 pause_on_start = | 200 pause_on_start = |
201 SharedWorkerDevToolsManager::GetInstance()->WorkerCreated( | 201 SharedWorkerDevToolsManager::GetInstance()->WorkerCreated( |
202 worker_process_id_, worker_route_id_, instance_); | 202 worker_process_id_, worker_route_id_, instance_); |
203 } | 203 } |
204 BrowserThread::PostTask( | 204 BrowserThread::PostTask( |
205 BrowserThread::IO, FROM_HERE, base::Bind(success_cb, pause_on_start)); | 205 BrowserThread::IO, FROM_HERE, base::Bind(success_cb, pause_on_start)); |
206 } | 206 } |
207 | 207 |
208 private: | 208 private: |
209 friend class base::RefCountedThreadSafe<SharedWorkerReserver>; | 209 friend class base::RefCountedThreadSafe<SharedWorkerReserver>; |
210 ~SharedWorkerReserver() {} | 210 ~SharedWorkerReserver() {} |
211 | 211 |
212 const int worker_process_id_; | 212 const int worker_process_id_; |
213 const int worker_route_id_; | 213 const int worker_route_id_; |
214 const bool is_new_worker_; | 214 const bool is_new_worker_; |
215 const SharedWorkerInstance instance_; | 215 const SharedWorkerInstance instance_; |
216 }; | 216 }; |
217 | 217 |
218 // static | 218 // static |
219 bool (*SharedWorkerServiceImpl::s_try_increment_worker_ref_count_)(int) = | 219 bool (*SharedWorkerServiceImpl::s_try_increment_worker_ref_count_)(int) = |
220 TryIncrementWorkerRefCount; | 220 TryIncrementWorkerRefCount; |
221 | 221 |
222 SharedWorkerServiceImpl* SharedWorkerServiceImpl::GetInstance() { | 222 SharedWorkerServiceImpl* SharedWorkerServiceImpl::GetInstance() { |
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 223 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
224 return Singleton<SharedWorkerServiceImpl>::get(); | 224 return Singleton<SharedWorkerServiceImpl>::get(); |
225 } | 225 } |
226 | 226 |
227 SharedWorkerServiceImpl::SharedWorkerServiceImpl() | 227 SharedWorkerServiceImpl::SharedWorkerServiceImpl() |
228 : update_worker_dependency_(UpdateWorkerDependency), | 228 : update_worker_dependency_(UpdateWorkerDependency), |
229 next_pending_instance_id_(0) { | 229 next_pending_instance_id_(0) { |
230 } | 230 } |
231 | 231 |
232 SharedWorkerServiceImpl::~SharedWorkerServiceImpl() {} | 232 SharedWorkerServiceImpl::~SharedWorkerServiceImpl() {} |
233 | 233 |
(...skipping 28 matching lines...) Expand all Loading... |
262 info.route_id = host->worker_route_id(); | 262 info.route_id = host->worker_route_id(); |
263 info.process_id = host->process_id(); | 263 info.process_id = host->process_id(); |
264 info.handle = host->container_render_filter()->PeerHandle(); | 264 info.handle = host->container_render_filter()->PeerHandle(); |
265 results.push_back(info); | 265 results.push_back(info); |
266 } | 266 } |
267 } | 267 } |
268 return results; | 268 return results; |
269 } | 269 } |
270 | 270 |
271 void SharedWorkerServiceImpl::AddObserver(WorkerServiceObserver* observer) { | 271 void SharedWorkerServiceImpl::AddObserver(WorkerServiceObserver* observer) { |
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
273 observers_.AddObserver(observer); | 273 observers_.AddObserver(observer); |
274 } | 274 } |
275 | 275 |
276 void SharedWorkerServiceImpl::RemoveObserver(WorkerServiceObserver* observer) { | 276 void SharedWorkerServiceImpl::RemoveObserver(WorkerServiceObserver* observer) { |
277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 277 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
278 observers_.RemoveObserver(observer); | 278 observers_.RemoveObserver(observer); |
279 } | 279 } |
280 | 280 |
281 void SharedWorkerServiceImpl::CreateWorker( | 281 void SharedWorkerServiceImpl::CreateWorker( |
282 const ViewHostMsg_CreateWorker_Params& params, | 282 const ViewHostMsg_CreateWorker_Params& params, |
283 int route_id, | 283 int route_id, |
284 SharedWorkerMessageFilter* filter, | 284 SharedWorkerMessageFilter* filter, |
285 ResourceContext* resource_context, | 285 ResourceContext* resource_context, |
286 const WorkerStoragePartitionId& partition_id, | 286 const WorkerStoragePartitionId& partition_id, |
287 bool* url_mismatch) { | 287 bool* url_mismatch) { |
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 288 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
289 *url_mismatch = false; | 289 *url_mismatch = false; |
290 scoped_ptr<SharedWorkerInstance> instance( | 290 scoped_ptr<SharedWorkerInstance> instance( |
291 new SharedWorkerInstance(params.url, | 291 new SharedWorkerInstance(params.url, |
292 params.name, | 292 params.name, |
293 params.content_security_policy, | 293 params.content_security_policy, |
294 params.security_policy_type, | 294 params.security_policy_type, |
295 resource_context, | 295 resource_context, |
296 partition_id)); | 296 partition_id)); |
297 scoped_ptr<SharedWorkerPendingInstance::SharedWorkerPendingRequest> request( | 297 scoped_ptr<SharedWorkerPendingInstance::SharedWorkerPendingRequest> request( |
298 new SharedWorkerPendingInstance::SharedWorkerPendingRequest( | 298 new SharedWorkerPendingInstance::SharedWorkerPendingRequest( |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 void SharedWorkerServiceImpl::NotifyWorkerDestroyed(int worker_process_id, | 461 void SharedWorkerServiceImpl::NotifyWorkerDestroyed(int worker_process_id, |
462 int worker_route_id) { | 462 int worker_route_id) { |
463 FOR_EACH_OBSERVER(WorkerServiceObserver, | 463 FOR_EACH_OBSERVER(WorkerServiceObserver, |
464 observers_, | 464 observers_, |
465 WorkerDestroyed(worker_process_id, worker_route_id)); | 465 WorkerDestroyed(worker_process_id, worker_route_id)); |
466 } | 466 } |
467 | 467 |
468 void SharedWorkerServiceImpl::ReserveRenderProcessToCreateWorker( | 468 void SharedWorkerServiceImpl::ReserveRenderProcessToCreateWorker( |
469 scoped_ptr<SharedWorkerPendingInstance> pending_instance, | 469 scoped_ptr<SharedWorkerPendingInstance> pending_instance, |
470 bool* url_mismatch) { | 470 bool* url_mismatch) { |
471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 471 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
472 DCHECK(!FindPendingInstance(*pending_instance->instance())); | 472 DCHECK(!FindPendingInstance(*pending_instance->instance())); |
473 if (url_mismatch) | 473 if (url_mismatch) |
474 *url_mismatch = false; | 474 *url_mismatch = false; |
475 if (!pending_instance->requests()->size()) | 475 if (!pending_instance->requests()->size()) |
476 return; | 476 return; |
477 int worker_process_id = -1; | 477 int worker_process_id = -1; |
478 int worker_route_id = MSG_ROUTING_NONE; | 478 int worker_route_id = MSG_ROUTING_NONE; |
479 bool is_new_worker = true; | 479 bool is_new_worker = true; |
480 SharedWorkerHost* host = FindSharedWorkerHost(*pending_instance->instance()); | 480 SharedWorkerHost* host = FindSharedWorkerHost(*pending_instance->instance()); |
481 if (host) { | 481 if (host) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 s_try_increment_worker_ref_count_)); | 522 s_try_increment_worker_ref_count_)); |
523 pending_instances_.set(pending_instance_id, pending_instance.Pass()); | 523 pending_instances_.set(pending_instance_id, pending_instance.Pass()); |
524 } | 524 } |
525 | 525 |
526 void SharedWorkerServiceImpl::RenderProcessReservedCallback( | 526 void SharedWorkerServiceImpl::RenderProcessReservedCallback( |
527 int pending_instance_id, | 527 int pending_instance_id, |
528 int worker_process_id, | 528 int worker_process_id, |
529 int worker_route_id, | 529 int worker_route_id, |
530 bool is_new_worker, | 530 bool is_new_worker, |
531 bool pause_on_start) { | 531 bool pause_on_start) { |
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 532 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
533 // To offset the TryIncrementWorkerRefCount called for the reservation, | 533 // To offset the TryIncrementWorkerRefCount called for the reservation, |
534 // calls DecrementWorkerRefCount after CheckWorkerDependency in | 534 // calls DecrementWorkerRefCount after CheckWorkerDependency in |
535 // ScopeWorkerDependencyChecker's destructor. | 535 // ScopeWorkerDependencyChecker's destructor. |
536 ScopedWorkerDependencyChecker checker( | 536 ScopedWorkerDependencyChecker checker( |
537 this, base::Bind(&DecrementWorkerRefCount, worker_process_id)); | 537 this, base::Bind(&DecrementWorkerRefCount, worker_process_id)); |
538 scoped_ptr<SharedWorkerPendingInstance> pending_instance = | 538 scoped_ptr<SharedWorkerPendingInstance> pending_instance = |
539 pending_instances_.take_and_erase(pending_instance_id); | 539 pending_instances_.take_and_erase(pending_instance_id); |
540 if (!pending_instance) | 540 if (!pending_instance) |
541 return; | 541 return; |
542 if (!is_new_worker) { | 542 if (!is_new_worker) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 UpdateWorkerDependencyFunc new_func) { | 660 UpdateWorkerDependencyFunc new_func) { |
661 update_worker_dependency_ = new_func; | 661 update_worker_dependency_ = new_func; |
662 } | 662 } |
663 | 663 |
664 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( | 664 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( |
665 bool (*new_func)(int)) { | 665 bool (*new_func)(int)) { |
666 s_try_increment_worker_ref_count_ = new_func; | 666 s_try_increment_worker_ref_count_ = new_func; |
667 } | 667 } |
668 | 668 |
669 } // namespace content | 669 } // namespace content |
OLD | NEW |