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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 if (SharedWorkerHost* host = | 339 if (SharedWorkerHost* host = |
340 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) | 340 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) |
341 host->WorkerContextClosed(); | 341 host->WorkerContextClosed(); |
342 } | 342 } |
343 | 343 |
344 void SharedWorkerServiceImpl::WorkerContextDestroyed( | 344 void SharedWorkerServiceImpl::WorkerContextDestroyed( |
345 int worker_route_id, | 345 int worker_route_id, |
346 SharedWorkerMessageFilter* filter) { | 346 SharedWorkerMessageFilter* filter) { |
347 ScopedWorkerDependencyChecker checker(this); | 347 ScopedWorkerDependencyChecker checker(this); |
348 ProcessRouteIdPair key(filter->render_process_id(), worker_route_id); | 348 ProcessRouteIdPair key(filter->render_process_id(), worker_route_id); |
349 if (!ContainsKey(worker_hosts_, key)) | 349 if (!base::ContainsKey(worker_hosts_, key)) |
350 return; | 350 return; |
351 std::unique_ptr<SharedWorkerHost> host(worker_hosts_[key].release()); | 351 std::unique_ptr<SharedWorkerHost> host(worker_hosts_[key].release()); |
352 worker_hosts_.erase(key); | 352 worker_hosts_.erase(key); |
353 host->WorkerContextDestroyed(); | 353 host->WorkerContextDestroyed(); |
354 } | 354 } |
355 | 355 |
356 void SharedWorkerServiceImpl::WorkerReadyForInspection( | 356 void SharedWorkerServiceImpl::WorkerReadyForInspection( |
357 int worker_route_id, | 357 int worker_route_id, |
358 SharedWorkerMessageFilter* filter) { | 358 SharedWorkerMessageFilter* filter) { |
359 if (SharedWorkerHost* host = | 359 if (SharedWorkerHost* host = |
360 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) | 360 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) |
361 host->WorkerReadyForInspection(); | 361 host->WorkerReadyForInspection(); |
362 } | 362 } |
363 | 363 |
364 void SharedWorkerServiceImpl::WorkerScriptLoaded( | 364 void SharedWorkerServiceImpl::WorkerScriptLoaded( |
365 int worker_route_id, | 365 int worker_route_id, |
366 SharedWorkerMessageFilter* filter) { | 366 SharedWorkerMessageFilter* filter) { |
367 if (SharedWorkerHost* host = | 367 if (SharedWorkerHost* host = |
368 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) | 368 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) |
369 host->WorkerScriptLoaded(); | 369 host->WorkerScriptLoaded(); |
370 } | 370 } |
371 | 371 |
372 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( | 372 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( |
373 int worker_route_id, | 373 int worker_route_id, |
374 SharedWorkerMessageFilter* filter) { | 374 SharedWorkerMessageFilter* filter) { |
375 ScopedWorkerDependencyChecker checker(this); | 375 ScopedWorkerDependencyChecker checker(this); |
376 ProcessRouteIdPair key(filter->render_process_id(), worker_route_id); | 376 ProcessRouteIdPair key(filter->render_process_id(), worker_route_id); |
377 if (!ContainsKey(worker_hosts_, key)) | 377 if (!base::ContainsKey(worker_hosts_, key)) |
378 return; | 378 return; |
379 std::unique_ptr<SharedWorkerHost> host(worker_hosts_[key].release()); | 379 std::unique_ptr<SharedWorkerHost> host(worker_hosts_[key].release()); |
380 worker_hosts_.erase(key); | 380 worker_hosts_.erase(key); |
381 host->WorkerScriptLoadFailed(); | 381 host->WorkerScriptLoadFailed(); |
382 } | 382 } |
383 | 383 |
384 void SharedWorkerServiceImpl::WorkerConnected( | 384 void SharedWorkerServiceImpl::WorkerConnected( |
385 int message_port_id, | 385 int message_port_id, |
386 int worker_route_id, | 386 int worker_route_id, |
387 SharedWorkerMessageFilter* filter) { | 387 SharedWorkerMessageFilter* filter) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 int worker_route_id, | 523 int worker_route_id, |
524 bool is_new_worker, | 524 bool is_new_worker, |
525 bool pause_on_start) { | 525 bool pause_on_start) { |
526 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 526 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
527 // To offset the TryIncrementWorkerRefCount called for the reservation, | 527 // To offset the TryIncrementWorkerRefCount called for the reservation, |
528 // calls DecrementWorkerRefCount after CheckWorkerDependency in | 528 // calls DecrementWorkerRefCount after CheckWorkerDependency in |
529 // ScopeWorkerDependencyChecker's destructor. | 529 // ScopeWorkerDependencyChecker's destructor. |
530 ScopedWorkerDependencyChecker checker( | 530 ScopedWorkerDependencyChecker checker( |
531 this, base::Bind(&DecrementWorkerRefCount, worker_process_id)); | 531 this, base::Bind(&DecrementWorkerRefCount, worker_process_id)); |
532 | 532 |
533 if (!ContainsKey(pending_instances_, pending_instance_id)) | 533 if (!base::ContainsKey(pending_instances_, pending_instance_id)) |
534 return; | 534 return; |
535 std::unique_ptr<SharedWorkerPendingInstance> pending_instance( | 535 std::unique_ptr<SharedWorkerPendingInstance> pending_instance( |
536 pending_instances_[pending_instance_id].release()); | 536 pending_instances_[pending_instance_id].release()); |
537 pending_instances_.erase(pending_instance_id); | 537 pending_instances_.erase(pending_instance_id); |
538 | 538 |
539 if (!is_new_worker) { | 539 if (!is_new_worker) { |
540 SharedWorkerHost* host = | 540 SharedWorkerHost* host = |
541 FindSharedWorkerHost(worker_process_id, worker_route_id); | 541 FindSharedWorkerHost(worker_process_id, worker_route_id); |
542 if (!host) { | 542 if (!host) { |
543 // Retry reserving a renderer process if the existed Shared Worker was | 543 // Retry reserving a renderer process if the existed Shared Worker was |
(...skipping 30 matching lines...) Expand all Loading... |
574 observers_, | 574 observers_, |
575 WorkerCreated(url, name, worker_process_id, worker_route_id)); | 575 WorkerCreated(url, name, worker_process_id, worker_route_id)); |
576 } | 576 } |
577 | 577 |
578 void SharedWorkerServiceImpl::RenderProcessReserveFailedCallback( | 578 void SharedWorkerServiceImpl::RenderProcessReserveFailedCallback( |
579 int pending_instance_id, | 579 int pending_instance_id, |
580 int worker_process_id, | 580 int worker_process_id, |
581 int worker_route_id, | 581 int worker_route_id, |
582 bool is_new_worker) { | 582 bool is_new_worker) { |
583 worker_hosts_.erase(std::make_pair(worker_process_id, worker_route_id)); | 583 worker_hosts_.erase(std::make_pair(worker_process_id, worker_route_id)); |
584 if (!ContainsKey(pending_instances_, pending_instance_id)) | 584 if (!base::ContainsKey(pending_instances_, pending_instance_id)) |
585 return; | 585 return; |
586 std::unique_ptr<SharedWorkerPendingInstance> pending_instance( | 586 std::unique_ptr<SharedWorkerPendingInstance> pending_instance( |
587 pending_instances_[pending_instance_id].release()); | 587 pending_instances_[pending_instance_id].release()); |
588 pending_instances_.erase(pending_instance_id); | 588 pending_instances_.erase(pending_instance_id); |
589 pending_instance->RemoveRequest(worker_process_id); | 589 pending_instance->RemoveRequest(worker_process_id); |
590 // Retry reserving a renderer process. | 590 // Retry reserving a renderer process. |
591 ReserveRenderProcessToCreateWorker(std::move(pending_instance)); | 591 ReserveRenderProcessToCreateWorker(std::move(pending_instance)); |
592 } | 592 } |
593 | 593 |
594 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( | 594 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( |
595 int render_process_id, | 595 int render_process_id, |
596 int worker_route_id) { | 596 int worker_route_id) { |
597 ProcessRouteIdPair key = std::make_pair(render_process_id, worker_route_id); | 597 ProcessRouteIdPair key = std::make_pair(render_process_id, worker_route_id); |
598 if (!ContainsKey(worker_hosts_, key)) | 598 if (!base::ContainsKey(worker_hosts_, key)) |
599 return nullptr; | 599 return nullptr; |
600 return worker_hosts_[key].get(); | 600 return worker_hosts_[key].get(); |
601 } | 601 } |
602 | 602 |
603 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( | 603 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( |
604 const SharedWorkerInstance& instance) { | 604 const SharedWorkerInstance& instance) { |
605 for (const auto& iter : worker_hosts_) { | 605 for (const auto& iter : worker_hosts_) { |
606 SharedWorkerHost* host = iter.second.get(); | 606 SharedWorkerHost* host = iter.second.get(); |
607 if (host->IsAvailable() && host->instance()->Matches(instance)) | 607 if (host->IsAvailable() && host->instance()->Matches(instance)) |
608 return host; | 608 return host; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 UpdateWorkerDependencyFunc new_func) { | 655 UpdateWorkerDependencyFunc new_func) { |
656 update_worker_dependency_ = new_func; | 656 update_worker_dependency_ = new_func; |
657 } | 657 } |
658 | 658 |
659 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( | 659 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( |
660 bool (*new_func)(int)) { | 660 bool (*new_func)(int)) { |
661 s_try_increment_worker_ref_count_ = new_func; | 661 s_try_increment_worker_ref_count_ = new_func; |
662 } | 662 } |
663 | 663 |
664 } // namespace content | 664 } // namespace content |
OLD | NEW |