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

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

Issue 2310563002: Adds routed interface support between RenderFrameHost and RenderFrame (Closed)
Patch Set: . Created 4 years, 3 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 bool is_for_guests_only) 668 bool is_for_guests_only)
669 : fast_shutdown_started_(false), 669 : fast_shutdown_started_(false),
670 deleting_soon_(false), 670 deleting_soon_(false),
671 #ifndef NDEBUG 671 #ifndef NDEBUG
672 is_self_deleted_(false), 672 is_self_deleted_(false),
673 #endif 673 #endif
674 pending_views_(0), 674 pending_views_(0),
675 child_token_(mojo::edk::GenerateRandomToken()), 675 child_token_(mojo::edk::GenerateRandomToken()),
676 service_worker_ref_count_(0), 676 service_worker_ref_count_(0),
677 shared_worker_ref_count_(0), 677 shared_worker_ref_count_(0),
678 route_provider_binding_(this),
679 associated_interface_provider_bindings_(
680 mojo::BindingSetDispatchMode::WITH_CONTEXT),
678 visible_widgets_(0), 681 visible_widgets_(0),
679 is_process_backgrounded_(false), 682 is_process_backgrounded_(false),
680 is_initialized_(false), 683 is_initialized_(false),
681 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), 684 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
682 browser_context_(browser_context), 685 browser_context_(browser_context),
683 storage_partition_impl_(storage_partition_impl), 686 storage_partition_impl_(storage_partition_impl),
684 sudden_termination_allowed_(true), 687 sudden_termination_allowed_(true),
685 ignore_input_events_(false), 688 ignore_input_events_(false),
686 is_for_guests_only_(is_for_guests_only), 689 is_for_guests_only_(is_for_guests_only),
687 gpu_observer_registered_(false), 690 gpu_observer_registered_(false),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); 837 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this);
835 gpu_observer_registered_ = false; 838 gpu_observer_registered_ = false;
836 } 839 }
837 840
838 #if USE_ATTACHMENT_BROKER 841 #if USE_ATTACHMENT_BROKER
839 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( 842 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel(
840 channel_.get()); 843 channel_.get());
841 #endif 844 #endif
842 // We may have some unsent messages at this point, but that's OK. 845 // We may have some unsent messages at this point, but that's OK.
843 channel_.reset(); 846 channel_.reset();
844 while (!queued_messages_.empty()) { 847 queued_messages_ = MessageQueue{};
845 delete queued_messages_.front();
846 queued_messages_.pop();
847 }
848 848
849 UnregisterHost(GetID()); 849 UnregisterHost(GetID());
850 850
851 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 851 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
852 switches::kDisableGpuShaderDiskCache)) { 852 switches::kDisableGpuShaderDiskCache)) {
853 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 853 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
854 base::Bind(&RemoveShaderInfo, GetID())); 854 base::Bind(&RemoveShaderInfo, GetID()));
855 } 855 }
856 } 856 }
857 857
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 960
961 // Spawn the child process asynchronously to avoid blocking the UI thread. 961 // Spawn the child process asynchronously to avoid blocking the UI thread.
962 // As long as there's no renderer prefix, we can use the zygote process 962 // As long as there's no renderer prefix, we can use the zygote process
963 // at this stage. 963 // at this stage.
964 child_process_launcher_.reset(new ChildProcessLauncher( 964 child_process_launcher_.reset(new ChildProcessLauncher(
965 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, 965 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line,
966 GetID(), this, child_token_, 966 GetID(), this, child_token_,
967 base::Bind(&RenderProcessHostImpl::OnMojoError, 967 base::Bind(&RenderProcessHostImpl::OnMojoError,
968 weak_factory_.GetWeakPtr(), 968 weak_factory_.GetWeakPtr(),
969 base::ThreadTaskRunnerHandle::Get()))); 969 base::ThreadTaskRunnerHandle::Get())));
970 channel_->Pause();
970 971
971 fast_shutdown_started_ = false; 972 fast_shutdown_started_ = false;
972 } 973 }
973 974
975 // Push any pending messages to the channel now. Note that if the child
976 // process is still launching, the channel will be paused and outgoing
977 // messages will be queued internally by the channel.
978 while (!queued_messages_.empty()) {
979 channel_->Send(queued_messages_.front().release());
980 queued_messages_.pop();
981 }
982
974 if (!gpu_observer_registered_) { 983 if (!gpu_observer_registered_) {
975 gpu_observer_registered_ = true; 984 gpu_observer_registered_ = true;
976 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); 985 ui::GpuSwitchingManager::GetInstance()->AddObserver(this);
977 } 986 }
978 987
979 power_monitor_broadcaster_.Init(); 988 power_monitor_broadcaster_.Init();
980 989
981 is_initialized_ = true; 990 is_initialized_ = true;
982 init_time_ = base::TimeTicks::Now(); 991 init_time_ = base::TimeTicks::Now();
983 return true; 992 return true;
984 } 993 }
985 994
986 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( 995 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy(
987 const std::string& channel_id) { 996 const std::string& channel_id) {
988 scoped_refptr<base::SingleThreadTaskRunner> runner = 997 scoped_refptr<base::SingleThreadTaskRunner> runner =
989 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); 998 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
990 IPC::mojom::ChannelBootstrapPtr bootstrap; 999 IPC::mojom::ChannelBootstrapPtr bootstrap;
991 GetRemoteInterfaces()->GetInterface(&bootstrap); 1000 GetRemoteInterfaces()->GetInterface(&bootstrap);
992 std::unique_ptr<IPC::ChannelFactory> channel_factory = 1001 std::unique_ptr<IPC::ChannelFactory> channel_factory =
993 IPC::ChannelMojo::CreateServerFactory( 1002 IPC::ChannelMojo::CreateServerFactory(
994 bootstrap.PassInterface().PassHandle(), runner); 1003 bootstrap.PassInterface().PassHandle(), runner);
995 1004
1005 std::unique_ptr<IPC::ChannelProxy> channel;
996 // Do NOT expand ifdef or run time condition checks here! Synchronous 1006 // Do NOT expand ifdef or run time condition checks here! Synchronous
997 // IPCs from browser process are banned. It is only narrowly allowed 1007 // IPCs from browser process are banned. It is only narrowly allowed
998 // for Android WebView to maintain backward compatibility. 1008 // for Android WebView to maintain backward compatibility.
999 // See crbug.com/526842 for details. 1009 // See crbug.com/526842 for details.
1000 #if defined(OS_ANDROID) 1010 #if defined(OS_ANDROID)
1001 if (GetContentClient()->UsingSynchronousCompositing()) { 1011 if (GetContentClient()->UsingSynchronousCompositing())
1002 return IPC::SyncChannel::Create( 1012 channel = IPC::SyncChannel::Create(this, runner.get(), &never_signaled_);
1003 std::move(channel_factory), this, runner.get(), true, &never_signaled_);
1004 }
1005 #endif // OS_ANDROID 1013 #endif // OS_ANDROID
1006 1014 if (!channel)
1007 std::unique_ptr<IPC::ChannelProxy> channel( 1015 channel.reset(new IPC::ChannelProxy(this, runner.get()));
1008 new IPC::ChannelProxy(this, runner.get()));
1009 #if USE_ATTACHMENT_BROKER 1016 #if USE_ATTACHMENT_BROKER
1010 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( 1017 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel(
1011 channel.get(), runner); 1018 channel.get(), runner);
1012 #endif 1019 #endif
1013 channel->Init(std::move(channel_factory), true); 1020 channel->Init(std::move(channel_factory), true /* create_pipe_now */);
1021
1014 return channel; 1022 return channel;
1015 } 1023 }
1016 1024
1017 void RenderProcessHostImpl::CreateMessageFilters() { 1025 void RenderProcessHostImpl::CreateMessageFilters() {
1018 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1026 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1019 AddFilter(new ResourceSchedulerFilter(GetID())); 1027 AddFilter(new ResourceSchedulerFilter(GetID()));
1020 MediaInternals* media_internals = MediaInternals::GetInstance(); 1028 MediaInternals* media_internals = MediaInternals::GetInstance();
1021 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages 1029 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages
1022 // from guests. 1030 // from guests.
1023 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( 1031 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter(
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 void RenderProcessHostImpl::RegisterMojoInterfaces() { 1213 void RenderProcessHostImpl::RegisterMojoInterfaces() {
1206 std::unique_ptr<shell::InterfaceRegistry> registry( 1214 std::unique_ptr<shell::InterfaceRegistry> registry(
1207 new shell::InterfaceRegistry); 1215 new shell::InterfaceRegistry);
1208 #if defined(OS_ANDROID) 1216 #if defined(OS_ANDROID)
1209 interface_registry_android_ = 1217 interface_registry_android_ =
1210 InterfaceRegistryAndroid::Create(registry.get()); 1218 InterfaceRegistryAndroid::Create(registry.get());
1211 InterfaceRegistrarAndroid::ExposeInterfacesToRenderer( 1219 InterfaceRegistrarAndroid::ExposeInterfacesToRenderer(
1212 interface_registry_android_.get()); 1220 interface_registry_android_.get());
1213 #endif 1221 #endif
1214 1222
1223 channel_->AddAssociatedInterface(
1224 base::Bind(&RenderProcessHostImpl::OnRouteProviderRequest,
1225 base::Unretained(this)));
1226
1215 #if !defined(OS_ANDROID) 1227 #if !defined(OS_ANDROID)
1216 AddUIThreadInterface( 1228 AddUIThreadInterface(
1217 registry.get(), base::Bind(&device::BatteryMonitorImpl::Create)); 1229 registry.get(), base::Bind(&device::BatteryMonitorImpl::Create));
1218 #endif 1230 #endif
1219 AddUIThreadInterface( 1231 AddUIThreadInterface(
1220 registry.get(), 1232 registry.get(),
1221 base::Bind(&PermissionServiceContext::CreateService, 1233 base::Bind(&PermissionServiceContext::CreateService,
1222 base::Unretained(permission_service_context_.get()))); 1234 base::Unretained(permission_service_context_.get())));
1223 // TODO(mcasas): finalize arguments. 1235 // TODO(mcasas): finalize arguments.
1224 AddUIThreadInterface(registry.get(), base::Bind(&ImageCaptureImpl::Create)); 1236 AddUIThreadInterface(registry.get(), base::Bind(&ImageCaptureImpl::Create));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 MojoShellConnection* mojo_shell_connection = 1292 MojoShellConnection* mojo_shell_connection =
1281 BrowserContext::GetMojoShellConnectionFor(browser_context_); 1293 BrowserContext::GetMojoShellConnectionFor(browser_context_);
1282 std::unique_ptr<ConnectionFilterImpl> connection_filter( 1294 std::unique_ptr<ConnectionFilterImpl> connection_filter(
1283 new ConnectionFilterImpl(mojo_child_connection_->child_identity(), 1295 new ConnectionFilterImpl(mojo_child_connection_->child_identity(),
1284 std::move(registry))); 1296 std::move(registry)));
1285 connection_filter_controller_ = connection_filter->controller(); 1297 connection_filter_controller_ = connection_filter->controller();
1286 connection_filter_id_ = 1298 connection_filter_id_ =
1287 mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); 1299 mojo_shell_connection->AddConnectionFilter(std::move(connection_filter));
1288 } 1300 }
1289 1301
1302 void RenderProcessHostImpl::GetRoute(
1303 int32_t routing_id,
1304 mojom::AssociatedInterfaceProviderAssociatedRequest request) {
1305 DCHECK(request.is_pending());
1306 associated_interface_provider_bindings_.AddBinding(
1307 this, std::move(request),
1308 reinterpret_cast<void*>(static_cast<uintptr_t>(routing_id)));
1309 }
1310
1311 void RenderProcessHostImpl::GetAssociatedInterface(
1312 const std::string& name,
1313 mojom::AssociatedInterfaceAssociatedRequest request) {
1314 int32_t routing_id = static_cast<int32_t>(reinterpret_cast<uintptr_t>(
1315 associated_interface_provider_bindings_.dispatch_context()));
1316 IPC::Listener* listener = listeners_.Lookup(routing_id);
1317 if (listener)
1318 listener->OnAssociatedInterfaceRequest(name, request.PassHandle());
1319 }
1320
1290 void RenderProcessHostImpl::CreateStoragePartitionService( 1321 void RenderProcessHostImpl::CreateStoragePartitionService(
1291 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { 1322 mojo::InterfaceRequest<mojom::StoragePartitionService> request) {
1292 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! 1323 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW!
1293 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1324 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1294 switches::kMojoLocalStorage)) { 1325 switches::kMojoLocalStorage)) {
1295 storage_partition_impl_->Bind(std::move(request)); 1326 storage_partition_impl_->Bind(std::move(request));
1296 } 1327 }
1297 } 1328 }
1298 1329
1299 int RenderProcessHostImpl::GetNextRoutingID() { 1330 int RenderProcessHostImpl::GetNextRoutingID() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 DCHECK_GT(worker_ref_count(), 0UL); 1397 DCHECK_GT(worker_ref_count(), 0UL);
1367 --shared_worker_ref_count_; 1398 --shared_worker_ref_count_;
1368 if (worker_ref_count() == 0) 1399 if (worker_ref_count() == 0)
1369 Cleanup(); 1400 Cleanup();
1370 } 1401 }
1371 1402
1372 void RenderProcessHostImpl::PurgeAndSuspend() { 1403 void RenderProcessHostImpl::PurgeAndSuspend() {
1373 Send(new ChildProcessMsg_PurgeAndSuspend()); 1404 Send(new ChildProcessMsg_PurgeAndSuspend());
1374 } 1405 }
1375 1406
1407 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() {
1408 if (!remote_route_provider_) {
1409 DCHECK(channel_);
1410 channel_->GetRemoteAssociatedInterface(&remote_route_provider_);
1411 }
1412 return remote_route_provider_.get();
1413 }
1414
1376 void RenderProcessHostImpl::AddRoute(int32_t routing_id, 1415 void RenderProcessHostImpl::AddRoute(int32_t routing_id,
1377 IPC::Listener* listener) { 1416 IPC::Listener* listener) {
1378 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " 1417 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: "
1379 << routing_id; 1418 << routing_id;
1380 listeners_.AddWithID(listener, routing_id); 1419 listeners_.AddWithID(listener, routing_id);
1381 } 1420 }
1382 1421
1383 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { 1422 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) {
1384 DCHECK(listeners_.Lookup(routing_id) != NULL); 1423 DCHECK(listeners_.Lookup(routing_id) != nullptr);
1385 listeners_.Remove(routing_id); 1424 listeners_.Remove(routing_id);
1386 Cleanup(); 1425 Cleanup();
1387 } 1426 }
1388 1427
1389 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { 1428 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) {
1390 observers_.AddObserver(observer); 1429 observers_.AddObserver(observer);
1391 } 1430 }
1392 1431
1393 void RenderProcessHostImpl::RemoveObserver( 1432 void RenderProcessHostImpl::RemoveObserver(
1394 RenderProcessHostObserver* observer) { 1433 RenderProcessHostObserver* observer) {
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 // Set this before ProcessDied() so observers can tell if the render process 1919 // Set this before ProcessDied() so observers can tell if the render process
1881 // died due to fast shutdown versus another cause. 1920 // died due to fast shutdown versus another cause.
1882 fast_shutdown_started_ = true; 1921 fast_shutdown_started_ = true;
1883 1922
1884 ProcessDied(false /* already_dead */, nullptr); 1923 ProcessDied(false /* already_dead */, nullptr);
1885 return true; 1924 return true;
1886 } 1925 }
1887 1926
1888 bool RenderProcessHostImpl::Send(IPC::Message* msg) { 1927 bool RenderProcessHostImpl::Send(IPC::Message* msg) {
1889 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); 1928 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send");
1929
1930 std::unique_ptr<IPC::Message> message(msg);
1931
1890 #if !defined(OS_ANDROID) 1932 #if !defined(OS_ANDROID)
1891 DCHECK(!msg->is_sync()); 1933 DCHECK(!message->is_sync());
1892 #endif 1934 #endif
1893 1935
1894 if (!channel_) { 1936 if (!channel_) {
1895 #if defined(OS_ANDROID) 1937 #if defined(OS_ANDROID)
1896 if (msg->is_sync()) { 1938 if (message->is_sync())
1897 delete msg;
1898 return false; 1939 return false;
1899 }
1900 #endif 1940 #endif
1901 if (!is_initialized_) { 1941 if (!is_initialized_) {
1902 queued_messages_.push(msg); 1942 queued_messages_.emplace(std::move(message));
1903 return true; 1943 return true;
1904 } else {
1905 delete msg;
1906 return false;
1907 } 1944 }
1945 return false;
1908 } 1946 }
1909 1947
1910 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) {
1911 #if defined(OS_ANDROID) 1948 #if defined(OS_ANDROID)
1912 if (msg->is_sync()) { 1949 if (child_process_launcher_.get() && child_process_launcher_->IsStarting() &&
1913 delete msg; 1950 message->is_sync()) {
1914 return false; 1951 return false;
1915 } 1952 }
1916 #endif 1953 #endif
1917 queued_messages_.push(msg);
1918 return true;
1919 }
1920 1954
1921 return channel_->Send(msg); 1955 return channel_->Send(message.release());
1922 } 1956 }
1923 1957
1924 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { 1958 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) {
1925 // If we're about to be deleted, or have initiated the fast shutdown sequence, 1959 // If we're about to be deleted, or have initiated the fast shutdown sequence,
1926 // we ignore incoming messages. 1960 // we ignore incoming messages.
1927 1961
1928 if (deleting_soon_ || fast_shutdown_started_) 1962 if (deleting_soon_ || fast_shutdown_started_)
1929 return false; 1963 return false;
1930 1964
1931 mark_child_process_activity_time(); 1965 mark_child_process_activity_time();
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 return; 2601 return;
2568 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( 2602 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator(
2569 std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false)); 2603 std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false));
2570 2604
2571 base::SharedMemoryHandle shm_handle; 2605 base::SharedMemoryHandle shm_handle;
2572 metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle); 2606 metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle);
2573 Send(new ChildProcessMsg_SetHistogramMemory( 2607 Send(new ChildProcessMsg_SetHistogramMemory(
2574 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); 2608 shm_handle, metrics_allocator_->shared_memory()->mapped_size()));
2575 } 2609 }
2576 2610
2611 void RenderProcessHostImpl::OnRouteProviderRequest(
2612 mojom::RouteProviderAssociatedRequest request) {
2613 if (route_provider_binding_.is_bound())
2614 return;
2615 route_provider_binding_.Bind(std::move(request));
2616 }
2617
2577 void RenderProcessHostImpl::ProcessDied(bool already_dead, 2618 void RenderProcessHostImpl::ProcessDied(bool already_dead,
2578 RendererClosedDetails* known_details) { 2619 RendererClosedDetails* known_details) {
2579 // Our child process has died. If we didn't expect it, it's a crash. 2620 // Our child process has died. If we didn't expect it, it's a crash.
2580 // In any case, we need to let everyone know it's gone. 2621 // In any case, we need to let everyone know it's gone.
2581 // The OnChannelError notification can fire multiple times due to nested sync 2622 // The OnChannelError notification can fire multiple times due to nested sync
2582 // calls to a renderer. If we don't have a valid channel here it means we 2623 // calls to a renderer. If we don't have a valid channel here it means we
2583 // already handled the error. 2624 // already handled the error.
2584 2625
2585 // It should not be possible for us to be called re-entrantly. 2626 // It should not be possible for us to be called re-entrantly.
2586 DCHECK(!within_process_died_observer_); 2627 DCHECK(!within_process_died_observer_);
(...skipping 24 matching lines...) Expand all
2611 } 2652 }
2612 2653
2613 RendererClosedDetails details(status, exit_code); 2654 RendererClosedDetails details(status, exit_code);
2614 2655
2615 child_process_launcher_.reset(); 2656 child_process_launcher_.reset();
2616 #if USE_ATTACHMENT_BROKER 2657 #if USE_ATTACHMENT_BROKER
2617 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( 2658 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel(
2618 channel_.get()); 2659 channel_.get());
2619 #endif 2660 #endif
2620 channel_.reset(); 2661 channel_.reset();
2621 while (!queued_messages_.empty()) { 2662 queued_messages_ = MessageQueue{};
2622 delete queued_messages_.front(); 2663
2623 queued_messages_.pop();
2624 }
2625 UpdateProcessPriority(); 2664 UpdateProcessPriority();
2626 DCHECK(!is_process_backgrounded_); 2665 DCHECK(!is_process_backgrounded_);
2627 2666
2628 // RenderProcessExited observers and RenderProcessGone handlers might 2667 // RenderProcessExited observers and RenderProcessGone handlers might
2629 // navigate or perform other actions that require a connection. Ensure that 2668 // navigate or perform other actions that require a connection. Ensure that
2630 // there is one before calling them. 2669 // there is one before calling them.
2631 child_token_ = mojo::edk::GenerateRandomToken(); 2670 child_token_ = mojo::edk::GenerateRandomToken();
2632 shell::Connector* connector = 2671 shell::Connector* connector =
2633 BrowserContext::GetShellConnectorFor(browser_context_); 2672 BrowserContext::GetShellConnectorFor(browser_context_);
2634 if (!connector) 2673 if (!connector)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2765 // especially don't want to send the RENDERER_PROCESS_CREATED notification, 2804 // especially don't want to send the RENDERER_PROCESS_CREATED notification,
2766 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to 2805 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to
2767 // properly cleanup. 2806 // properly cleanup.
2768 if (deleting_soon_) 2807 if (deleting_soon_)
2769 return; 2808 return;
2770 2809
2771 if (child_process_launcher_) { 2810 if (child_process_launcher_) {
2772 DCHECK(child_process_launcher_->GetProcess().IsValid()); 2811 DCHECK(child_process_launcher_->GetProcess().IsValid());
2773 DCHECK(!is_process_backgrounded_); 2812 DCHECK(!is_process_backgrounded_);
2774 2813
2814 // Unpause the channel now that the process is launched. We don't flush it
2815 // yet to ensure that any initialization messages sent here (e.g., things
2816 // done in response to NOTIFICATION_RENDER_PROCESS_CREATED; see below)
2817 // preempt already queued messages.
2818 channel_->Unpause(false /* flush */);
2819
2775 if (mojo_child_connection_) { 2820 if (mojo_child_connection_) {
2776 mojo_child_connection_->SetProcessHandle( 2821 mojo_child_connection_->SetProcessHandle(
2777 child_process_launcher_->GetProcess().Handle()); 2822 child_process_launcher_->GetProcess().Handle());
2778 } 2823 }
2779 2824
2780 // Not all platforms launch processes in the same backgrounded state. Make 2825 // Not all platforms launch processes in the same backgrounded state. Make
2781 // sure |is_process_backgrounded_| reflects this platform's initial process 2826 // sure |is_process_backgrounded_| reflects this platform's initial process
2782 // state. 2827 // state.
2783 is_process_backgrounded_ = 2828 is_process_backgrounded_ =
2784 child_process_launcher_->GetProcess().IsProcessBackgrounded(); 2829 child_process_launcher_->GetProcess().IsProcessBackgrounded();
2785 2830
2786 // Disable updating process priority on startup for now as it incorrectly 2831 // Disable updating process priority on startup for now as it incorrectly
2787 // results in backgrounding foreground navigations until their first commit 2832 // results in backgrounding foreground navigations until their first commit
2788 // is made. A better long term solution would be to be aware of the tab's 2833 // is made. A better long term solution would be to be aware of the tab's
2789 // visibility at this point. https://crbug.com/560446. 2834 // visibility at this point. https://crbug.com/560446.
2790 // Except on Android for now because of https://crbug.com/601184 :-(. 2835 // Except on Android for now because of https://crbug.com/601184 :-(.
2791 #if defined(OS_ANDROID) 2836 #if defined(OS_ANDROID)
2792 UpdateProcessPriority(); 2837 UpdateProcessPriority();
2793 #endif 2838 #endif
2794 2839
2795 // Share histograms between the renderer and this process. 2840 // Share histograms between the renderer and this process.
2796 CreateSharedRendererHistogramAllocator(); 2841 CreateSharedRendererHistogramAllocator();
2797 } 2842 }
2798 2843
2799 // NOTE: This needs to be before sending queued messages because 2844 // NOTE: This needs to be before flushing queued messages, because
2800 // ExtensionService uses this notification to initialize the renderer process 2845 // ExtensionService uses this notification to initialize the renderer process
2801 // with state that must be there before any JavaScript executes. 2846 // with state that must be there before any JavaScript executes.
2802 // 2847 //
2803 // The queued messages contain such things as "navigate". If this notification 2848 // The queued messages contain such things as "navigate". If this notification
2804 // was after, we can end up executing JavaScript before the initialization 2849 // was after, we can end up executing JavaScript before the initialization
2805 // happens. 2850 // happens.
2806 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, 2851 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED,
2807 Source<RenderProcessHost>(this), 2852 Source<RenderProcessHost>(this),
2808 NotificationService::NoDetails()); 2853 NotificationService::NoDetails());
2809 2854
2810 while (!queued_messages_.empty()) { 2855 if (child_process_launcher_)
2811 Send(queued_messages_.front()); 2856 channel_->Flush();
2812 queued_messages_.pop();
2813 }
2814 2857
2815 if (IsReady()) { 2858 if (IsReady()) {
2816 DCHECK(!sent_render_process_ready_); 2859 DCHECK(!sent_render_process_ready_);
2817 sent_render_process_ready_ = true; 2860 sent_render_process_ready_ = true;
2818 // Send RenderProcessReady only if the channel is already connected. 2861 // Send RenderProcessReady only if the channel is already connected.
2819 FOR_EACH_OBSERVER(RenderProcessHostObserver, 2862 FOR_EACH_OBSERVER(RenderProcessHostObserver,
2820 observers_, 2863 observers_,
2821 RenderProcessReady(this)); 2864 RenderProcessReady(this));
2822 } 2865 }
2823 2866
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2966 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 3009 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
2967 3010
2968 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 3011 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
2969 // enough information here so that we can determine what the bad message was. 3012 // enough information here so that we can determine what the bad message was.
2970 base::debug::Alias(&error); 3013 base::debug::Alias(&error);
2971 bad_message::ReceivedBadMessage(process.get(), 3014 bad_message::ReceivedBadMessage(process.get(),
2972 bad_message::RPH_MOJO_PROCESS_ERROR); 3015 bad_message::RPH_MOJO_PROCESS_ERROR);
2973 } 3016 }
2974 3017
2975 } // namespace content 3018 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698