| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 #include "content/public/common/process_type.h" | 154 #include "content/public/common/process_type.h" |
| 155 #include "content/public/common/resource_type.h" | 155 #include "content/public/common/resource_type.h" |
| 156 #include "content/public/common/result_codes.h" | 156 #include "content/public/common/result_codes.h" |
| 157 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 157 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 158 #include "content/public/common/url_constants.h" | 158 #include "content/public/common/url_constants.h" |
| 159 #include "device/battery/battery_monitor_impl.h" | 159 #include "device/battery/battery_monitor_impl.h" |
| 160 #include "gpu/GLES2/gl2extchromium.h" | 160 #include "gpu/GLES2/gl2extchromium.h" |
| 161 #include "gpu/command_buffer/client/gpu_switches.h" | 161 #include "gpu/command_buffer/client/gpu_switches.h" |
| 162 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 162 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 163 #include "gpu/command_buffer/service/gpu_switches.h" | 163 #include "gpu/command_buffer/service/gpu_switches.h" |
| 164 #include "ipc/attachment_broker.h" | |
| 165 #include "ipc/attachment_broker_privileged.h" | |
| 166 #include "ipc/ipc_channel.h" | 164 #include "ipc/ipc_channel.h" |
| 167 #include "ipc/ipc_channel_mojo.h" | 165 #include "ipc/ipc_channel_mojo.h" |
| 168 #include "ipc/ipc_logging.h" | 166 #include "ipc/ipc_logging.h" |
| 169 #include "ipc/ipc_switches.h" | 167 #include "ipc/ipc_switches.h" |
| 170 #include "media/base/media_switches.h" | 168 #include "media/base/media_switches.h" |
| 171 #include "mojo/edk/embedder/embedder.h" | 169 #include "mojo/edk/embedder/embedder.h" |
| 172 #include "net/url_request/url_request_context_getter.h" | 170 #include "net/url_request/url_request_context_getter.h" |
| 173 #include "ppapi/shared_impl/ppapi_switches.h" | 171 #include "ppapi/shared_impl/ppapi_switches.h" |
| 174 #include "services/shell/public/cpp/interface_provider.h" | 172 #include "services/shell/public/cpp/interface_provider.h" |
| 175 #include "services/shell/public/cpp/interface_registry.h" | 173 #include "services/shell/public/cpp/interface_registry.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 592 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 595 base::Bind(&CacheShaderInfo, GetID(), | 593 base::Bind(&CacheShaderInfo, GetID(), |
| 596 storage_partition_impl_->GetPath())); | 594 storage_partition_impl_->GetPath())); |
| 597 } | 595 } |
| 598 | 596 |
| 599 #if defined(OS_MACOSX) | 597 #if defined(OS_MACOSX) |
| 600 if (BootstrapSandboxManager::ShouldEnable()) | 598 if (BootstrapSandboxManager::ShouldEnable()) |
| 601 AddObserver(BootstrapSandboxManager::GetInstance()); | 599 AddObserver(BootstrapSandboxManager::GetInstance()); |
| 602 #endif | 600 #endif |
| 603 | 601 |
| 604 #if USE_ATTACHMENT_BROKER | |
| 605 // Construct the privileged attachment broker early in the life cycle of a | |
| 606 // render process. This ensures that when a test is being run in one of the | |
| 607 // single process modes, the global attachment broker is the privileged | |
| 608 // attachment broker, rather than an unprivileged attachment broker. | |
| 609 #if defined(OS_MACOSX) | |
| 610 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( | |
| 611 MachBroker::GetInstance()); | |
| 612 #else | |
| 613 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); | |
| 614 #endif // defined(OS_MACOSX) | |
| 615 #endif // USE_ATTACHMENT_BROKER | |
| 616 | |
| 617 scoped_refptr<base::SequencedTaskRunner> io_task_runner = | 602 scoped_refptr<base::SequencedTaskRunner> io_task_runner = |
| 618 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 603 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
| 619 shell::Connector* connector = | 604 shell::Connector* connector = |
| 620 BrowserContext::GetShellConnectorFor(browser_context_); | 605 BrowserContext::GetShellConnectorFor(browser_context_); |
| 621 // Some embedders may not initialize Mojo or the shell connector for a browser | 606 // Some embedders may not initialize Mojo or the shell connector for a browser |
| 622 // context (e.g. Android WebView)... so just fall back to the per-process | 607 // context (e.g. Android WebView)... so just fall back to the per-process |
| 623 // connector. | 608 // connector. |
| 624 if (!connector) { | 609 if (!connector) { |
| 625 // Additionally, some test code may not initialize the process-wide | 610 // Additionally, some test code may not initialize the process-wide |
| 626 // MojoShellConnection prior to this point. This class of test code doesn't | 611 // MojoShellConnection prior to this point. This class of test code doesn't |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 // it may still run and have its IPCs fail, causing asserts. | 662 // it may still run and have its IPCs fail, causing asserts. |
| 678 in_process_renderer_.reset(); | 663 in_process_renderer_.reset(); |
| 679 | 664 |
| 680 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 665 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
| 681 | 666 |
| 682 if (gpu_observer_registered_) { | 667 if (gpu_observer_registered_) { |
| 683 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); | 668 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); |
| 684 gpu_observer_registered_ = false; | 669 gpu_observer_registered_ = false; |
| 685 } | 670 } |
| 686 | 671 |
| 687 #if USE_ATTACHMENT_BROKER | |
| 688 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 689 channel_.get()); | |
| 690 #endif | |
| 691 // We may have some unsent messages at this point, but that's OK. | 672 // We may have some unsent messages at this point, but that's OK. |
| 692 channel_.reset(); | 673 channel_.reset(); |
| 693 while (!queued_messages_.empty()) { | 674 while (!queued_messages_.empty()) { |
| 694 delete queued_messages_.front(); | 675 delete queued_messages_.front(); |
| 695 queued_messages_.pop(); | 676 queued_messages_.pop(); |
| 696 } | 677 } |
| 697 | 678 |
| 698 UnregisterHost(GetID()); | 679 UnregisterHost(GetID()); |
| 699 | 680 |
| 700 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 681 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 // See crbug.com/526842 for details. | 831 // See crbug.com/526842 for details. |
| 851 #if defined(OS_ANDROID) | 832 #if defined(OS_ANDROID) |
| 852 if (GetContentClient()->UsingSynchronousCompositing()) { | 833 if (GetContentClient()->UsingSynchronousCompositing()) { |
| 853 return IPC::SyncChannel::Create( | 834 return IPC::SyncChannel::Create( |
| 854 std::move(channel_factory), this, runner.get(), true, &never_signaled_); | 835 std::move(channel_factory), this, runner.get(), true, &never_signaled_); |
| 855 } | 836 } |
| 856 #endif // OS_ANDROID | 837 #endif // OS_ANDROID |
| 857 | 838 |
| 858 std::unique_ptr<IPC::ChannelProxy> channel( | 839 std::unique_ptr<IPC::ChannelProxy> channel( |
| 859 new IPC::ChannelProxy(this, runner.get())); | 840 new IPC::ChannelProxy(this, runner.get())); |
| 860 #if USE_ATTACHMENT_BROKER | |
| 861 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | |
| 862 channel.get(), runner); | |
| 863 #endif | |
| 864 channel->Init(std::move(channel_factory), true); | 841 channel->Init(std::move(channel_factory), true); |
| 865 return channel; | 842 return channel; |
| 866 } | 843 } |
| 867 | 844 |
| 868 void RenderProcessHostImpl::CreateMessageFilters() { | 845 void RenderProcessHostImpl::CreateMessageFilters() { |
| 869 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 846 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 870 AddFilter(new ResourceSchedulerFilter(GetID())); | 847 AddFilter(new ResourceSchedulerFilter(GetID())); |
| 871 MediaInternals* media_internals = MediaInternals::GetInstance(); | 848 MediaInternals* media_internals = MediaInternals::GetInstance(); |
| 872 media::AudioManager* audio_manager = | 849 media::AudioManager* audio_manager = |
| 873 BrowserMainLoop::GetInstance()->audio_manager(); | 850 BrowserMainLoop::GetInstance()->audio_manager(); |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1945 NotificationService::current()->Notify( | 1922 NotificationService::current()->Notify( |
| 1946 NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 1923 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 1947 Source<RenderProcessHost>(this), NotificationService::NoDetails()); | 1924 Source<RenderProcessHost>(this), NotificationService::NoDetails()); |
| 1948 | 1925 |
| 1949 #ifndef NDEBUG | 1926 #ifndef NDEBUG |
| 1950 is_self_deleted_ = true; | 1927 is_self_deleted_ = true; |
| 1951 #endif | 1928 #endif |
| 1952 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 1929 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 1953 deleting_soon_ = true; | 1930 deleting_soon_ = true; |
| 1954 | 1931 |
| 1955 #if USE_ATTACHMENT_BROKER | |
| 1956 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 1957 channel_.get()); | |
| 1958 #endif | |
| 1959 | |
| 1960 // It's important not to wait for the DeleteTask to delete the channel | 1932 // It's important not to wait for the DeleteTask to delete the channel |
| 1961 // proxy. Kill it off now. That way, in case the profile is going away, the | 1933 // proxy. Kill it off now. That way, in case the profile is going away, the |
| 1962 // rest of the objects attached to this RenderProcessHost start going | 1934 // rest of the objects attached to this RenderProcessHost start going |
| 1963 // away first, since deleting the channel proxy will post a | 1935 // away first, since deleting the channel proxy will post a |
| 1964 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1936 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
| 1965 channel_.reset(); | 1937 channel_.reset(); |
| 1966 | 1938 |
| 1967 // The following members should be cleared in ProcessDied() as well! | 1939 // The following members should be cleared in ProcessDied() as well! |
| 1968 message_port_message_filter_ = NULL; | 1940 message_port_message_filter_ = NULL; |
| 1969 | 1941 |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2443 // FrameHostMsg_RenderProcessGone with status | 2415 // FrameHostMsg_RenderProcessGone with status |
| 2444 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl | 2416 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl |
| 2445 // logic. | 2417 // logic. |
| 2446 status = base::TERMINATION_STATUS_PROCESS_CRASHED; | 2418 status = base::TERMINATION_STATUS_PROCESS_CRASHED; |
| 2447 } | 2419 } |
| 2448 } | 2420 } |
| 2449 | 2421 |
| 2450 RendererClosedDetails details(status, exit_code); | 2422 RendererClosedDetails details(status, exit_code); |
| 2451 | 2423 |
| 2452 child_process_launcher_.reset(); | 2424 child_process_launcher_.reset(); |
| 2453 #if USE_ATTACHMENT_BROKER | |
| 2454 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 2455 channel_.get()); | |
| 2456 #endif | |
| 2457 channel_.reset(); | 2425 channel_.reset(); |
| 2458 while (!queued_messages_.empty()) { | 2426 while (!queued_messages_.empty()) { |
| 2459 delete queued_messages_.front(); | 2427 delete queued_messages_.front(); |
| 2460 queued_messages_.pop(); | 2428 queued_messages_.pop(); |
| 2461 } | 2429 } |
| 2462 UpdateProcessPriority(); | 2430 UpdateProcessPriority(); |
| 2463 DCHECK(!is_process_backgrounded_); | 2431 DCHECK(!is_process_backgrounded_); |
| 2464 | 2432 |
| 2465 // RenderProcessExited observers and RenderProcessGone handlers might | 2433 // RenderProcessExited observers and RenderProcessGone handlers might |
| 2466 // navigate or perform other actions that require a connection. Ensure that | 2434 // navigate or perform other actions that require a connection. Ensure that |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2801 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2769 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 2802 | 2770 |
| 2803 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2771 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
| 2804 // enough information here so that we can determine what the bad message was. | 2772 // enough information here so that we can determine what the bad message was. |
| 2805 base::debug::Alias(&error); | 2773 base::debug::Alias(&error); |
| 2806 bad_message::ReceivedBadMessage(process.get(), | 2774 bad_message::ReceivedBadMessage(process.get(), |
| 2807 bad_message::RPH_MOJO_PROCESS_ERROR); | 2775 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 2808 } | 2776 } |
| 2809 | 2777 |
| 2810 } // namespace content | 2778 } // namespace content |
| OLD | NEW |