Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
| 6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
| 7 | 7 |
| 8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 url_loader_factory_binding_.Bind(std::move(loader_request)); | 508 url_loader_factory_binding_.Bind(std::move(loader_request)); |
| 509 } | 509 } |
| 510 | 510 |
| 511 private: | 511 private: |
| 512 const int render_process_id_; | 512 const int render_process_id_; |
| 513 mojo::AssociatedBinding<mojom::URLLoaderFactory> url_loader_factory_binding_; | 513 mojo::AssociatedBinding<mojom::URLLoaderFactory> url_loader_factory_binding_; |
| 514 | 514 |
| 515 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 515 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 516 }; | 516 }; |
| 517 | 517 |
| 518 class RenderProcessHostIsReadyObserver : public RenderProcessHostObserver { | |
| 519 public: | |
| 520 RenderProcessHostIsReadyObserver(RenderProcessHost* render_process_host, | |
| 521 base::OnceClosure task) | |
| 522 : render_process_host_(render_process_host), | |
| 523 task_(std::move(task)), | |
| 524 weak_factory_(this) { | |
| 525 render_process_host_->AddObserver(this); | |
| 526 if (render_process_host_->IsReady()) | |
| 527 PostTask(); | |
| 528 } | |
| 529 | |
| 530 ~RenderProcessHostIsReadyObserver() override { | |
| 531 render_process_host_->RemoveObserver(this); | |
| 532 } | |
| 533 | |
| 534 void RenderProcessReady(RenderProcessHost* host) override { PostTask(); } | |
| 535 | |
| 536 void RenderProcessHostDestroyed(RenderProcessHost* host) override { | |
| 537 delete this; | |
| 538 } | |
| 539 | |
| 540 private: | |
| 541 void PostTask() { | |
| 542 BrowserThread::PostTask( | |
| 543 BrowserThread::UI, FROM_HERE, | |
| 544 base::Bind(&RenderProcessHostIsReadyObserver::CallTask, | |
| 545 weak_factory_.GetWeakPtr())); | |
| 546 } | |
| 547 | |
| 548 void CallTask() { | |
| 549 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 550 if (render_process_host_->IsReady()) { | |
| 551 std::move(task_).Run(); | |
| 552 delete this; | |
|
ncarter (slow)
2017/05/12 21:56:02
I'd probably elect to |delete this| unconditionall
Łukasz Anforowicz
2017/05/16 16:37:25
Done.
I think in the scenario you point out Rende
| |
| 553 } | |
| 554 } | |
| 555 | |
| 556 RenderProcessHost* render_process_host_; | |
| 557 base::OnceClosure task_; | |
| 558 base::WeakPtrFactory<RenderProcessHostIsReadyObserver> weak_factory_; | |
| 559 | |
| 560 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostIsReadyObserver); | |
| 561 }; | |
| 562 | |
| 518 } // namespace | 563 } // namespace |
| 519 | 564 |
| 520 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; | 565 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; |
| 521 | 566 |
| 522 base::MessageLoop* g_in_process_thread; | 567 base::MessageLoop* g_in_process_thread; |
| 523 | 568 |
| 524 // Stores the maximum number of renderer processes the content module can | 569 // Stores the maximum number of renderer processes the content module can |
| 525 // create. | 570 // create. |
| 526 static size_t g_max_renderer_count_override = 0; | 571 static size_t g_max_renderer_count_override = 0; |
| 527 | 572 |
| (...skipping 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2825 std::unique_ptr<RenderWidgetHostIterator> widgets( | 2870 std::unique_ptr<RenderWidgetHostIterator> widgets( |
| 2826 RenderWidgetHost::GetRenderWidgetHosts()); | 2871 RenderWidgetHost::GetRenderWidgetHosts()); |
| 2827 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 2872 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 2828 // Count only RenderWidgetHosts in this process. | 2873 // Count only RenderWidgetHosts in this process. |
| 2829 if (widget->GetProcess()->GetID() == GetID()) | 2874 if (widget->GetProcess()->GetID() == GetID()) |
| 2830 num_active_views++; | 2875 num_active_views++; |
| 2831 } | 2876 } |
| 2832 return num_active_views; | 2877 return num_active_views; |
| 2833 } | 2878 } |
| 2834 | 2879 |
| 2880 void RenderProcessHost::PostTaskWhenProcessIsReady(base::OnceClosure task) { | |
| 2881 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 2882 DCHECK(!task.is_null()); | |
| 2883 new RenderProcessHostIsReadyObserver(this, std::move(task)); | |
| 2884 } | |
| 2885 | |
| 2835 void RenderProcessHostImpl::ReleaseOnCloseACK( | 2886 void RenderProcessHostImpl::ReleaseOnCloseACK( |
| 2836 RenderProcessHost* host, | 2887 RenderProcessHost* host, |
| 2837 const SessionStorageNamespaceMap& sessions, | 2888 const SessionStorageNamespaceMap& sessions, |
| 2838 int view_route_id) { | 2889 int view_route_id) { |
| 2839 DCHECK(host); | 2890 DCHECK(host); |
| 2840 if (sessions.empty()) | 2891 if (sessions.empty()) |
| 2841 return; | 2892 return; |
| 2842 SessionStorageHolder* holder = static_cast<SessionStorageHolder*>( | 2893 SessionStorageHolder* holder = static_cast<SessionStorageHolder*>( |
| 2843 host->GetUserData(kSessionStorageHolderKey)); | 2894 host->GetUserData(kSessionStorageHolderKey)); |
| 2844 if (!holder) { | 2895 if (!holder) { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3113 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3164 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 3114 | 3165 |
| 3115 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3166 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
| 3116 // Capture the error message in a crash key value. | 3167 // Capture the error message in a crash key value. |
| 3117 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3168 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
| 3118 bad_message::ReceivedBadMessage(render_process_id, | 3169 bad_message::ReceivedBadMessage(render_process_id, |
| 3119 bad_message::RPH_MOJO_PROCESS_ERROR); | 3170 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3120 } | 3171 } |
| 3121 | 3172 |
| 3122 } // namespace content | 3173 } // namespace content |
| OLD | NEW |