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

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

Issue 1891043002: Revert of 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 #include "content/browser/storage_partition_impl.h" 119 #include "content/browser/storage_partition_impl.h"
120 #include "content/browser/streams/stream_context.h" 120 #include "content/browser/streams/stream_context.h"
121 #include "content/browser/tracing/trace_message_filter.h" 121 #include "content/browser/tracing/trace_message_filter.h"
122 #include "content/browser/webui/web_ui_controller_factory_registry.h" 122 #include "content/browser/webui/web_ui_controller_factory_registry.h"
123 #include "content/common/child_process_host_impl.h" 123 #include "content/common/child_process_host_impl.h"
124 #include "content/common/child_process_messages.h" 124 #include "content/common/child_process_messages.h"
125 #include "content/common/content_switches_internal.h" 125 #include "content/common/content_switches_internal.h"
126 #include "content/common/frame_messages.h" 126 #include "content/common/frame_messages.h"
127 #include "content/common/gpu_host_messages.h" 127 #include "content/common/gpu_host_messages.h"
128 #include "content/common/in_process_child_thread_params.h" 128 #include "content/common/in_process_child_thread_params.h"
129 #include "content/common/mojo/channel_init.h"
130 #include "content/common/mojo/mojo_messages.h"
129 #include "content/common/mojo/mojo_shell_connection_impl.h" 131 #include "content/common/mojo/mojo_shell_connection_impl.h"
130 #include "content/common/render_process_messages.h" 132 #include "content/common/render_process_messages.h"
131 #include "content/common/resource_messages.h" 133 #include "content/common/resource_messages.h"
132 #include "content/common/site_isolation_policy.h" 134 #include "content/common/site_isolation_policy.h"
133 #include "content/common/view_messages.h" 135 #include "content/common/view_messages.h"
134 #include "content/public/browser/browser_context.h" 136 #include "content/public/browser/browser_context.h"
135 #include "content/public/browser/browser_thread.h" 137 #include "content/public/browser/browser_thread.h"
136 #include "content/public/browser/content_browser_client.h" 138 #include "content/public/browser/content_browser_client.h"
137 #include "content/public/browser/notification_service.h" 139 #include "content/public/browser/notification_service.h"
138 #include "content/public/browser/notification_types.h" 140 #include "content/public/browser/notification_types.h"
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 // Setup the IPC channel. 725 // Setup the IPC channel.
724 const std::string channel_id = 726 const std::string channel_id =
725 IPC::Channel::GenerateVerifiedChannelID(std::string()); 727 IPC::Channel::GenerateVerifiedChannelID(std::string());
726 channel_ = CreateChannelProxy(channel_id); 728 channel_ = CreateChannelProxy(channel_id);
727 #if USE_ATTACHMENT_BROKER 729 #if USE_ATTACHMENT_BROKER
728 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( 730 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel(
729 channel_.get(), content::BrowserThread::GetMessageLoopProxyForThread( 731 channel_.get(), content::BrowserThread::GetMessageLoopProxyForThread(
730 content::BrowserThread::IO)); 732 content::BrowserThread::IO));
731 #endif 733 #endif
732 734
735 // Setup the Mojo channel.
736 mojo_application_host_->Init();
737
733 // Call the embedder first so that their IPC filters have priority. 738 // Call the embedder first so that their IPC filters have priority.
734 GetContentClient()->browser()->RenderProcessWillLaunch(this); 739 GetContentClient()->browser()->RenderProcessWillLaunch(this);
735 740
736 CreateMessageFilters(); 741 CreateMessageFilters();
737 RegisterMojoServices(); 742 RegisterMojoServices();
738 743
739 if (run_renderer_in_process()) { 744 if (run_renderer_in_process()) {
740 DCHECK(g_renderer_main_thread_factory); 745 DCHECK(g_renderer_main_thread_factory);
741 // Crank up a thread and run the initialization there. With the way that 746 // Crank up a thread and run the initialization there. With the way that
742 // messages flow between the browser and renderer, this thread is required 747 // messages flow between the browser and renderer, this thread is required
743 // to prevent a deadlock in single-process mode. Since the primordial 748 // to prevent a deadlock in single-process mode. Since the primordial
744 // thread in the renderer process runs the WebKit code and can sometimes 749 // thread in the renderer process runs the WebKit code and can sometimes
745 // make blocking calls to the UI thread (i.e. this thread), they need to run 750 // make blocking calls to the UI thread (i.e. this thread), they need to run
746 // on separate threads. 751 // on separate threads.
747 in_process_renderer_.reset( 752 in_process_renderer_.reset(
748 g_renderer_main_thread_factory(InProcessChildThreadParams( 753 g_renderer_main_thread_factory(InProcessChildThreadParams(
749 channel_id, 754 channel_id,
750 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) 755 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO)
751 ->task_runner(), 756 ->task_runner(),
752 mojo_channel_token_, mojo_application_host_->GetToken()))); 757 in_process_renderer_handle_.release())));
753 758
754 base::Thread::Options options; 759 base::Thread::Options options;
755 #if defined(OS_WIN) && !defined(OS_MACOSX) 760 #if defined(OS_WIN) && !defined(OS_MACOSX)
756 // In-process plugins require this to be a UI message loop. 761 // In-process plugins require this to be a UI message loop.
757 options.message_loop_type = base::MessageLoop::TYPE_UI; 762 options.message_loop_type = base::MessageLoop::TYPE_UI;
758 #else 763 #else
759 // We can't have multiple UI loops on Linux and Android, so we don't support 764 // We can't have multiple UI loops on Linux and Android, so we don't support
760 // in-process plugins. 765 // in-process plugins.
761 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; 766 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT;
762 #endif 767 #endif
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 init_time_ = base::TimeTicks::Now(); 806 init_time_ = base::TimeTicks::Now();
802 return true; 807 return true;
803 } 808 }
804 809
805 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( 810 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy(
806 const std::string& channel_id) { 811 const std::string& channel_id) {
807 scoped_refptr<base::SingleThreadTaskRunner> runner = 812 scoped_refptr<base::SingleThreadTaskRunner> runner =
808 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 813 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
809 if (ShouldUseMojoChannel()) { 814 if (ShouldUseMojoChannel()) {
810 VLOG(1) << "Mojo Channel is enabled on host"; 815 VLOG(1) << "Mojo Channel is enabled on host";
811 mojo_channel_token_ = mojo::edk::GenerateRandomToken(); 816 mojo::ScopedMessagePipeHandle handle;
812 mojo::ScopedMessagePipeHandle handle = 817
813 mojo::edk::CreateParentMessagePipe(mojo_channel_token_); 818 if (run_renderer_in_process()) {
819 mojo::MessagePipe pipe;
820 handle = std::move(pipe.handle0);
821 in_process_renderer_handle_ = std::move(pipe.handle1);
822 } else {
823 mojo_channel_token_ = mojo::edk::GenerateRandomToken();
824 handle = mojo::edk::CreateParentMessagePipe(mojo_channel_token_);
825 }
814 826
815 // Do NOT expand ifdef or run time condition checks here! Synchronous 827 // Do NOT expand ifdef or run time condition checks here! Synchronous
816 // IPCs from browser process are banned. It is only narrowly allowed 828 // IPCs from browser process are banned. It is only narrowly allowed
817 // for Android WebView to maintain backward compatibility. 829 // for Android WebView to maintain backward compatibility.
818 // See crbug.com/526842 for details. 830 // See crbug.com/526842 for details.
819 #if defined(OS_ANDROID) 831 #if defined(OS_ANDROID)
820 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 832 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
821 switches::kIPCSyncCompositing)) { 833 switches::kIPCSyncCompositing)) {
822 return IPC::SyncChannel::Create( 834 return IPC::SyncChannel::Create(
823 IPC::ChannelMojo::CreateServerFactory(std::move(handle)), this, 835 IPC::ChannelMojo::CreateServerFactory(std::move(handle)), this,
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 command_line->AppendSwitchASCII(switches::kDeviceScaleFactor, 1374 command_line->AppendSwitchASCII(switches::kDeviceScaleFactor,
1363 base::DoubleToString(gfx::GetDPIScale())); 1375 base::DoubleToString(gfx::GetDPIScale()));
1364 #endif 1376 #endif
1365 1377
1366 AppendCompositorCommandLineFlags(command_line); 1378 AppendCompositorCommandLineFlags(command_line);
1367 1379
1368 if (!mojo_channel_token_.empty()) { 1380 if (!mojo_channel_token_.empty()) {
1369 command_line->AppendSwitchASCII(switches::kMojoChannelToken, 1381 command_line->AppendSwitchASCII(switches::kMojoChannelToken,
1370 mojo_channel_token_); 1382 mojo_channel_token_);
1371 } 1383 }
1372 command_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken,
1373 mojo_application_host_->GetToken());
1374 } 1384 }
1375 1385
1376 void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( 1386 void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
1377 const base::CommandLine& browser_cmd, 1387 const base::CommandLine& browser_cmd,
1378 base::CommandLine* renderer_cmd) const { 1388 base::CommandLine* renderer_cmd) const {
1379 // Propagate the following switches to the renderer command line (along 1389 // Propagate the following switches to the renderer command line (along
1380 // with any associated values) if present in the browser command line. 1390 // with any associated values) if present in the browser command line.
1381 static const char* const kSwitchNames[] = { 1391 static const char* const kSwitchNames[] = {
1382 switches::kAgcStartupMinVolume, 1392 switches::kAgcStartupMinVolume,
1383 switches::kAllowLoopbackInPeerConnection, 1393 switches::kAllowLoopbackInPeerConnection,
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 // ExtensionService uses this notification to initialize the renderer process 2611 // ExtensionService uses this notification to initialize the renderer process
2602 // with state that must be there before any JavaScript executes. 2612 // with state that must be there before any JavaScript executes.
2603 // 2613 //
2604 // The queued messages contain such things as "navigate". If this notification 2614 // The queued messages contain such things as "navigate". If this notification
2605 // was after, we can end up executing JavaScript before the initialization 2615 // was after, we can end up executing JavaScript before the initialization
2606 // happens. 2616 // happens.
2607 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, 2617 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED,
2608 Source<RenderProcessHost>(this), 2618 Source<RenderProcessHost>(this),
2609 NotificationService::NoDetails()); 2619 NotificationService::NoDetails());
2610 2620
2621 // Allow Mojo to be setup before the renderer sees any Chrome IPC messages.
2622 // This way, Mojo can be safely used from the renderer in response to any
2623 // Chrome IPC message.
2624 mojo_application_host_->Activate(this, GetHandle());
2625
2611 while (!queued_messages_.empty()) { 2626 while (!queued_messages_.empty()) {
2612 Send(queued_messages_.front()); 2627 Send(queued_messages_.front());
2613 queued_messages_.pop(); 2628 queued_messages_.pop();
2614 } 2629 }
2615 2630
2616 if (IsReady()) { 2631 if (IsReady()) {
2617 DCHECK(!sent_render_process_ready_); 2632 DCHECK(!sent_render_process_ready_);
2618 sent_render_process_ready_ = true; 2633 sent_render_process_ready_ = true;
2619 // Send RenderProcessReady only if the channel is already connected. 2634 // Send RenderProcessReady only if the channel is already connected.
2620 FOR_EACH_OBSERVER(RenderProcessHostObserver, 2635 FOR_EACH_OBSERVER(RenderProcessHostObserver,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 2829
2815 // Skip widgets in other processes. 2830 // Skip widgets in other processes.
2816 if (rvh->GetProcess()->GetID() != GetID()) 2831 if (rvh->GetProcess()->GetID() != GetID())
2817 continue; 2832 continue;
2818 2833
2819 rvh->OnWebkitPreferencesChanged(); 2834 rvh->OnWebkitPreferencesChanged();
2820 } 2835 }
2821 } 2836 }
2822 2837
2823 } // namespace content 2838 } // 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