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

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

Issue 1883053003: Revert "Use a token to initialise ChannelMojo and MojoApplication everywhere." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 #include "content/browser/storage_partition_impl.h" 121 #include "content/browser/storage_partition_impl.h"
122 #include "content/browser/streams/stream_context.h" 122 #include "content/browser/streams/stream_context.h"
123 #include "content/browser/tracing/trace_message_filter.h" 123 #include "content/browser/tracing/trace_message_filter.h"
124 #include "content/browser/webui/web_ui_controller_factory_registry.h" 124 #include "content/browser/webui/web_ui_controller_factory_registry.h"
125 #include "content/common/child_process_host_impl.h" 125 #include "content/common/child_process_host_impl.h"
126 #include "content/common/child_process_messages.h" 126 #include "content/common/child_process_messages.h"
127 #include "content/common/content_switches_internal.h" 127 #include "content/common/content_switches_internal.h"
128 #include "content/common/frame_messages.h" 128 #include "content/common/frame_messages.h"
129 #include "content/common/gpu_host_messages.h" 129 #include "content/common/gpu_host_messages.h"
130 #include "content/common/in_process_child_thread_params.h" 130 #include "content/common/in_process_child_thread_params.h"
131 #include "content/common/mojo/channel_init.h"
132 #include "content/common/mojo/mojo_messages.h"
131 #include "content/common/mojo/mojo_shell_connection_impl.h" 133 #include "content/common/mojo/mojo_shell_connection_impl.h"
132 #include "content/common/render_process_messages.h" 134 #include "content/common/render_process_messages.h"
133 #include "content/common/resource_messages.h" 135 #include "content/common/resource_messages.h"
134 #include "content/common/site_isolation_policy.h" 136 #include "content/common/site_isolation_policy.h"
135 #include "content/common/view_messages.h" 137 #include "content/common/view_messages.h"
136 #include "content/public/browser/browser_context.h" 138 #include "content/public/browser/browser_context.h"
137 #include "content/public/browser/browser_thread.h" 139 #include "content/public/browser/browser_thread.h"
138 #include "content/public/browser/content_browser_client.h" 140 #include "content/public/browser/content_browser_client.h"
139 #include "content/public/browser/notification_service.h" 141 #include "content/public/browser/notification_service.h"
140 #include "content/public/browser/notification_types.h" 142 #include "content/public/browser/notification_types.h"
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 // Setup the IPC channel. 729 // Setup the IPC channel.
728 const std::string channel_id = 730 const std::string channel_id =
729 IPC::Channel::GenerateVerifiedChannelID(std::string()); 731 IPC::Channel::GenerateVerifiedChannelID(std::string());
730 channel_ = CreateChannelProxy(channel_id); 732 channel_ = CreateChannelProxy(channel_id);
731 #if USE_ATTACHMENT_BROKER 733 #if USE_ATTACHMENT_BROKER
732 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( 734 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel(
733 channel_.get(), content::BrowserThread::GetMessageLoopProxyForThread( 735 channel_.get(), content::BrowserThread::GetMessageLoopProxyForThread(
734 content::BrowserThread::IO)); 736 content::BrowserThread::IO));
735 #endif 737 #endif
736 738
739 // Setup the Mojo channel.
740 mojo_application_host_->Init();
741
737 // Call the embedder first so that their IPC filters have priority. 742 // Call the embedder first so that their IPC filters have priority.
738 GetContentClient()->browser()->RenderProcessWillLaunch(this); 743 GetContentClient()->browser()->RenderProcessWillLaunch(this);
739 744
740 CreateMessageFilters(); 745 CreateMessageFilters();
741 RegisterMojoServices(); 746 RegisterMojoServices();
742 747
743 if (run_renderer_in_process()) { 748 if (run_renderer_in_process()) {
744 DCHECK(g_renderer_main_thread_factory); 749 DCHECK(g_renderer_main_thread_factory);
745 // Crank up a thread and run the initialization there. With the way that 750 // Crank up a thread and run the initialization there. With the way that
746 // messages flow between the browser and renderer, this thread is required 751 // messages flow between the browser and renderer, this thread is required
747 // to prevent a deadlock in single-process mode. Since the primordial 752 // to prevent a deadlock in single-process mode. Since the primordial
748 // thread in the renderer process runs the WebKit code and can sometimes 753 // thread in the renderer process runs the WebKit code and can sometimes
749 // make blocking calls to the UI thread (i.e. this thread), they need to run 754 // make blocking calls to the UI thread (i.e. this thread), they need to run
750 // on separate threads. 755 // on separate threads.
751 in_process_renderer_.reset( 756 in_process_renderer_.reset(
752 g_renderer_main_thread_factory(InProcessChildThreadParams( 757 g_renderer_main_thread_factory(InProcessChildThreadParams(
753 channel_id, 758 channel_id,
754 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) 759 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO)
755 ->task_runner(), 760 ->task_runner(),
756 mojo_channel_token_, mojo_application_host_->GetToken()))); 761 in_process_renderer_handle_.release())));
757 762
758 base::Thread::Options options; 763 base::Thread::Options options;
759 #if defined(OS_WIN) && !defined(OS_MACOSX) 764 #if defined(OS_WIN) && !defined(OS_MACOSX)
760 // In-process plugins require this to be a UI message loop. 765 // In-process plugins require this to be a UI message loop.
761 options.message_loop_type = base::MessageLoop::TYPE_UI; 766 options.message_loop_type = base::MessageLoop::TYPE_UI;
762 #else 767 #else
763 // We can't have multiple UI loops on Linux and Android, so we don't support 768 // We can't have multiple UI loops on Linux and Android, so we don't support
764 // in-process plugins. 769 // in-process plugins.
765 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; 770 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT;
766 #endif 771 #endif
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 init_time_ = base::TimeTicks::Now(); 810 init_time_ = base::TimeTicks::Now();
806 return true; 811 return true;
807 } 812 }
808 813
809 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( 814 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy(
810 const std::string& channel_id) { 815 const std::string& channel_id) {
811 scoped_refptr<base::SingleThreadTaskRunner> runner = 816 scoped_refptr<base::SingleThreadTaskRunner> runner =
812 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 817 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
813 if (ShouldUseMojoChannel()) { 818 if (ShouldUseMojoChannel()) {
814 VLOG(1) << "Mojo Channel is enabled on host"; 819 VLOG(1) << "Mojo Channel is enabled on host";
815 mojo_channel_token_ = mojo::edk::GenerateRandomToken(); 820 mojo::ScopedMessagePipeHandle handle;
816 mojo::ScopedMessagePipeHandle handle = 821
817 mojo::edk::CreateParentMessagePipe(mojo_channel_token_); 822 if (run_renderer_in_process()) {
823 mojo::MessagePipe pipe;
824 handle = std::move(pipe.handle0);
825 in_process_renderer_handle_ = std::move(pipe.handle1);
826 } else {
827 mojo_channel_token_ = mojo::edk::GenerateRandomToken();
828 handle = mojo::edk::CreateParentMessagePipe(mojo_channel_token_);
829 }
818 830
819 // Do NOT expand ifdef or run time condition checks here! Synchronous 831 // Do NOT expand ifdef or run time condition checks here! Synchronous
820 // IPCs from browser process are banned. It is only narrowly allowed 832 // IPCs from browser process are banned. It is only narrowly allowed
821 // for Android WebView to maintain backward compatibility. 833 // for Android WebView to maintain backward compatibility.
822 // See crbug.com/526842 for details. 834 // See crbug.com/526842 for details.
823 #if defined(OS_ANDROID) 835 #if defined(OS_ANDROID)
824 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 836 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
825 switches::kIPCSyncCompositing)) { 837 switches::kIPCSyncCompositing)) {
826 return IPC::SyncChannel::Create( 838 return IPC::SyncChannel::Create(
827 IPC::ChannelMojo::CreateServerFactory(std::move(handle)), this, 839 IPC::ChannelMojo::CreateServerFactory(std::move(handle)), this,
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 command_line->AppendSwitchASCII(switches::kDeviceScaleFactor, 1383 command_line->AppendSwitchASCII(switches::kDeviceScaleFactor,
1372 base::DoubleToString(gfx::GetDPIScale())); 1384 base::DoubleToString(gfx::GetDPIScale()));
1373 #endif 1385 #endif
1374 1386
1375 AppendCompositorCommandLineFlags(command_line); 1387 AppendCompositorCommandLineFlags(command_line);
1376 1388
1377 if (!mojo_channel_token_.empty()) { 1389 if (!mojo_channel_token_.empty()) {
1378 command_line->AppendSwitchASCII(switches::kMojoChannelToken, 1390 command_line->AppendSwitchASCII(switches::kMojoChannelToken,
1379 mojo_channel_token_); 1391 mojo_channel_token_);
1380 } 1392 }
1381 command_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken,
1382 mojo_application_host_->GetToken());
1383 } 1393 }
1384 1394
1385 void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( 1395 void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
1386 const base::CommandLine& browser_cmd, 1396 const base::CommandLine& browser_cmd,
1387 base::CommandLine* renderer_cmd) const { 1397 base::CommandLine* renderer_cmd) const {
1388 // Propagate the following switches to the renderer command line (along 1398 // Propagate the following switches to the renderer command line (along
1389 // with any associated values) if present in the browser command line. 1399 // with any associated values) if present in the browser command line.
1390 static const char* const kSwitchNames[] = { 1400 static const char* const kSwitchNames[] = {
1391 switches::kAgcStartupMinVolume, 1401 switches::kAgcStartupMinVolume,
1392 switches::kAllowLoopbackInPeerConnection, 1402 switches::kAllowLoopbackInPeerConnection,
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 // ExtensionService uses this notification to initialize the renderer process 2624 // ExtensionService uses this notification to initialize the renderer process
2615 // with state that must be there before any JavaScript executes. 2625 // with state that must be there before any JavaScript executes.
2616 // 2626 //
2617 // The queued messages contain such things as "navigate". If this notification 2627 // The queued messages contain such things as "navigate". If this notification
2618 // was after, we can end up executing JavaScript before the initialization 2628 // was after, we can end up executing JavaScript before the initialization
2619 // happens. 2629 // happens.
2620 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, 2630 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED,
2621 Source<RenderProcessHost>(this), 2631 Source<RenderProcessHost>(this),
2622 NotificationService::NoDetails()); 2632 NotificationService::NoDetails());
2623 2633
2634 // Allow Mojo to be setup before the renderer sees any Chrome IPC messages.
2635 // This way, Mojo can be safely used from the renderer in response to any
2636 // Chrome IPC message.
2637 mojo_application_host_->Activate(this, GetHandle());
2638
2624 while (!queued_messages_.empty()) { 2639 while (!queued_messages_.empty()) {
2625 Send(queued_messages_.front()); 2640 Send(queued_messages_.front());
2626 queued_messages_.pop(); 2641 queued_messages_.pop();
2627 } 2642 }
2628 2643
2629 if (IsReady()) { 2644 if (IsReady()) {
2630 DCHECK(!sent_render_process_ready_); 2645 DCHECK(!sent_render_process_ready_);
2631 sent_render_process_ready_ = true; 2646 sent_render_process_ready_ = true;
2632 // Send RenderProcessReady only if the channel is already connected. 2647 // Send RenderProcessReady only if the channel is already connected.
2633 FOR_EACH_OBSERVER(RenderProcessHostObserver, 2648 FOR_EACH_OBSERVER(RenderProcessHostObserver,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2827 2842
2828 // Skip widgets in other processes. 2843 // Skip widgets in other processes.
2829 if (rvh->GetProcess()->GetID() != GetID()) 2844 if (rvh->GetProcess()->GetID() != GetID())
2830 continue; 2845 continue;
2831 2846
2832 rvh->OnWebkitPreferencesChanged(); 2847 rvh->OnWebkitPreferencesChanged();
2833 } 2848 }
2834 } 2849 }
2835 2850
2836 } // namespace content 2851 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/mojo_application_host.cc ('k') | content/browser/utility_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698