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 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 id_, | 700 id_, |
701 storage_partition_impl_->GetURLRequestContext(), | 701 storage_partition_impl_->GetURLRequestContext(), |
702 storage_partition_impl_->GetIndexedDBContext(), | 702 storage_partition_impl_->GetIndexedDBContext(), |
703 ChromeBlobStorageContext::GetFor(browser_context_))), | 703 ChromeBlobStorageContext::GetFor(browser_context_))), |
704 channel_connected_(false), | 704 channel_connected_(false), |
705 sent_render_process_ready_(false), | 705 sent_render_process_ready_(false), |
706 #if defined(OS_ANDROID) | 706 #if defined(OS_ANDROID) |
707 never_signaled_(base::WaitableEvent::ResetPolicy::MANUAL, | 707 never_signaled_(base::WaitableEvent::ResetPolicy::MANUAL, |
708 base::WaitableEvent::InitialState::NOT_SIGNALED), | 708 base::WaitableEvent::InitialState::NOT_SIGNALED), |
709 #endif | 709 #endif |
| 710 resource_coordinator_binding_(this), |
710 instance_weak_factory_( | 711 instance_weak_factory_( |
711 new base::WeakPtrFactory<RenderProcessHostImpl>(this)), | 712 new base::WeakPtrFactory<RenderProcessHostImpl>(this)), |
712 weak_factory_(this) { | 713 weak_factory_(this) { |
713 widget_helper_ = new RenderWidgetHelper(); | 714 widget_helper_ = new RenderWidgetHelper(); |
714 | 715 |
715 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); | 716 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); |
716 | 717 |
717 CHECK(!BrowserMainRunner::ExitedMainMessageLoop()); | 718 CHECK(!BrowserMainRunner::ExitedMainMessageLoop()); |
718 RegisterHost(GetID(), this); | 719 RegisterHost(GetID(), this); |
719 g_all_hosts.Get().set_check_on_null_data(true); | 720 g_all_hosts.Get().set_check_on_null_data(true); |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 base::debug::DumpWithoutCrashing(); | 1547 base::debug::DumpWithoutCrashing(); |
1547 } | 1548 } |
1548 | 1549 |
1549 // Log the renderer kill to the histogram tracking all kills. | 1550 // Log the renderer kill to the histogram tracking all kills. |
1550 BrowserChildProcessHostImpl::HistogramBadMessageTerminated( | 1551 BrowserChildProcessHostImpl::HistogramBadMessageTerminated( |
1551 PROCESS_TYPE_RENDERER); | 1552 PROCESS_TYPE_RENDERER); |
1552 } | 1553 } |
1553 | 1554 |
1554 void RenderProcessHostImpl::WidgetRestored() { | 1555 void RenderProcessHostImpl::WidgetRestored() { |
1555 visible_widgets_++; | 1556 visible_widgets_++; |
1556 UpdateProcessPriority(); | 1557 // UpdateProcessPriority(); |
1557 DCHECK(!is_process_backgrounded_); | 1558 DCHECK(!is_process_backgrounded_); |
1558 } | 1559 } |
1559 | 1560 |
1560 void RenderProcessHostImpl::WidgetHidden() { | 1561 void RenderProcessHostImpl::WidgetHidden() { |
1561 // On startup, the browser will call Hide. We ignore this call. | 1562 // On startup, the browser will call Hide. We ignore this call. |
1562 if (visible_widgets_ == 0) | 1563 if (visible_widgets_ == 0) |
1563 return; | 1564 return; |
1564 | 1565 |
1565 --visible_widgets_; | 1566 --visible_widgets_; |
1566 if (visible_widgets_ == 0) { | 1567 if (visible_widgets_ == 0) { |
1567 DCHECK(!is_process_backgrounded_); | 1568 DCHECK(!is_process_backgrounded_); |
1568 UpdateProcessPriority(); | 1569 // UpdateProcessPriority(); |
1569 } | 1570 } |
1570 } | 1571 } |
1571 | 1572 |
1572 int RenderProcessHostImpl::VisibleWidgetCount() const { | 1573 int RenderProcessHostImpl::VisibleWidgetCount() const { |
1573 return visible_widgets_; | 1574 return visible_widgets_; |
1574 } | 1575 } |
1575 | 1576 |
1576 void RenderProcessHostImpl::OnAudioStreamAdded() { | 1577 void RenderProcessHostImpl::OnAudioStreamAdded() { |
1577 ++audio_stream_count_; | 1578 if (++audio_stream_count_ == 1) { |
1578 UpdateProcessPriority(); | 1579 GetProcessResourceCoordinator()->SendEvent( |
| 1580 resource_coordinator::mojom::EventType::ON_PROCESS_AUDIO_STARTED); |
| 1581 } |
| 1582 // UpdateProcessPriority(); |
1579 } | 1583 } |
1580 | 1584 |
1581 void RenderProcessHostImpl::OnAudioStreamRemoved() { | 1585 void RenderProcessHostImpl::OnAudioStreamRemoved() { |
1582 DCHECK_GT(audio_stream_count_, 0); | 1586 DCHECK_GT(audio_stream_count_, 0); |
1583 --audio_stream_count_; | 1587 if (--audio_stream_count_ == 0) { |
1584 UpdateProcessPriority(); | 1588 GetProcessResourceCoordinator()->SendEvent( |
| 1589 resource_coordinator::mojom::EventType::ON_PROCESS_AUDIO_STOPPED); |
| 1590 } |
| 1591 // UpdateProcessPriority(); |
| 1592 } |
| 1593 |
| 1594 resource_coordinator::ResourceCoordinatorInterface* |
| 1595 RenderProcessHostImpl::GetProcessResourceCoordinator() { |
| 1596 if (!process_resource_coordinator_) { |
| 1597 process_resource_coordinator_ = |
| 1598 base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>( |
| 1599 ServiceManagerConnection::GetForProcess()->GetConnector(), |
| 1600 resource_coordinator::mojom::IDType::PROCESS); |
| 1601 |
| 1602 process_resource_coordinator_->service()->SetPolicyCallback( |
| 1603 resource_coordinator_binding_.CreateInterfacePtrAndBind()); |
| 1604 } |
| 1605 |
| 1606 return process_resource_coordinator_.get(); |
1585 } | 1607 } |
1586 | 1608 |
1587 bool RenderProcessHostImpl::IsForGuestsOnly() const { | 1609 bool RenderProcessHostImpl::IsForGuestsOnly() const { |
1588 return is_for_guests_only_; | 1610 return is_for_guests_only_; |
1589 } | 1611 } |
1590 | 1612 |
1591 StoragePartition* RenderProcessHostImpl::GetStoragePartition() const { | 1613 StoragePartition* RenderProcessHostImpl::GetStoragePartition() const { |
1592 return storage_partition_impl_; | 1614 return storage_partition_impl_; |
1593 } | 1615 } |
1594 | 1616 |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2722 } | 2744 } |
2723 | 2745 |
2724 RendererClosedDetails details(status, exit_code); | 2746 RendererClosedDetails details(status, exit_code); |
2725 | 2747 |
2726 child_process_launcher_.reset(); | 2748 child_process_launcher_.reset(); |
2727 is_dead_ = true; | 2749 is_dead_ = true; |
2728 if (route_provider_binding_.is_bound()) | 2750 if (route_provider_binding_.is_bound()) |
2729 route_provider_binding_.Close(); | 2751 route_provider_binding_.Close(); |
2730 ResetChannelProxy(); | 2752 ResetChannelProxy(); |
2731 | 2753 |
2732 UpdateProcessPriority(); | 2754 // UpdateProcessPriority(); |
2733 DCHECK(!is_process_backgrounded_); | 2755 DCHECK(!is_process_backgrounded_); |
2734 | 2756 |
2735 within_process_died_observer_ = true; | 2757 within_process_died_observer_ = true; |
2736 NotificationService::current()->Notify( | 2758 NotificationService::current()->Notify( |
2737 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2759 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2738 Details<RendererClosedDetails>(&details)); | 2760 Details<RendererClosedDetails>(&details)); |
2739 for (auto& observer : observers_) | 2761 for (auto& observer : observers_) |
2740 observer.RenderProcessExited(this, status, exit_code); | 2762 observer.RenderProcessExited(this, status, exit_code); |
2741 within_process_died_observer_ = false; | 2763 within_process_died_observer_ = false; |
2742 | 2764 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2805 for (auto& observer : observers_) | 2827 for (auto& observer : observers_) |
2806 observer.RenderProcessWillExit(this); | 2828 observer.RenderProcessWillExit(this); |
2807 | 2829 |
2808 Send(new ChildProcessMsg_Shutdown()); | 2830 Send(new ChildProcessMsg_Shutdown()); |
2809 } | 2831 } |
2810 | 2832 |
2811 void RenderProcessHostImpl::SuddenTerminationChanged(bool enabled) { | 2833 void RenderProcessHostImpl::SuddenTerminationChanged(bool enabled) { |
2812 SetSuddenTerminationAllowed(enabled); | 2834 SetSuddenTerminationAllowed(enabled); |
2813 } | 2835 } |
2814 | 2836 |
2815 void RenderProcessHostImpl::UpdateProcessPriority() { | 2837 void RenderProcessHostImpl::SetPolicy( |
| 2838 resource_coordinator::mojom::PolicyPtr policy) { |
| 2839 SetProcessPriority(policy->use_background_priority); |
| 2840 } |
| 2841 |
| 2842 void RenderProcessHostImpl::SetProcessPriority(bool should_background) { |
| 2843 LOG(ERROR) << "RenderProcessHostImpl::SetProcessPriority(" |
| 2844 << should_background << ")"; |
2816 if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) { | 2845 if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) { |
2817 is_process_backgrounded_ = false; | 2846 is_process_backgrounded_ = false; |
2818 return; | 2847 return; |
2819 } | 2848 } |
2820 | 2849 |
2821 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 2850 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
2822 switches::kDisableRendererPriorityManagement)) { | 2851 switches::kDisableRendererPriorityManagement)) { |
2823 return; | 2852 return; |
2824 } | 2853 } |
2825 | 2854 |
2826 // We background a process as soon as it hosts no active audio streams and no | 2855 // We background a process as soon as it hosts no active audio streams and no |
2827 // visible widgets -- the callers must call this function whenever we | 2856 // visible widgets -- the callers must call this function whenever we |
2828 // transition in/out of those states. | 2857 // transition in/out of those states. |
2829 const bool should_background = | 2858 // const bool should_background = |
2830 visible_widgets_ == 0 && audio_stream_count_ == 0 && | 2859 // visible_widgets_ == 0 && audio_stream_count_ == 0 && |
2831 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 2860 // !base::CommandLine::ForCurrentProcess()->HasSwitch( |
2832 switches::kDisableRendererBackgrounding); | 2861 // switches::kDisableRendererBackgrounding); |
2833 | 2862 |
2834 // TODO(sebsg): Remove this ifdef when https://crbug.com/537671 is fixed. | 2863 // TODO(sebsg): Remove this ifdef when https://crbug.com/537671 is fixed. |
2835 #if !defined(OS_ANDROID) | 2864 #if !defined(OS_ANDROID) |
2836 if (is_process_backgrounded_ == should_background) | 2865 if (is_process_backgrounded_ == should_background) |
2837 return; | 2866 return; |
2838 #endif | 2867 #endif |
2839 | 2868 |
2840 TRACE_EVENT1("renderer_host", "RenderProcessHostImpl::UpdateProcessPriority", | 2869 TRACE_EVENT1("renderer_host", "RenderProcessHostImpl::UpdateProcessPriority", |
2841 "should_background", should_background); | 2870 "should_background", should_background); |
2842 is_process_backgrounded_ = should_background; | 2871 is_process_backgrounded_ = should_background; |
(...skipping 11 matching lines...) Expand all Loading... |
2854 | 2883 |
2855 // Control the background state from the browser process, otherwise the task | 2884 // Control the background state from the browser process, otherwise the task |
2856 // telling the renderer to "unbackground" itself may be preempted by other | 2885 // telling the renderer to "unbackground" itself may be preempted by other |
2857 // tasks executing at lowered priority ahead of it or simply by not being | 2886 // tasks executing at lowered priority ahead of it or simply by not being |
2858 // swiftly scheduled by the OS per the low process priority | 2887 // swiftly scheduled by the OS per the low process priority |
2859 // (http://crbug.com/398103). | 2888 // (http://crbug.com/398103). |
2860 child_process_launcher_->SetProcessBackgrounded(should_background); | 2889 child_process_launcher_->SetProcessBackgrounded(should_background); |
2861 | 2890 |
2862 // Notify the child process of background state. | 2891 // Notify the child process of background state. |
2863 Send(new ChildProcessMsg_SetProcessBackgrounded(should_background)); | 2892 Send(new ChildProcessMsg_SetProcessBackgrounded(should_background)); |
| 2893 LOG(ERROR) << "RenderProcessHostImpl::SetProcessPriority: SUCCESS!"; |
2864 } | 2894 } |
2865 | 2895 |
2866 void RenderProcessHostImpl::OnProcessLaunched() { | 2896 void RenderProcessHostImpl::OnProcessLaunched() { |
2867 // No point doing anything, since this object will be destructed soon. We | 2897 // No point doing anything, since this object will be destructed soon. We |
2868 // especially don't want to send the RENDERER_PROCESS_CREATED notification, | 2898 // especially don't want to send the RENDERER_PROCESS_CREATED notification, |
2869 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to | 2899 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to |
2870 // properly cleanup. | 2900 // properly cleanup. |
2871 if (deleting_soon_) | 2901 if (deleting_soon_) |
2872 return; | 2902 return; |
2873 | 2903 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3069 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3099 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
3070 | 3100 |
3071 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3101 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
3072 // Capture the error message in a crash key value. | 3102 // Capture the error message in a crash key value. |
3073 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3103 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
3074 bad_message::ReceivedBadMessage(render_process_id, | 3104 bad_message::ReceivedBadMessage(render_process_id, |
3075 bad_message::RPH_MOJO_PROCESS_ERROR); | 3105 bad_message::RPH_MOJO_PROCESS_ERROR); |
3076 } | 3106 } |
3077 | 3107 |
3078 } // namespace content | 3108 } // namespace content |
OLD | NEW |