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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 StoragePartitionImpl* storage_partition_impl, | 550 StoragePartitionImpl* storage_partition_impl, |
551 bool is_for_guests_only) | 551 bool is_for_guests_only) |
552 : fast_shutdown_started_(false), | 552 : fast_shutdown_started_(false), |
553 deleting_soon_(false), | 553 deleting_soon_(false), |
554 #ifndef NDEBUG | 554 #ifndef NDEBUG |
555 is_self_deleted_(false), | 555 is_self_deleted_(false), |
556 #endif | 556 #endif |
557 pending_views_(0), | 557 pending_views_(0), |
558 immediate_sender_(new SafeSenderProxy(this, true)), | 558 immediate_sender_(new SafeSenderProxy(this, true)), |
559 io_thread_sender_(new SafeSenderProxy(this, false)), | 559 io_thread_sender_(new SafeSenderProxy(this, false)), |
560 mojo_application_host_(new MojoApplicationHost), | 560 child_token_(mojo::edk::GenerateRandomToken()), |
| 561 mojo_application_host_(new MojoApplicationHost(child_token_)), |
561 visible_widgets_(0), | 562 visible_widgets_(0), |
562 is_process_backgrounded_(false), | 563 is_process_backgrounded_(false), |
563 is_initialized_(false), | 564 is_initialized_(false), |
564 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 565 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
565 browser_context_(browser_context), | 566 browser_context_(browser_context), |
566 storage_partition_impl_(storage_partition_impl), | 567 storage_partition_impl_(storage_partition_impl), |
567 sudden_termination_allowed_(true), | 568 sudden_termination_allowed_(true), |
568 ignore_input_events_(false), | 569 ignore_input_events_(false), |
569 is_for_guests_only_(is_for_guests_only), | 570 is_for_guests_only_(is_for_guests_only), |
570 gpu_observer_registered_(false), | 571 gpu_observer_registered_(false), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 } | 687 } |
687 | 688 |
688 bool RenderProcessHostImpl::Init() { | 689 bool RenderProcessHostImpl::Init() { |
689 // calling Init() more than once does nothing, this makes it more convenient | 690 // calling Init() more than once does nothing, this makes it more convenient |
690 // for the view host which may not be sure in some cases | 691 // for the view host which may not be sure in some cases |
691 if (channel_) | 692 if (channel_) |
692 return true; | 693 return true; |
693 | 694 |
694 mojo_child_connection_.reset(new MojoChildConnection( | 695 mojo_child_connection_.reset(new MojoChildConnection( |
695 kRendererMojoApplicationName, | 696 kRendererMojoApplicationName, |
696 base::StringPrintf("%d_%d", id_, instance_id_++))); | 697 base::StringPrintf("%d_%d", id_, instance_id_++), |
| 698 child_token_)); |
697 | 699 |
698 base::CommandLine::StringType renderer_prefix; | 700 base::CommandLine::StringType renderer_prefix; |
699 // A command prefix is something prepended to the command line of the spawned | 701 // A command prefix is something prepended to the command line of the spawned |
700 // process. | 702 // process. |
701 const base::CommandLine& browser_command_line = | 703 const base::CommandLine& browser_command_line = |
702 *base::CommandLine::ForCurrentProcess(); | 704 *base::CommandLine::ForCurrentProcess(); |
703 renderer_prefix = | 705 renderer_prefix = |
704 browser_command_line.GetSwitchValueNative(switches::kRendererCmdPrefix); | 706 browser_command_line.GetSwitchValueNative(switches::kRendererCmdPrefix); |
705 | 707 |
706 #if defined(OS_LINUX) | 708 #if defined(OS_LINUX) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 if (!renderer_prefix.empty()) | 774 if (!renderer_prefix.empty()) |
773 cmd_line->PrependWrapper(renderer_prefix); | 775 cmd_line->PrependWrapper(renderer_prefix); |
774 AppendRendererCommandLine(cmd_line); | 776 AppendRendererCommandLine(cmd_line); |
775 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 777 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
776 | 778 |
777 // Spawn the child process asynchronously to avoid blocking the UI thread. | 779 // Spawn the child process asynchronously to avoid blocking the UI thread. |
778 // As long as there's no renderer prefix, we can use the zygote process | 780 // As long as there's no renderer prefix, we can use the zygote process |
779 // at this stage. | 781 // at this stage. |
780 child_process_launcher_.reset(new ChildProcessLauncher( | 782 child_process_launcher_.reset(new ChildProcessLauncher( |
781 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, | 783 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, |
782 GetID(), this)); | 784 GetID(), this, child_token_)); |
783 | 785 |
784 fast_shutdown_started_ = false; | 786 fast_shutdown_started_ = false; |
785 } | 787 } |
786 | 788 |
787 if (!gpu_observer_registered_) { | 789 if (!gpu_observer_registered_) { |
788 gpu_observer_registered_ = true; | 790 gpu_observer_registered_ = true; |
789 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 791 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); |
790 } | 792 } |
791 | 793 |
792 power_monitor_broadcaster_.Init(); | 794 power_monitor_broadcaster_.Init(); |
793 | 795 |
794 is_initialized_ = true; | 796 is_initialized_ = true; |
795 init_time_ = base::TimeTicks::Now(); | 797 init_time_ = base::TimeTicks::Now(); |
796 return true; | 798 return true; |
797 } | 799 } |
798 | 800 |
799 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( | 801 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( |
800 const std::string& channel_id) { | 802 const std::string& channel_id) { |
801 scoped_refptr<base::SingleThreadTaskRunner> runner = | 803 scoped_refptr<base::SingleThreadTaskRunner> runner = |
802 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 804 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
803 mojo_channel_token_ = mojo::edk::GenerateRandomToken(); | 805 mojo_channel_token_ = mojo::edk::GenerateRandomToken(); |
804 mojo::ScopedMessagePipeHandle handle = | 806 mojo::ScopedMessagePipeHandle handle = |
805 mojo::edk::CreateParentMessagePipe(mojo_channel_token_); | 807 mojo::edk::CreateParentMessagePipe(mojo_channel_token_, child_token_); |
806 | 808 |
807 // Do NOT expand ifdef or run time condition checks here! Synchronous | 809 // Do NOT expand ifdef or run time condition checks here! Synchronous |
808 // IPCs from browser process are banned. It is only narrowly allowed | 810 // IPCs from browser process are banned. It is only narrowly allowed |
809 // for Android WebView to maintain backward compatibility. | 811 // for Android WebView to maintain backward compatibility. |
810 // See crbug.com/526842 for details. | 812 // See crbug.com/526842 for details. |
811 #if defined(OS_ANDROID) | 813 #if defined(OS_ANDROID) |
812 if (GetContentClient()->UsingSynchronousCompositing()) { | 814 if (GetContentClient()->UsingSynchronousCompositing()) { |
813 return IPC::SyncChannel::Create( | 815 return IPC::SyncChannel::Create( |
814 IPC::ChannelMojo::CreateServerFactory(std::move(handle)), this, | 816 IPC::ChannelMojo::CreateServerFactory(std::move(handle)), this, |
815 runner.get(), true, &never_signaled_); | 817 runner.get(), true, &never_signaled_); |
(...skipping 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2397 #endif | 2399 #endif |
2398 channel_.reset(); | 2400 channel_.reset(); |
2399 while (!queued_messages_.empty()) | 2401 while (!queued_messages_.empty()) |
2400 queued_messages_.pop(); | 2402 queued_messages_.pop(); |
2401 UpdateProcessPriority(); | 2403 UpdateProcessPriority(); |
2402 DCHECK(!is_process_backgrounded_); | 2404 DCHECK(!is_process_backgrounded_); |
2403 | 2405 |
2404 // RenderProcessExited observers and RenderProcessGone handlers might | 2406 // RenderProcessExited observers and RenderProcessGone handlers might |
2405 // navigate or perform other actions that require a connection. Ensure that | 2407 // navigate or perform other actions that require a connection. Ensure that |
2406 // there is one before calling them. | 2408 // there is one before calling them. |
2407 mojo_application_host_.reset(new MojoApplicationHost); | 2409 child_token_ = mojo::edk::GenerateRandomToken(); |
| 2410 mojo_application_host_.reset(new MojoApplicationHost(child_token_)); |
2408 | 2411 |
2409 within_process_died_observer_ = true; | 2412 within_process_died_observer_ = true; |
2410 NotificationService::current()->Notify( | 2413 NotificationService::current()->Notify( |
2411 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2414 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2412 Details<RendererClosedDetails>(&details)); | 2415 Details<RendererClosedDetails>(&details)); |
2413 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2416 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
2414 RenderProcessExited(this, status, exit_code)); | 2417 RenderProcessExited(this, status, exit_code)); |
2415 within_process_died_observer_ = false; | 2418 within_process_died_observer_ = false; |
2416 | 2419 |
2417 message_port_message_filter_ = NULL; | 2420 message_port_message_filter_ = NULL; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2780 | 2783 |
2781 // Skip widgets in other processes. | 2784 // Skip widgets in other processes. |
2782 if (rvh->GetProcess()->GetID() != GetID()) | 2785 if (rvh->GetProcess()->GetID() != GetID()) |
2783 continue; | 2786 continue; |
2784 | 2787 |
2785 rvh->OnWebkitPreferencesChanged(); | 2788 rvh->OnWebkitPreferencesChanged(); |
2786 } | 2789 } |
2787 } | 2790 } |
2788 | 2791 |
2789 } // namespace content | 2792 } // namespace content |
OLD | NEW |