Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_render_process_host.h" | 8 #include "content/browser/renderer_host/browser_render_process_host.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 | 180 |
| 181 scoped_refptr<net::URLRequestContextGetter> request_context_; | 181 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 182 scoped_refptr<net::URLRequestContextGetter> media_request_context_; | 182 scoped_refptr<net::URLRequestContextGetter> media_request_context_; |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 } // namespace | 185 } // namespace |
| 186 | 186 |
| 187 BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) | 187 BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) |
| 188 : RenderProcessHost(profile), | 188 : RenderProcessHost(profile), |
| 189 visible_widgets_(0), | 189 visible_widgets_(0), |
| 190 pending_views_(0), | |
| 190 backgrounded_(true), | 191 backgrounded_(true), |
| 191 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( | 192 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( |
| 192 base::TimeDelta::FromSeconds(5), | 193 base::TimeDelta::FromSeconds(5), |
| 193 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), | 194 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), |
| 194 accessibility_enabled_(false), | 195 accessibility_enabled_(false), |
| 195 extension_process_(false) { | 196 extension_process_(false) { |
| 196 widget_helper_ = new RenderWidgetHelper(); | 197 widget_helper_ = new RenderWidgetHelper(); |
| 197 | 198 |
| 198 WebCacheManager::GetInstance()->Add(id()); | 199 WebCacheManager::GetInstance()->Add(id()); |
| 199 ChildProcessSecurityPolicy::GetInstance()->Add(id()); | 200 ChildProcessSecurityPolicy::GetInstance()->Add(id()); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 if (visible_widgets_ == 0) { | 457 if (visible_widgets_ == 0) { |
| 457 DCHECK(!backgrounded_); | 458 DCHECK(!backgrounded_); |
| 458 SetBackgrounded(true); | 459 SetBackgrounded(true); |
| 459 } | 460 } |
| 460 } | 461 } |
| 461 | 462 |
| 462 int BrowserRenderProcessHost::VisibleWidgetCount() const { | 463 int BrowserRenderProcessHost::VisibleWidgetCount() const { |
| 463 return visible_widgets_; | 464 return visible_widgets_; |
| 464 } | 465 } |
| 465 | 466 |
| 467 void BrowserRenderProcessHost::AddPendingView() { | |
| 468 pending_views_++; | |
| 469 } | |
| 470 | |
| 471 void BrowserRenderProcessHost::RemovePendingView() { | |
| 472 DCHECK(pending_views_); | |
| 473 pending_views_--; | |
|
Matt Perry
2011/05/10 01:14:50
does this need to send a shutdown if pending_views
Charlie Reis
2011/05/10 01:33:09
Nope-- it'll also reach 0 if we commit the view an
| |
| 474 } | |
| 475 | |
| 466 void BrowserRenderProcessHost::AppendRendererCommandLine( | 476 void BrowserRenderProcessHost::AppendRendererCommandLine( |
| 467 CommandLine* command_line) const { | 477 CommandLine* command_line) const { |
| 468 // Pass the process type first, so it shows first in process listings. | 478 // Pass the process type first, so it shows first in process listings. |
| 469 // Extensions use a special pseudo-process type to make them distinguishable, | 479 // Extensions use a special pseudo-process type to make them distinguishable, |
| 470 // even though they're just renderers. | 480 // even though they're just renderers. |
| 471 command_line->AppendSwitchASCII(switches::kProcessType, | 481 command_line->AppendSwitchASCII(switches::kProcessType, |
| 472 extension_process_ ? switches::kExtensionProcess : | 482 extension_process_ ? switches::kExtensionProcess : |
| 473 switches::kRendererProcess); | 483 switches::kRendererProcess); |
| 474 | 484 |
| 475 if (logging::DialogsAreSuppressed()) | 485 if (logging::DialogsAreSuppressed()) |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 777 // If we're about to be deleted, we can no longer trust that our profile is | 787 // If we're about to be deleted, we can no longer trust that our profile is |
| 778 // valid, so we ignore incoming messages. | 788 // valid, so we ignore incoming messages. |
| 779 if (deleting_soon_) | 789 if (deleting_soon_) |
| 780 return false; | 790 return false; |
| 781 | 791 |
| 782 mark_child_process_activity_time(); | 792 mark_child_process_activity_time(); |
| 783 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 793 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
| 784 // Dispatch control messages. | 794 // Dispatch control messages. |
| 785 bool msg_is_ok = true; | 795 bool msg_is_ok = true; |
| 786 IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok) | 796 IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok) |
| 797 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest, | |
| 798 OnShutdownRequest) | |
| 787 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, | 799 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, |
| 788 OnUpdatedCacheStats) | 800 OnUpdatedCacheStats) |
| 789 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, | 801 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, |
| 790 SuddenTerminationChanged) | 802 SuddenTerminationChanged) |
| 791 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, | 803 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, |
| 792 OnUserMetricsRecordAction) | 804 OnUserMetricsRecordAction) |
| 793 IPC_MESSAGE_UNHANDLED_ERROR() | 805 IPC_MESSAGE_UNHANDLED_ERROR() |
| 794 IPC_END_MESSAGE_MAP_EX() | 806 IPC_END_MESSAGE_MAP_EX() |
| 795 | 807 |
| 796 if (!msg_is_ok) { | 808 if (!msg_is_ok) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 816 return true; | 828 return true; |
| 817 } | 829 } |
| 818 return listener->OnMessageReceived(msg); | 830 return listener->OnMessageReceived(msg); |
| 819 } | 831 } |
| 820 | 832 |
| 821 void BrowserRenderProcessHost::OnChannelConnected(int32 peer_pid) { | 833 void BrowserRenderProcessHost::OnChannelConnected(int32 peer_pid) { |
| 822 #if defined(IPC_MESSAGE_LOG_ENABLED) | 834 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 823 Send(new ChildProcessMsg_SetIPCLoggingEnabled( | 835 Send(new ChildProcessMsg_SetIPCLoggingEnabled( |
| 824 IPC::Logging::GetInstance()->Enabled())); | 836 IPC::Logging::GetInstance()->Enabled())); |
| 825 #endif | 837 #endif |
| 838 | |
| 839 // Make sure the child checks with us before exiting, so that we do not try | |
| 840 // to schedule a new navigation in a swapped out and exiting renderer. | |
| 841 Send(new ChildProcessMsg_AskBeforeShutdown()); | |
| 826 } | 842 } |
| 827 | 843 |
| 828 void BrowserRenderProcessHost::OnChannelError() { | 844 void BrowserRenderProcessHost::OnChannelError() { |
| 829 // Our child process has died. If we didn't expect it, it's a crash. | 845 // Our child process has died. If we didn't expect it, it's a crash. |
| 830 // In any case, we need to let everyone know it's gone. | 846 // In any case, we need to let everyone know it's gone. |
| 831 // The OnChannelError notification can fire multiple times due to nested sync | 847 // The OnChannelError notification can fire multiple times due to nested sync |
| 832 // calls to a renderer. If we don't have a valid channel here it means we | 848 // calls to a renderer. If we don't have a valid channel here it means we |
| 833 // already handled the error. | 849 // already handled the error. |
| 834 if (!channel_.get()) | 850 if (!channel_.get()) |
| 835 return; | 851 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 exit_code)); | 887 exit_code)); |
| 872 iter.Advance(); | 888 iter.Advance(); |
| 873 } | 889 } |
| 874 | 890 |
| 875 ClearTransportDIBCache(); | 891 ClearTransportDIBCache(); |
| 876 | 892 |
| 877 // this object is not deleted at this point and may be reused later. | 893 // this object is not deleted at this point and may be reused later. |
| 878 // TODO(darin): clean this up | 894 // TODO(darin): clean this up |
| 879 } | 895 } |
| 880 | 896 |
| 897 void BrowserRenderProcessHost::OnShutdownRequest() { | |
| 898 // Don't shutdown if there are pending RenderViews being swapped back in. | |
| 899 if (pending_views_) | |
| 900 return; | |
| 901 | |
| 902 // Notify any tabs that might have swapped out renderers from this process. | |
| 903 // They should not attempt to swap them back in. | |
| 904 NotificationService::current()->Notify( | |
| 905 NotificationType::RENDERER_PROCESS_CLOSING, | |
| 906 Source<RenderProcessHost>(this), NotificationService::NoDetails()); | |
| 907 | |
| 908 Send(new ChildProcessMsg_Shutdown()); | |
| 909 } | |
| 910 | |
| 881 void BrowserRenderProcessHost::OnUpdatedCacheStats( | 911 void BrowserRenderProcessHost::OnUpdatedCacheStats( |
| 882 const WebCache::UsageStats& stats) { | 912 const WebCache::UsageStats& stats) { |
| 883 WebCacheManager::GetInstance()->ObserveStats(id(), stats); | 913 WebCacheManager::GetInstance()->ObserveStats(id(), stats); |
| 884 } | 914 } |
| 885 | 915 |
| 886 void BrowserRenderProcessHost::SuddenTerminationChanged(bool enabled) { | 916 void BrowserRenderProcessHost::SuddenTerminationChanged(bool enabled) { |
| 887 set_sudden_termination_allowed(enabled); | 917 set_sudden_termination_allowed(enabled); |
| 888 } | 918 } |
| 889 | 919 |
| 890 void BrowserRenderProcessHost::SetBackgrounded(bool backgrounded) { | 920 void BrowserRenderProcessHost::SetBackgrounded(bool backgrounded) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 while (!queued_messages_.empty()) { | 969 while (!queued_messages_.empty()) { |
| 940 Send(queued_messages_.front()); | 970 Send(queued_messages_.front()); |
| 941 queued_messages_.pop(); | 971 queued_messages_.pop(); |
| 942 } | 972 } |
| 943 } | 973 } |
| 944 | 974 |
| 945 void BrowserRenderProcessHost::OnUserMetricsRecordAction( | 975 void BrowserRenderProcessHost::OnUserMetricsRecordAction( |
| 946 const std::string& action) { | 976 const std::string& action) { |
| 947 UserMetrics::RecordComputedAction(action); | 977 UserMetrics::RecordComputedAction(action); |
| 948 } | 978 } |
| OLD | NEW |