| 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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 url_loader_factory_binding_.Bind(std::move(loader_request)); | 576 url_loader_factory_binding_.Bind(std::move(loader_request)); |
| 577 } | 577 } |
| 578 | 578 |
| 579 private: | 579 private: |
| 580 const int render_process_id_; | 580 const int render_process_id_; |
| 581 mojo::AssociatedBinding<mojom::URLLoaderFactory> url_loader_factory_binding_; | 581 mojo::AssociatedBinding<mojom::URLLoaderFactory> url_loader_factory_binding_; |
| 582 | 582 |
| 583 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 583 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 584 }; | 584 }; |
| 585 | 585 |
| 586 class RenderProcessHostIsReadyObserver : public RenderProcessHostObserver { |
| 587 public: |
| 588 RenderProcessHostIsReadyObserver(RenderProcessHost* render_process_host, |
| 589 base::OnceClosure task) |
| 590 : render_process_host_(render_process_host), |
| 591 task_(std::move(task)), |
| 592 weak_factory_(this) { |
| 593 render_process_host_->AddObserver(this); |
| 594 if (render_process_host_->IsReady()) |
| 595 PostTask(); |
| 596 } |
| 597 |
| 598 ~RenderProcessHostIsReadyObserver() override { |
| 599 render_process_host_->RemoveObserver(this); |
| 600 } |
| 601 |
| 602 void RenderProcessReady(RenderProcessHost* host) override { PostTask(); } |
| 603 |
| 604 void RenderProcessHostDestroyed(RenderProcessHost* host) override { |
| 605 delete this; |
| 606 } |
| 607 |
| 608 private: |
| 609 void PostTask() { |
| 610 BrowserThread::PostTask( |
| 611 BrowserThread::UI, FROM_HERE, |
| 612 base::Bind(&RenderProcessHostIsReadyObserver::CallTask, |
| 613 weak_factory_.GetWeakPtr())); |
| 614 } |
| 615 |
| 616 void CallTask() { |
| 617 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 618 if (render_process_host_->IsReady()) |
| 619 std::move(task_).Run(); |
| 620 |
| 621 delete this; |
| 622 } |
| 623 |
| 624 RenderProcessHost* render_process_host_; |
| 625 base::OnceClosure task_; |
| 626 base::WeakPtrFactory<RenderProcessHostIsReadyObserver> weak_factory_; |
| 627 |
| 628 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostIsReadyObserver); |
| 629 }; |
| 630 |
| 586 } // namespace | 631 } // namespace |
| 587 | 632 |
| 588 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; | 633 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; |
| 589 | 634 |
| 590 base::MessageLoop* g_in_process_thread; | 635 base::MessageLoop* g_in_process_thread; |
| 591 | 636 |
| 592 // Stores the maximum number of renderer processes the content module can | 637 // Stores the maximum number of renderer processes the content module can |
| 593 // create. | 638 // create. |
| 594 static size_t g_max_renderer_count_override = 0; | 639 static size_t g_max_renderer_count_override = 0; |
| 595 | 640 |
| (...skipping 2353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2949 std::unique_ptr<RenderWidgetHostIterator> widgets( | 2994 std::unique_ptr<RenderWidgetHostIterator> widgets( |
| 2950 RenderWidgetHost::GetRenderWidgetHosts()); | 2995 RenderWidgetHost::GetRenderWidgetHosts()); |
| 2951 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 2996 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 2952 // Count only RenderWidgetHosts in this process. | 2997 // Count only RenderWidgetHosts in this process. |
| 2953 if (widget->GetProcess()->GetID() == GetID()) | 2998 if (widget->GetProcess()->GetID() == GetID()) |
| 2954 num_active_views++; | 2999 num_active_views++; |
| 2955 } | 3000 } |
| 2956 return num_active_views; | 3001 return num_active_views; |
| 2957 } | 3002 } |
| 2958 | 3003 |
| 3004 void RenderProcessHost::PostTaskWhenProcessIsReady(base::OnceClosure task) { |
| 3005 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 3006 DCHECK(!task.is_null()); |
| 3007 new RenderProcessHostIsReadyObserver(this, std::move(task)); |
| 3008 } |
| 3009 |
| 2959 void RenderProcessHostImpl::ReleaseOnCloseACK( | 3010 void RenderProcessHostImpl::ReleaseOnCloseACK( |
| 2960 RenderProcessHost* host, | 3011 RenderProcessHost* host, |
| 2961 const SessionStorageNamespaceMap& sessions, | 3012 const SessionStorageNamespaceMap& sessions, |
| 2962 int view_route_id) { | 3013 int view_route_id) { |
| 2963 DCHECK(host); | 3014 DCHECK(host); |
| 2964 if (sessions.empty()) | 3015 if (sessions.empty()) |
| 2965 return; | 3016 return; |
| 2966 SessionStorageHolder* holder = static_cast<SessionStorageHolder*>( | 3017 SessionStorageHolder* holder = static_cast<SessionStorageHolder*>( |
| 2967 host->GetUserData(kSessionStorageHolderKey)); | 3018 host->GetUserData(kSessionStorageHolderKey)); |
| 2968 if (!holder) { | 3019 if (!holder) { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3270 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3321 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 3271 | 3322 |
| 3272 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3323 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
| 3273 // Capture the error message in a crash key value. | 3324 // Capture the error message in a crash key value. |
| 3274 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3325 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
| 3275 bad_message::ReceivedBadMessage(render_process_id, | 3326 bad_message::ReceivedBadMessage(render_process_id, |
| 3276 bad_message::RPH_MOJO_PROCESS_ERROR); | 3327 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3277 } | 3328 } |
| 3278 | 3329 |
| 3279 } // namespace content | 3330 } // namespace content |
| OLD | NEW |