| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "chrome/browser/renderer_host/browser_render_process_host.h" | 8 #include "chrome/browser/renderer_host/browser_render_process_host.h" |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 VisitedLinkCommon::Fingerprints pending_; | 186 VisitedLinkCommon::Fingerprints pending_; |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) | 189 BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) |
| 190 : RenderProcessHost(profile), | 190 : RenderProcessHost(profile), |
| 191 visible_widgets_(0), | 191 visible_widgets_(0), |
| 192 backgrounded_(true), | 192 backgrounded_(true), |
| 193 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( | 193 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( |
| 194 base::TimeDelta::FromSeconds(5), | 194 base::TimeDelta::FromSeconds(5), |
| 195 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), | 195 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), |
| 196 zygote_child_(false) { | 196 zygote_child_(false), |
| 197 fast_shutdown_(false) { |
| 197 widget_helper_ = new RenderWidgetHelper(); | 198 widget_helper_ = new RenderWidgetHelper(); |
| 198 | 199 |
| 199 registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED, | 200 registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED, |
| 200 NotificationService::AllSources()); | 201 NotificationService::AllSources()); |
| 201 visited_link_updater_.reset(new VisitedLinkUpdater()); | 202 visited_link_updater_.reset(new VisitedLinkUpdater()); |
| 202 | 203 |
| 203 WebCacheManager::GetInstance()->Add(id()); | 204 WebCacheManager::GetInstance()->Add(id()); |
| 204 ChildProcessSecurityPolicy::GetInstance()->Add(id()); | 205 ChildProcessSecurityPolicy::GetInstance()->Add(id()); |
| 205 | 206 |
| 206 // Note: When we create the BrowserRenderProcessHost, it's technically | 207 // Note: When we create the BrowserRenderProcessHost, it's technically |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 #if defined(OS_LINUX) | 434 #if defined(OS_LINUX) |
| 434 } | 435 } |
| 435 #endif // defined(OS_LINUX) | 436 #endif // defined(OS_LINUX) |
| 436 #endif // defined(OS_POSIX) | 437 #endif // defined(OS_POSIX) |
| 437 | 438 |
| 438 if (!process) { | 439 if (!process) { |
| 439 channel_.reset(); | 440 channel_.reset(); |
| 440 return false; | 441 return false; |
| 441 } | 442 } |
| 442 process_.set_handle(process); | 443 process_.set_handle(process); |
| 444 fast_shutdown_ = false; |
| 443 | 445 |
| 444 // Log the launch time, separating out the first one (which will likely be | 446 // Log the launch time, separating out the first one (which will likely be |
| 445 // slower due to the rest of the browser initializing at the same time). | 447 // slower due to the rest of the browser initializing at the same time). |
| 446 static bool done_first_launch = false; | 448 static bool done_first_launch = false; |
| 447 if (done_first_launch) { | 449 if (done_first_launch) { |
| 448 UMA_HISTOGRAM_TIMES("MPArch.RendererLaunchSubsequent", | 450 UMA_HISTOGRAM_TIMES("MPArch.RendererLaunchSubsequent", |
| 449 base::TimeTicks::Now() - begin_launch_time); | 451 base::TimeTicks::Now() - begin_launch_time); |
| 450 } else { | 452 } else { |
| 451 UMA_HISTOGRAM_TIMES("MPArch.RendererLaunchFirst", | 453 UMA_HISTOGRAM_TIMES("MPArch.RendererLaunchFirst", |
| 452 base::TimeTicks::Now() - begin_launch_time); | 454 base::TimeTicks::Now() - begin_launch_time); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 if (rvh->delegate()->IsExternalTabContainer()) | 630 if (rvh->delegate()->IsExternalTabContainer()) |
| 629 return false; | 631 return false; |
| 630 } | 632 } |
| 631 | 633 |
| 632 iter.Advance(); | 634 iter.Advance(); |
| 633 } | 635 } |
| 634 | 636 |
| 635 // Otherwise, we're allowed to just terminate the process. Using exit code 0 | 637 // Otherwise, we're allowed to just terminate the process. Using exit code 0 |
| 636 // means that UMA won't treat this as a renderer crash. | 638 // means that UMA won't treat this as a renderer crash. |
| 637 process_.Terminate(ResultCodes::NORMAL_EXIT); | 639 process_.Terminate(ResultCodes::NORMAL_EXIT); |
| 640 process_.Close(); |
| 641 fast_shutdown_ = true; |
| 638 return true; | 642 return true; |
| 639 } | 643 } |
| 640 | 644 |
| 641 bool BrowserRenderProcessHost::SendWithTimeout(IPC::Message* msg, | 645 bool BrowserRenderProcessHost::SendWithTimeout(IPC::Message* msg, |
| 642 int timeout_ms) { | 646 int timeout_ms) { |
| 643 if (!channel_.get()) { | 647 if (!channel_.get()) { |
| 644 delete msg; | 648 delete msg; |
| 645 return false; | 649 return false; |
| 646 } | 650 } |
| 647 return channel_->SendWithTimeout(msg, timeout_ms); | 651 return channel_->SendWithTimeout(msg, timeout_ms); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 Send(reply); | 758 Send(reply); |
| 755 } | 759 } |
| 756 return; | 760 return; |
| 757 } | 761 } |
| 758 listener->OnMessageReceived(msg); | 762 listener->OnMessageReceived(msg); |
| 759 } | 763 } |
| 760 | 764 |
| 761 void BrowserRenderProcessHost::OnChannelConnected(int32 peer_pid) { | 765 void BrowserRenderProcessHost::OnChannelConnected(int32 peer_pid) { |
| 762 // process_ is not NULL if we created the renderer process | 766 // process_ is not NULL if we created the renderer process |
| 763 if (!process_.handle()) { | 767 if (!process_.handle()) { |
| 764 if (base::GetCurrentProcId() == peer_pid) { | 768 if (fast_shutdown_) { |
| 769 // We terminated the process, but the ChannelConnected task was still |
| 770 // in the queue. We can safely ignore it. |
| 771 return; |
| 772 } else if (base::GetCurrentProcId() == peer_pid) { |
| 765 // We are in single-process mode. In theory we should have access to | 773 // We are in single-process mode. In theory we should have access to |
| 766 // ourself but it may happen that we don't. | 774 // ourself but it may happen that we don't. |
| 767 process_.set_handle(base::GetCurrentProcessHandle()); | 775 process_.set_handle(base::GetCurrentProcessHandle()); |
| 768 } else { | 776 } else { |
| 769 #if defined(OS_WIN) | 777 #if defined(OS_WIN) |
| 770 // Request MAXIMUM_ALLOWED to match the access a handle | 778 // Request MAXIMUM_ALLOWED to match the access a handle |
| 771 // returned by CreateProcess() has to the process object. | 779 // returned by CreateProcess() has to the process object. |
| 772 process_.set_handle(OpenProcess(MAXIMUM_ALLOWED, FALSE, peer_pid)); | 780 process_.set_handle(OpenProcess(MAXIMUM_ALLOWED, FALSE, peer_pid)); |
| 773 #else | 781 #else |
| 774 NOTREACHED(); | 782 NOTREACHED(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 803 // In single process mode it is better if we don't suicide but just crash. | 811 // In single process mode it is better if we don't suicide but just crash. |
| 804 CHECK(false); | 812 CHECK(false); |
| 805 } | 813 } |
| 806 NOTREACHED(); | 814 NOTREACHED(); |
| 807 base::KillProcess(process, ResultCodes::KILLED_BAD_MESSAGE, false); | 815 base::KillProcess(process, ResultCodes::KILLED_BAD_MESSAGE, false); |
| 808 } | 816 } |
| 809 | 817 |
| 810 void BrowserRenderProcessHost::OnChannelError() { | 818 void BrowserRenderProcessHost::OnChannelError() { |
| 811 // Our child process has died. If we didn't expect it, it's a crash. | 819 // Our child process has died. If we didn't expect it, it's a crash. |
| 812 // In any case, we need to let everyone know it's gone. | 820 // In any case, we need to let everyone know it's gone. |
| 813 | |
| 814 DCHECK(process_.handle()); | |
| 815 DCHECK(channel_.get()); | 821 DCHECK(channel_.get()); |
| 816 | 822 |
| 817 bool child_exited; | 823 bool child_exited; |
| 818 bool did_crash; | 824 bool did_crash; |
| 819 if (zygote_child_) { | 825 if (!process_.handle()) { |
| 826 // The process has been terminated (likely FastShutdownIfPossible). |
| 827 did_crash = false; |
| 828 child_exited = true; |
| 829 } else if (zygote_child_) { |
| 820 #if defined(OS_LINUX) | 830 #if defined(OS_LINUX) |
| 821 did_crash = Singleton<ZygoteHost>()->DidProcessCrash( | 831 did_crash = Singleton<ZygoteHost>()->DidProcessCrash( |
| 822 process_.handle(), &child_exited); | 832 process_.handle(), &child_exited); |
| 823 #else | 833 #else |
| 824 NOTREACHED(); | 834 NOTREACHED(); |
| 825 did_crash = true; | 835 did_crash = true; |
| 826 #endif | 836 #endif |
| 827 } else { | 837 } else { |
| 828 did_crash = base::DidProcessCrash(&child_exited, process_.handle()); | 838 did_crash = base::DidProcessCrash(&child_exited, process_.handle()); |
| 829 } | 839 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 profile()->GetExtensionMessageService()->RemoveEventListener( | 970 profile()->GetExtensionMessageService()->RemoveEventListener( |
| 961 event_name, id()); | 971 event_name, id()); |
| 962 } | 972 } |
| 963 } | 973 } |
| 964 | 974 |
| 965 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { | 975 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { |
| 966 if (profile()->GetExtensionMessageService()) { | 976 if (profile()->GetExtensionMessageService()) { |
| 967 profile()->GetExtensionMessageService()->CloseChannel(port_id); | 977 profile()->GetExtensionMessageService()->CloseChannel(port_id); |
| 968 } | 978 } |
| 969 } | 979 } |
| OLD | NEW |