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 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 id_, | 940 id_, |
941 storage_partition_impl_->GetURLRequestContext(), | 941 storage_partition_impl_->GetURLRequestContext(), |
942 storage_partition_impl_->GetIndexedDBContext(), | 942 storage_partition_impl_->GetIndexedDBContext(), |
943 ChromeBlobStorageContext::GetFor(browser_context_))), | 943 ChromeBlobStorageContext::GetFor(browser_context_))), |
944 channel_connected_(false), | 944 channel_connected_(false), |
945 sent_render_process_ready_(false), | 945 sent_render_process_ready_(false), |
946 #if defined(OS_ANDROID) | 946 #if defined(OS_ANDROID) |
947 never_signaled_(base::WaitableEvent::ResetPolicy::MANUAL, | 947 never_signaled_(base::WaitableEvent::ResetPolicy::MANUAL, |
948 base::WaitableEvent::InitialState::NOT_SIGNALED), | 948 base::WaitableEvent::InitialState::NOT_SIGNALED), |
949 #endif | 949 #endif |
| 950 resource_coordinator_binding_(this), |
950 instance_weak_factory_( | 951 instance_weak_factory_( |
951 new base::WeakPtrFactory<RenderProcessHostImpl>(this)), | 952 new base::WeakPtrFactory<RenderProcessHostImpl>(this)), |
952 frame_sink_provider_(id_), | 953 frame_sink_provider_(id_), |
953 weak_factory_(this) { | 954 weak_factory_(this) { |
954 widget_helper_ = new RenderWidgetHelper(); | 955 widget_helper_ = new RenderWidgetHelper(); |
955 | 956 |
956 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); | 957 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); |
957 | 958 |
958 CHECK(!BrowserMainRunner::ExitedMainMessageLoop()); | 959 CHECK(!BrowserMainRunner::ExitedMainMessageLoop()); |
959 RegisterHost(GetID(), this); | 960 RegisterHost(GetID(), this); |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 base::debug::DumpWithoutCrashing(); | 1808 base::debug::DumpWithoutCrashing(); |
1808 } | 1809 } |
1809 | 1810 |
1810 // Log the renderer kill to the histogram tracking all kills. | 1811 // Log the renderer kill to the histogram tracking all kills. |
1811 BrowserChildProcessHostImpl::HistogramBadMessageTerminated( | 1812 BrowserChildProcessHostImpl::HistogramBadMessageTerminated( |
1812 PROCESS_TYPE_RENDERER); | 1813 PROCESS_TYPE_RENDERER); |
1813 } | 1814 } |
1814 | 1815 |
1815 void RenderProcessHostImpl::WidgetRestored() { | 1816 void RenderProcessHostImpl::WidgetRestored() { |
1816 visible_widgets_++; | 1817 visible_widgets_++; |
1817 UpdateProcessPriority(); | 1818 // UpdateProcessPriority(); |
1818 } | 1819 } |
1819 | 1820 |
1820 void RenderProcessHostImpl::WidgetHidden() { | 1821 void RenderProcessHostImpl::WidgetHidden() { |
1821 // On startup, the browser will call Hide. We ignore this call. | 1822 // On startup, the browser will call Hide. We ignore this call. |
1822 if (visible_widgets_ == 0) | 1823 if (visible_widgets_ == 0) |
1823 return; | 1824 return; |
1824 | 1825 |
1825 --visible_widgets_; | 1826 --visible_widgets_; |
1826 if (visible_widgets_ == 0) { | 1827 if (visible_widgets_ == 0) { |
1827 UpdateProcessPriority(); | 1828 // UpdateProcessPriority(); |
1828 } | 1829 } |
1829 } | 1830 } |
1830 | 1831 |
1831 int RenderProcessHostImpl::VisibleWidgetCount() const { | 1832 int RenderProcessHostImpl::VisibleWidgetCount() const { |
1832 return visible_widgets_; | 1833 return visible_widgets_; |
1833 } | 1834 } |
1834 | 1835 |
1835 void RenderProcessHostImpl::OnAudioStreamAdded() { | 1836 void RenderProcessHostImpl::OnAudioStreamAdded() { |
1836 ++audio_stream_count_; | 1837 if (++audio_stream_count_ == 1) { |
1837 UpdateProcessPriority(); | 1838 GetProcessResourceCoordinator()->SendEvent( |
| 1839 resource_coordinator::EventType::kOnProcessAudioStarted); |
| 1840 } |
| 1841 // UpdateProcessPriority(); |
1838 } | 1842 } |
1839 | 1843 |
1840 void RenderProcessHostImpl::OnAudioStreamRemoved() { | 1844 void RenderProcessHostImpl::OnAudioStreamRemoved() { |
1841 DCHECK_GT(audio_stream_count_, 0); | 1845 DCHECK_GT(audio_stream_count_, 0); |
1842 --audio_stream_count_; | 1846 if (--audio_stream_count_ == 0) { |
1843 UpdateProcessPriority(); | 1847 GetProcessResourceCoordinator()->SendEvent( |
| 1848 resource_coordinator::EventType::kOnProcessAudioStopped); |
| 1849 } |
| 1850 // UpdateProcessPriority(); |
| 1851 } |
| 1852 |
| 1853 resource_coordinator::ResourceCoordinatorInterface* |
| 1854 RenderProcessHostImpl::GetProcessResourceCoordinator() { |
| 1855 if (!process_resource_coordinator_) { |
| 1856 process_resource_coordinator_ = |
| 1857 base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>( |
| 1858 ServiceManagerConnection::GetForProcess()->GetConnector(), |
| 1859 resource_coordinator::CoordinationUnitType::kProcess); |
| 1860 |
| 1861 process_resource_coordinator_->service()->SetCoordinationPolicyCallback( |
| 1862 resource_coordinator_binding_.CreateInterfacePtrAndBind()); |
| 1863 } |
| 1864 |
| 1865 return process_resource_coordinator_.get(); |
1844 } | 1866 } |
1845 | 1867 |
1846 void RenderProcessHostImpl::set_render_process_host_factory( | 1868 void RenderProcessHostImpl::set_render_process_host_factory( |
1847 const RenderProcessHostFactory* rph_factory) { | 1869 const RenderProcessHostFactory* rph_factory) { |
1848 g_render_process_host_factory_ = rph_factory; | 1870 g_render_process_host_factory_ = rph_factory; |
1849 } | 1871 } |
1850 | 1872 |
1851 // static | 1873 // static |
1852 void RenderProcessHostImpl::AddFrameWithSite( | 1874 void RenderProcessHostImpl::AddFrameWithSite( |
1853 BrowserContext* browser_context, | 1875 BrowserContext* browser_context, |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2611 // Remove ourself from the list of renderer processes so that we can't be | 2633 // Remove ourself from the list of renderer processes so that we can't be |
2612 // reused in between now and when the Delete task runs. | 2634 // reused in between now and when the Delete task runs. |
2613 UnregisterHost(GetID()); | 2635 UnregisterHost(GetID()); |
2614 | 2636 |
2615 instance_weak_factory_.reset( | 2637 instance_weak_factory_.reset( |
2616 new base::WeakPtrFactory<RenderProcessHostImpl>(this)); | 2638 new base::WeakPtrFactory<RenderProcessHostImpl>(this)); |
2617 } | 2639 } |
2618 | 2640 |
2619 void RenderProcessHostImpl::AddPendingView() { | 2641 void RenderProcessHostImpl::AddPendingView() { |
2620 pending_views_++; | 2642 pending_views_++; |
2621 UpdateProcessPriority(); | 2643 // UpdateProcessPriority(); |
2622 } | 2644 } |
2623 | 2645 |
2624 void RenderProcessHostImpl::RemovePendingView() { | 2646 void RenderProcessHostImpl::RemovePendingView() { |
2625 DCHECK(pending_views_); | 2647 DCHECK(pending_views_); |
2626 pending_views_--; | 2648 pending_views_--; |
2627 UpdateProcessPriority(); | 2649 // UpdateProcessPriority(); |
2628 } | 2650 } |
2629 | 2651 |
2630 void RenderProcessHostImpl::AddWidget(RenderWidgetHost* widget) { | 2652 void RenderProcessHostImpl::AddWidget(RenderWidgetHost* widget) { |
2631 widgets_.insert(static_cast<RenderWidgetHostImpl*>(widget)); | 2653 widgets_.insert(static_cast<RenderWidgetHostImpl*>(widget)); |
2632 } | 2654 } |
2633 | 2655 |
2634 void RenderProcessHostImpl::RemoveWidget(RenderWidgetHost* widget) { | 2656 void RenderProcessHostImpl::RemoveWidget(RenderWidgetHost* widget) { |
2635 widgets_.erase(static_cast<RenderWidgetHostImpl*>(widget)); | 2657 widgets_.erase(static_cast<RenderWidgetHostImpl*>(widget)); |
2636 } | 2658 } |
2637 | 2659 |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3144 | 3166 |
3145 RendererClosedDetails details(status, exit_code); | 3167 RendererClosedDetails details(status, exit_code); |
3146 | 3168 |
3147 child_process_launcher_.reset(); | 3169 child_process_launcher_.reset(); |
3148 is_dead_ = true; | 3170 is_dead_ = true; |
3149 if (route_provider_binding_.is_bound()) | 3171 if (route_provider_binding_.is_bound()) |
3150 route_provider_binding_.Close(); | 3172 route_provider_binding_.Close(); |
3151 associated_interfaces_.reset(); | 3173 associated_interfaces_.reset(); |
3152 ResetChannelProxy(); | 3174 ResetChannelProxy(); |
3153 | 3175 |
3154 UpdateProcessPriority(); | 3176 // UpdateProcessPriority(); |
3155 | 3177 |
3156 within_process_died_observer_ = true; | 3178 within_process_died_observer_ = true; |
3157 NotificationService::current()->Notify( | 3179 NotificationService::current()->Notify( |
3158 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 3180 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
3159 Details<RendererClosedDetails>(&details)); | 3181 Details<RendererClosedDetails>(&details)); |
3160 for (auto& observer : observers_) | 3182 for (auto& observer : observers_) |
3161 observer.RenderProcessExited(this, status, exit_code); | 3183 observer.RenderProcessExited(this, status, exit_code); |
3162 within_process_died_observer_ = false; | 3184 within_process_died_observer_ = false; |
3163 | 3185 |
3164 RemoveUserData(kSessionStorageHolderKey); | 3186 RemoveUserData(kSessionStorageHolderKey); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3237 for (auto& observer : observers_) | 3259 for (auto& observer : observers_) |
3238 observer.RenderProcessWillExit(this); | 3260 observer.RenderProcessWillExit(this); |
3239 | 3261 |
3240 Send(new ChildProcessMsg_Shutdown()); | 3262 Send(new ChildProcessMsg_Shutdown()); |
3241 } | 3263 } |
3242 | 3264 |
3243 void RenderProcessHostImpl::SuddenTerminationChanged(bool enabled) { | 3265 void RenderProcessHostImpl::SuddenTerminationChanged(bool enabled) { |
3244 SetSuddenTerminationAllowed(enabled); | 3266 SetSuddenTerminationAllowed(enabled); |
3245 } | 3267 } |
3246 | 3268 |
3247 void RenderProcessHostImpl::UpdateProcessPriority() { | 3269 void RenderProcessHostImpl::SetCoordinationPolicy( |
| 3270 resource_coordinator::mojom::CoordinationPolicyPtr policy) { |
| 3271 SetProcessPriority(policy->use_background_priority); |
| 3272 } |
| 3273 |
| 3274 void RenderProcessHostImpl::SetProcessPriority(bool should_background) { |
| 3275 LOG(ERROR) << "RenderProcessHostImpl::SetProcessPriority(" |
| 3276 << should_background << ")"; |
3248 if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) { | 3277 if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) { |
3249 is_process_backgrounded_ = kLaunchingProcessIsBackgrounded; | 3278 is_process_backgrounded_ = kLaunchingProcessIsBackgrounded; |
3250 boost_priority_for_pending_views_ = | 3279 boost_priority_for_pending_views_ = |
3251 kLaunchingProcessIsBoostedForPendingView; | 3280 kLaunchingProcessIsBoostedForPendingView; |
3252 return; | 3281 return; |
3253 } | 3282 } |
3254 | 3283 |
3255 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 3284 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
3256 switches::kDisableRendererPriorityManagement)) { | 3285 switches::kDisableRendererPriorityManagement)) { |
3257 return; | 3286 return; |
3258 } | 3287 } |
3259 | 3288 |
3260 // We background a process as soon as it hosts no active audio streams and no | 3289 // We background a process as soon as it hosts no active audio streams and no |
3261 // visible widgets -- the callers must call this function whenever we | 3290 // visible widgets -- the callers must call this function whenever we |
3262 // transition in/out of those states. | 3291 // transition in/out of those states. |
3263 const bool should_background = | 3292 // const bool should_background = |
3264 visible_widgets_ == 0 && audio_stream_count_ == 0 && | 3293 // visible_widgets_ == 0 && audio_stream_count_ == 0 && |
3265 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 3294 // !base::CommandLine::ForCurrentProcess()->HasSwitch( |
3266 switches::kDisableRendererBackgrounding); | 3295 // switches::kDisableRendererBackgrounding); |
3267 const bool should_background_changed = | 3296 const bool should_background_changed = |
3268 is_process_backgrounded_ != should_background; | 3297 is_process_backgrounded_ != should_background; |
3269 const bool has_pending_views = !!pending_views_; | 3298 const bool has_pending_views = !!pending_views_; |
3270 | 3299 |
3271 if (!should_background_changed && | 3300 if (!should_background_changed && |
3272 boost_priority_for_pending_views_ == has_pending_views) { | 3301 boost_priority_for_pending_views_ == has_pending_views) { |
3273 return; | 3302 return; |
3274 } | 3303 } |
3275 | 3304 |
3276 TRACE_EVENT2("renderer_host", "RenderProcessHostImpl::UpdateProcessPriority", | 3305 TRACE_EVENT2("renderer_host", "RenderProcessHostImpl::UpdateProcessPriority", |
(...skipping 17 matching lines...) Expand all Loading... |
3294 // telling the renderer to "unbackground" itself may be preempted by other | 3323 // telling the renderer to "unbackground" itself may be preempted by other |
3295 // tasks executing at lowered priority ahead of it or simply by not being | 3324 // tasks executing at lowered priority ahead of it or simply by not being |
3296 // swiftly scheduled by the OS per the low process priority | 3325 // swiftly scheduled by the OS per the low process priority |
3297 // (http://crbug.com/398103). | 3326 // (http://crbug.com/398103). |
3298 child_process_launcher_->SetProcessPriority(should_background, | 3327 child_process_launcher_->SetProcessPriority(should_background, |
3299 has_pending_views); | 3328 has_pending_views); |
3300 | 3329 |
3301 // Notify the child process of background state. Note | 3330 // Notify the child process of background state. Note |
3302 // |boost_priority_for_pending_views_| state is not sent to renderer simply | 3331 // |boost_priority_for_pending_views_| state is not sent to renderer simply |
3303 // due to lack of need. | 3332 // due to lack of need. |
3304 if (should_background_changed) | 3333 if (should_background_changed) { |
3305 Send(new ChildProcessMsg_SetProcessBackgrounded(should_background)); | 3334 Send(new ChildProcessMsg_SetProcessBackgrounded(should_background)); |
| 3335 LOG(ERROR) << "RenderProcessHostImpl::SetProcessPriority: SUCCESS!"; |
| 3336 } |
3306 } | 3337 } |
3307 | 3338 |
3308 void RenderProcessHostImpl::OnProcessLaunched() { | 3339 void RenderProcessHostImpl::OnProcessLaunched() { |
3309 // No point doing anything, since this object will be destructed soon. We | 3340 // No point doing anything, since this object will be destructed soon. We |
3310 // especially don't want to send the RENDERER_PROCESS_CREATED notification, | 3341 // especially don't want to send the RENDERER_PROCESS_CREATED notification, |
3311 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to | 3342 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to |
3312 // properly cleanup. | 3343 // properly cleanup. |
3313 if (deleting_soon_) | 3344 if (deleting_soon_) |
3314 return; | 3345 return; |
3315 | 3346 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3574 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3605 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
3575 | 3606 |
3576 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3607 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
3577 // Capture the error message in a crash key value. | 3608 // Capture the error message in a crash key value. |
3578 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3609 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
3579 bad_message::ReceivedBadMessage(render_process_id, | 3610 bad_message::ReceivedBadMessage(render_process_id, |
3580 bad_message::RPH_MOJO_PROCESS_ERROR); | 3611 bad_message::RPH_MOJO_PROCESS_ERROR); |
3581 } | 3612 } |
3582 | 3613 |
3583 } // namespace content | 3614 } // namespace content |
OLD | NEW |