Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: content/browser/renderer_host/browser_render_process_host.cc

Issue 6927014: Avoid exiting the renderer process if it has a pending render view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix pre-render issue. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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_--;
474 }
475
476 int BrowserRenderProcessHost::PendingViewCount() const {
477 return pending_views_;
478 }
479
466 void BrowserRenderProcessHost::AppendRendererCommandLine( 480 void BrowserRenderProcessHost::AppendRendererCommandLine(
467 CommandLine* command_line) const { 481 CommandLine* command_line) const {
468 // Pass the process type first, so it shows first in process listings. 482 // Pass the process type first, so it shows first in process listings.
469 // Extensions use a special pseudo-process type to make them distinguishable, 483 // Extensions use a special pseudo-process type to make them distinguishable,
470 // even though they're just renderers. 484 // even though they're just renderers.
471 command_line->AppendSwitchASCII(switches::kProcessType, 485 command_line->AppendSwitchASCII(switches::kProcessType,
472 extension_process_ ? switches::kExtensionProcess : 486 extension_process_ ? switches::kExtensionProcess :
473 switches::kRendererProcess); 487 switches::kRendererProcess);
474 488
475 if (logging::DialogsAreSuppressed()) 489 if (logging::DialogsAreSuppressed())
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 // If we're about to be deleted, we can no longer trust that our profile is 784 // If we're about to be deleted, we can no longer trust that our profile is
771 // valid, so we ignore incoming messages. 785 // valid, so we ignore incoming messages.
772 if (deleting_soon_) 786 if (deleting_soon_)
773 return false; 787 return false;
774 788
775 mark_child_process_activity_time(); 789 mark_child_process_activity_time();
776 if (msg.routing_id() == MSG_ROUTING_CONTROL) { 790 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
777 // Dispatch control messages. 791 // Dispatch control messages.
778 bool msg_is_ok = true; 792 bool msg_is_ok = true;
779 IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok) 793 IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok)
794 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest,
795 OnShutdownRequest)
780 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, 796 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats,
781 OnUpdatedCacheStats) 797 OnUpdatedCacheStats)
782 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, 798 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged,
783 SuddenTerminationChanged) 799 SuddenTerminationChanged)
784 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, 800 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction,
785 OnUserMetricsRecordAction) 801 OnUserMetricsRecordAction)
786 IPC_MESSAGE_UNHANDLED_ERROR() 802 IPC_MESSAGE_UNHANDLED_ERROR()
787 IPC_END_MESSAGE_MAP_EX() 803 IPC_END_MESSAGE_MAP_EX()
788 804
789 if (!msg_is_ok) { 805 if (!msg_is_ok) {
(...skipping 19 matching lines...) Expand all
809 return true; 825 return true;
810 } 826 }
811 return listener->OnMessageReceived(msg); 827 return listener->OnMessageReceived(msg);
812 } 828 }
813 829
814 void BrowserRenderProcessHost::OnChannelConnected(int32 peer_pid) { 830 void BrowserRenderProcessHost::OnChannelConnected(int32 peer_pid) {
815 #if defined(IPC_MESSAGE_LOG_ENABLED) 831 #if defined(IPC_MESSAGE_LOG_ENABLED)
816 Send(new ChildProcessMsg_SetIPCLoggingEnabled( 832 Send(new ChildProcessMsg_SetIPCLoggingEnabled(
817 IPC::Logging::GetInstance()->Enabled())); 833 IPC::Logging::GetInstance()->Enabled()));
818 #endif 834 #endif
835
836 // Make sure the child checks with us before exiting, so that we do not try
837 // to schedule a new navigation in a swapped out and exiting renderer.
838 Send(new ChildProcessMsg_AskBeforeShutdown());
819 } 839 }
820 840
821 void BrowserRenderProcessHost::OnChannelError() { 841 void BrowserRenderProcessHost::OnChannelError() {
822 // Our child process has died. If we didn't expect it, it's a crash. 842 // Our child process has died. If we didn't expect it, it's a crash.
823 // In any case, we need to let everyone know it's gone. 843 // In any case, we need to let everyone know it's gone.
824 // The OnChannelError notification can fire multiple times due to nested sync 844 // The OnChannelError notification can fire multiple times due to nested sync
825 // calls to a renderer. If we don't have a valid channel here it means we 845 // calls to a renderer. If we don't have a valid channel here it means we
826 // already handled the error. 846 // already handled the error.
827 if (!channel_.get()) 847 if (!channel_.get())
828 return; 848 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 exit_code)); 884 exit_code));
865 iter.Advance(); 885 iter.Advance();
866 } 886 }
867 887
868 ClearTransportDIBCache(); 888 ClearTransportDIBCache();
869 889
870 // this object is not deleted at this point and may be reused later. 890 // this object is not deleted at this point and may be reused later.
871 // TODO(darin): clean this up 891 // TODO(darin): clean this up
872 } 892 }
873 893
894 void BrowserRenderProcessHost::OnShutdownRequest() {
895 // Don't shutdown if there are pending RenderViews being swapped back in.
896 if (pending_views_)
897 return;
898
899 // Notify any tabs that might have swapped out renderers from this process
900 // on the swapped out list. They should not attempt to swap them back in.
901 NotificationService::current()->Notify(
902 NotificationType::RENDERER_PROCESS_CLOSING,
903 Source<RenderProcessHost>(this), NotificationService::NoDetails());
904
905 Send(new ChildProcessMsg_Shutdown());
906 }
907
874 void BrowserRenderProcessHost::OnUpdatedCacheStats( 908 void BrowserRenderProcessHost::OnUpdatedCacheStats(
875 const WebCache::UsageStats& stats) { 909 const WebCache::UsageStats& stats) {
876 WebCacheManager::GetInstance()->ObserveStats(id(), stats); 910 WebCacheManager::GetInstance()->ObserveStats(id(), stats);
877 } 911 }
878 912
879 void BrowserRenderProcessHost::SuddenTerminationChanged(bool enabled) { 913 void BrowserRenderProcessHost::SuddenTerminationChanged(bool enabled) {
880 set_sudden_termination_allowed(enabled); 914 set_sudden_termination_allowed(enabled);
881 } 915 }
882 916
883 void BrowserRenderProcessHost::SetBackgrounded(bool backgrounded) { 917 void BrowserRenderProcessHost::SetBackgrounded(bool backgrounded) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 while (!queued_messages_.empty()) { 966 while (!queued_messages_.empty()) {
933 Send(queued_messages_.front()); 967 Send(queued_messages_.front());
934 queued_messages_.pop(); 968 queued_messages_.pop();
935 } 969 }
936 } 970 }
937 971
938 void BrowserRenderProcessHost::OnUserMetricsRecordAction( 972 void BrowserRenderProcessHost::OnUserMetricsRecordAction(
939 const std::string& action) { 973 const std::string& action) {
940 UserMetrics::RecordComputedAction(action); 974 UserMetrics::RecordComputedAction(action);
941 } 975 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698