Chromium Code Reviews| 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 while (!queued_messages_.empty()) |
|
Sam McNally
2016/09/09 05:33:14
queued_messages_.clear();
Ken Rockot(use gerrit already)
2016/09/09 16:01:50
std::queue has no clear(). I've change these to de
| |
| 845 delete queued_messages_.front(); | |
| 846 queued_messages_.pop(); | 848 queued_messages_.pop(); |
| 847 } | |
| 848 | 849 |
| 849 UnregisterHost(GetID()); | 850 UnregisterHost(GetID()); |
| 850 | 851 |
| 851 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 852 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 852 switches::kDisableGpuShaderDiskCache)) { | 853 switches::kDisableGpuShaderDiskCache)) { |
| 853 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 854 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 854 base::Bind(&RemoveShaderInfo, GetID())); | 855 base::Bind(&RemoveShaderInfo, GetID())); |
| 855 } | 856 } |
| 856 } | 857 } |
| 857 | 858 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 | 961 |
| 961 // Spawn the child process asynchronously to avoid blocking the UI thread. | 962 // 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 | 963 // As long as there's no renderer prefix, we can use the zygote process |
| 963 // at this stage. | 964 // at this stage. |
| 964 child_process_launcher_.reset(new ChildProcessLauncher( | 965 child_process_launcher_.reset(new ChildProcessLauncher( |
| 965 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, | 966 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, |
| 966 GetID(), this, child_token_, | 967 GetID(), this, child_token_, |
| 967 base::Bind(&RenderProcessHostImpl::OnMojoError, | 968 base::Bind(&RenderProcessHostImpl::OnMojoError, |
| 968 weak_factory_.GetWeakPtr(), | 969 weak_factory_.GetWeakPtr(), |
| 969 base::ThreadTaskRunnerHandle::Get()))); | 970 base::ThreadTaskRunnerHandle::Get()))); |
| 971 channel_->Pause(); | |
| 970 | 972 |
| 971 fast_shutdown_started_ = false; | 973 fast_shutdown_started_ = false; |
| 972 } | 974 } |
| 973 | 975 |
| 976 // Push any pending messages to the channel.now. Note that if the child | |
|
Sam McNally
2016/09/09 05:33:14
s/channel.now/channel now/
Ken Rockot(use gerrit already)
2016/09/09 16:01:50
Done
| |
| 977 // process is still launching, the channel will be paused and outgoing | |
| 978 // messages will be queued internally by the channel. | |
| 979 while (!queued_messages_.empty()) { | |
| 980 channel_->Send(queued_messages_.front().release()); | |
| 981 queued_messages_.pop(); | |
| 982 } | |
| 983 | |
| 974 if (!gpu_observer_registered_) { | 984 if (!gpu_observer_registered_) { |
| 975 gpu_observer_registered_ = true; | 985 gpu_observer_registered_ = true; |
| 976 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 986 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); |
| 977 } | 987 } |
| 978 | 988 |
| 979 power_monitor_broadcaster_.Init(); | 989 power_monitor_broadcaster_.Init(); |
| 980 | 990 |
| 981 is_initialized_ = true; | 991 is_initialized_ = true; |
| 982 init_time_ = base::TimeTicks::Now(); | 992 init_time_ = base::TimeTicks::Now(); |
| 983 return true; | 993 return true; |
| 984 } | 994 } |
| 985 | 995 |
| 986 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( | 996 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( |
| 987 const std::string& channel_id) { | 997 const std::string& channel_id) { |
| 988 scoped_refptr<base::SingleThreadTaskRunner> runner = | 998 scoped_refptr<base::SingleThreadTaskRunner> runner = |
| 989 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 999 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
| 990 IPC::mojom::ChannelBootstrapPtr bootstrap; | 1000 IPC::mojom::ChannelBootstrapPtr bootstrap; |
| 991 GetRemoteInterfaces()->GetInterface(&bootstrap); | 1001 GetRemoteInterfaces()->GetInterface(&bootstrap); |
| 992 std::unique_ptr<IPC::ChannelFactory> channel_factory = | 1002 std::unique_ptr<IPC::ChannelFactory> channel_factory = |
| 993 IPC::ChannelMojo::CreateServerFactory( | 1003 IPC::ChannelMojo::CreateServerFactory( |
| 994 bootstrap.PassInterface().PassHandle(), runner); | 1004 bootstrap.PassInterface().PassHandle(), runner); |
| 995 | 1005 |
| 1006 std::unique_ptr<IPC::ChannelProxy> channel; | |
| 996 // Do NOT expand ifdef or run time condition checks here! Synchronous | 1007 // Do NOT expand ifdef or run time condition checks here! Synchronous |
| 997 // IPCs from browser process are banned. It is only narrowly allowed | 1008 // IPCs from browser process are banned. It is only narrowly allowed |
| 998 // for Android WebView to maintain backward compatibility. | 1009 // for Android WebView to maintain backward compatibility. |
| 999 // See crbug.com/526842 for details. | 1010 // See crbug.com/526842 for details. |
| 1000 #if defined(OS_ANDROID) | 1011 #if defined(OS_ANDROID) |
| 1001 if (GetContentClient()->UsingSynchronousCompositing()) { | 1012 if (GetContentClient()->UsingSynchronousCompositing()) |
| 1002 return IPC::SyncChannel::Create( | 1013 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 | 1014 #endif // OS_ANDROID |
| 1006 | 1015 if (!channel) |
| 1007 std::unique_ptr<IPC::ChannelProxy> channel( | 1016 channel.reset(new IPC::ChannelProxy(this, runner.get())); |
| 1008 new IPC::ChannelProxy(this, runner.get())); | |
| 1009 #if USE_ATTACHMENT_BROKER | 1017 #if USE_ATTACHMENT_BROKER |
| 1010 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | 1018 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( |
| 1011 channel.get(), runner); | 1019 channel.get(), runner); |
| 1012 #endif | 1020 #endif |
| 1013 channel->Init(std::move(channel_factory), true); | 1021 channel->Init(std::move(channel_factory), true /* create_pipe_now */); |
| 1022 | |
| 1014 return channel; | 1023 return channel; |
| 1015 } | 1024 } |
| 1016 | 1025 |
| 1017 void RenderProcessHostImpl::CreateMessageFilters() { | 1026 void RenderProcessHostImpl::CreateMessageFilters() { |
| 1018 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1027 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1019 AddFilter(new ResourceSchedulerFilter(GetID())); | 1028 AddFilter(new ResourceSchedulerFilter(GetID())); |
| 1020 MediaInternals* media_internals = MediaInternals::GetInstance(); | 1029 MediaInternals* media_internals = MediaInternals::GetInstance(); |
| 1021 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages | 1030 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages |
| 1022 // from guests. | 1031 // from guests. |
| 1023 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( | 1032 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1205 void RenderProcessHostImpl::RegisterMojoInterfaces() { | 1214 void RenderProcessHostImpl::RegisterMojoInterfaces() { |
| 1206 std::unique_ptr<shell::InterfaceRegistry> registry( | 1215 std::unique_ptr<shell::InterfaceRegistry> registry( |
| 1207 new shell::InterfaceRegistry); | 1216 new shell::InterfaceRegistry); |
| 1208 #if defined(OS_ANDROID) | 1217 #if defined(OS_ANDROID) |
| 1209 interface_registry_android_ = | 1218 interface_registry_android_ = |
| 1210 InterfaceRegistryAndroid::Create(registry.get()); | 1219 InterfaceRegistryAndroid::Create(registry.get()); |
| 1211 InterfaceRegistrarAndroid::ExposeInterfacesToRenderer( | 1220 InterfaceRegistrarAndroid::ExposeInterfacesToRenderer( |
| 1212 interface_registry_android_.get()); | 1221 interface_registry_android_.get()); |
| 1213 #endif | 1222 #endif |
| 1214 | 1223 |
| 1224 channel_->AddAssociatedInterface( | |
| 1225 base::Bind(&RenderProcessHostImpl::OnRouteProviderRequest, | |
| 1226 base::Unretained(this))); | |
| 1227 | |
| 1215 #if !defined(OS_ANDROID) | 1228 #if !defined(OS_ANDROID) |
| 1216 AddUIThreadInterface( | 1229 AddUIThreadInterface( |
| 1217 registry.get(), base::Bind(&device::BatteryMonitorImpl::Create)); | 1230 registry.get(), base::Bind(&device::BatteryMonitorImpl::Create)); |
| 1218 #endif | 1231 #endif |
| 1219 AddUIThreadInterface( | 1232 AddUIThreadInterface( |
| 1220 registry.get(), | 1233 registry.get(), |
| 1221 base::Bind(&PermissionServiceContext::CreateService, | 1234 base::Bind(&PermissionServiceContext::CreateService, |
| 1222 base::Unretained(permission_service_context_.get()))); | 1235 base::Unretained(permission_service_context_.get()))); |
| 1223 // TODO(mcasas): finalize arguments. | 1236 // TODO(mcasas): finalize arguments. |
| 1224 AddUIThreadInterface(registry.get(), base::Bind(&ImageCaptureImpl::Create)); | 1237 AddUIThreadInterface(registry.get(), base::Bind(&ImageCaptureImpl::Create)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1280 MojoShellConnection* mojo_shell_connection = | 1293 MojoShellConnection* mojo_shell_connection = |
| 1281 BrowserContext::GetMojoShellConnectionFor(browser_context_); | 1294 BrowserContext::GetMojoShellConnectionFor(browser_context_); |
| 1282 std::unique_ptr<ConnectionFilterImpl> connection_filter( | 1295 std::unique_ptr<ConnectionFilterImpl> connection_filter( |
| 1283 new ConnectionFilterImpl(mojo_child_connection_->child_identity(), | 1296 new ConnectionFilterImpl(mojo_child_connection_->child_identity(), |
| 1284 std::move(registry))); | 1297 std::move(registry))); |
| 1285 connection_filter_controller_ = connection_filter->controller(); | 1298 connection_filter_controller_ = connection_filter->controller(); |
| 1286 connection_filter_id_ = | 1299 connection_filter_id_ = |
| 1287 mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); | 1300 mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); |
| 1288 } | 1301 } |
| 1289 | 1302 |
| 1303 void RenderProcessHostImpl::GetRoute( | |
| 1304 int32_t routing_id, | |
| 1305 mojom::AssociatedInterfaceProviderAssociatedRequest request) { | |
| 1306 DCHECK(request.is_pending()); | |
| 1307 associated_interface_provider_bindings_.AddBinding( | |
| 1308 this, std::move(request), | |
| 1309 reinterpret_cast<void*>(static_cast<uintptr_t>(routing_id))); | |
| 1310 } | |
| 1311 | |
| 1312 void RenderProcessHostImpl::GetAssociatedInterface( | |
| 1313 const std::string& name, | |
| 1314 mojom::AssociatedInterfaceAssociatedRequest request) { | |
| 1315 int32_t routing_id = static_cast<int32_t>(reinterpret_cast<uintptr_t>( | |
| 1316 associated_interface_provider_bindings_.dispatch_context())); | |
| 1317 IPC::Listener* listener = listeners_.Lookup(routing_id); | |
| 1318 if (listener) | |
| 1319 listener->OnAssociatedInterfaceRequest(name, request.PassHandle()); | |
| 1320 } | |
| 1321 | |
| 1290 void RenderProcessHostImpl::CreateStoragePartitionService( | 1322 void RenderProcessHostImpl::CreateStoragePartitionService( |
| 1291 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1323 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
| 1292 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1324 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
| 1293 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1325 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1294 switches::kMojoLocalStorage)) { | 1326 switches::kMojoLocalStorage)) { |
| 1295 storage_partition_impl_->Bind(std::move(request)); | 1327 storage_partition_impl_->Bind(std::move(request)); |
| 1296 } | 1328 } |
| 1297 } | 1329 } |
| 1298 | 1330 |
| 1299 int RenderProcessHostImpl::GetNextRoutingID() { | 1331 int RenderProcessHostImpl::GetNextRoutingID() { |
| 1300 return widget_helper_->GetNextRoutingID(); | 1332 return widget_helper_->GetNextRoutingID(); |
| 1301 } | 1333 } |
| 1302 | 1334 |
| 1303 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1335 void RenderProcessHostImpl::ResumeDeferredNavigation( |
| 1304 const GlobalRequestID& request_id) { | 1336 const GlobalRequestID& request_id) { |
| 1305 widget_helper_->ResumeDeferredNavigation(request_id); | 1337 widget_helper_->ResumeDeferredNavigation(request_id); |
| 1306 } | 1338 } |
| 1307 | 1339 |
| 1308 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1340 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
| 1309 Send(new ViewMsg_TimezoneChange(zone_id)); | 1341 Send(new ViewMsg_TimezoneChange(zone_id)); |
| 1310 } | 1342 } |
| 1311 | 1343 |
| 1312 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { | 1344 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { |
| 1313 return mojo_child_connection_->GetRemoteInterfaces(); | 1345 return mojo_child_connection_->GetRemoteInterfaces(); |
| 1314 } | 1346 } |
| 1315 | 1347 |
| 1348 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { | |
| 1349 if (!remote_route_provider_) { | |
| 1350 DCHECK(channel_); | |
| 1351 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); | |
| 1352 } | |
| 1353 return remote_route_provider_.get(); | |
| 1354 } | |
| 1355 | |
| 1316 std::unique_ptr<base::SharedPersistentMemoryAllocator> | 1356 std::unique_ptr<base::SharedPersistentMemoryAllocator> |
| 1317 RenderProcessHostImpl::TakeMetricsAllocator() { | 1357 RenderProcessHostImpl::TakeMetricsAllocator() { |
| 1318 return std::move(metrics_allocator_); | 1358 return std::move(metrics_allocator_); |
| 1319 } | 1359 } |
| 1320 | 1360 |
| 1321 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1361 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
| 1322 const { | 1362 const { |
| 1323 return init_time_; | 1363 return init_time_; |
| 1324 } | 1364 } |
| 1325 | 1365 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1374 } | 1414 } |
| 1375 | 1415 |
| 1376 void RenderProcessHostImpl::AddRoute(int32_t routing_id, | 1416 void RenderProcessHostImpl::AddRoute(int32_t routing_id, |
| 1377 IPC::Listener* listener) { | 1417 IPC::Listener* listener) { |
| 1378 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " | 1418 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " |
| 1379 << routing_id; | 1419 << routing_id; |
| 1380 listeners_.AddWithID(listener, routing_id); | 1420 listeners_.AddWithID(listener, routing_id); |
| 1381 } | 1421 } |
| 1382 | 1422 |
| 1383 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { | 1423 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { |
| 1384 DCHECK(listeners_.Lookup(routing_id) != NULL); | 1424 DCHECK(listeners_.Lookup(routing_id) != nullptr); |
| 1385 listeners_.Remove(routing_id); | 1425 listeners_.Remove(routing_id); |
| 1386 Cleanup(); | 1426 Cleanup(); |
| 1387 } | 1427 } |
| 1388 | 1428 |
| 1389 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { | 1429 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { |
| 1390 observers_.AddObserver(observer); | 1430 observers_.AddObserver(observer); |
| 1391 } | 1431 } |
| 1392 | 1432 |
| 1393 void RenderProcessHostImpl::RemoveObserver( | 1433 void RenderProcessHostImpl::RemoveObserver( |
| 1394 RenderProcessHostObserver* observer) { | 1434 RenderProcessHostObserver* observer) { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1879 // 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 |
| 1880 // died due to fast shutdown versus another cause. | 1920 // died due to fast shutdown versus another cause. |
| 1881 fast_shutdown_started_ = true; | 1921 fast_shutdown_started_ = true; |
| 1882 | 1922 |
| 1883 ProcessDied(false /* already_dead */, nullptr); | 1923 ProcessDied(false /* already_dead */, nullptr); |
| 1884 return true; | 1924 return true; |
| 1885 } | 1925 } |
| 1886 | 1926 |
| 1887 bool RenderProcessHostImpl::Send(IPC::Message* msg) { | 1927 bool RenderProcessHostImpl::Send(IPC::Message* msg) { |
| 1888 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); | 1928 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); |
| 1929 | |
| 1930 std::unique_ptr<IPC::Message> message(msg); | |
| 1931 | |
| 1889 #if !defined(OS_ANDROID) | 1932 #if !defined(OS_ANDROID) |
| 1890 DCHECK(!msg->is_sync()); | 1933 DCHECK(!message->is_sync()); |
| 1891 #endif | 1934 #endif |
| 1892 | 1935 |
| 1893 if (!channel_) { | 1936 if (!channel_) { |
| 1894 #if defined(OS_ANDROID) | 1937 #if defined(OS_ANDROID) |
| 1895 if (msg->is_sync()) { | 1938 if (message->is_sync()) |
| 1896 delete msg; | |
| 1897 return false; | 1939 return false; |
| 1898 } | |
| 1899 #endif | 1940 #endif |
| 1900 if (!is_initialized_) { | 1941 if (!is_initialized_) { |
| 1901 queued_messages_.push(msg); | 1942 queued_messages_.emplace(std::move(message)); |
| 1902 return true; | 1943 return true; |
| 1903 } else { | |
| 1904 delete msg; | |
| 1905 return false; | |
| 1906 } | 1944 } |
| 1945 return false; | |
| 1907 } | 1946 } |
| 1908 | 1947 |
| 1909 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) { | |
| 1910 #if defined(OS_ANDROID) | 1948 #if defined(OS_ANDROID) |
| 1911 if (msg->is_sync()) { | 1949 if (child_process_launcher_.get() && child_process_launcher_->IsStarting() && |
| 1912 delete msg; | 1950 message->is_sync()) { |
| 1913 return false; | 1951 return false; |
| 1914 } | 1952 } |
| 1915 #endif | 1953 #endif |
| 1916 queued_messages_.push(msg); | |
| 1917 return true; | |
| 1918 } | |
| 1919 | 1954 |
| 1920 return channel_->Send(msg); | 1955 return channel_->Send(message.release()); |
| 1921 } | 1956 } |
| 1922 | 1957 |
| 1923 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 1958 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
| 1924 // 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, |
| 1925 // we ignore incoming messages. | 1960 // we ignore incoming messages. |
| 1926 | 1961 |
| 1927 if (deleting_soon_ || fast_shutdown_started_) | 1962 if (deleting_soon_ || fast_shutdown_started_) |
| 1928 return false; | 1963 return false; |
| 1929 | 1964 |
| 1930 mark_child_process_activity_time(); | 1965 mark_child_process_activity_time(); |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2566 return; | 2601 return; |
| 2567 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( | 2602 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( |
| 2568 std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false)); | 2603 std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false)); |
| 2569 | 2604 |
| 2570 base::SharedMemoryHandle shm_handle; | 2605 base::SharedMemoryHandle shm_handle; |
| 2571 metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle); | 2606 metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle); |
| 2572 Send(new ChildProcessMsg_SetHistogramMemory( | 2607 Send(new ChildProcessMsg_SetHistogramMemory( |
| 2573 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); | 2608 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); |
| 2574 } | 2609 } |
| 2575 | 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 | |
| 2576 void RenderProcessHostImpl::ProcessDied(bool already_dead, | 2618 void RenderProcessHostImpl::ProcessDied(bool already_dead, |
| 2577 RendererClosedDetails* known_details) { | 2619 RendererClosedDetails* known_details) { |
| 2578 // 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. |
| 2579 // 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. |
| 2580 // The OnChannelError notification can fire multiple times due to nested sync | 2622 // The OnChannelError notification can fire multiple times due to nested sync |
| 2581 // 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 |
| 2582 // already handled the error. | 2624 // already handled the error. |
| 2583 | 2625 |
| 2584 // 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. |
| 2585 DCHECK(!within_process_died_observer_); | 2627 DCHECK(!within_process_died_observer_); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2610 } | 2652 } |
| 2611 | 2653 |
| 2612 RendererClosedDetails details(status, exit_code); | 2654 RendererClosedDetails details(status, exit_code); |
| 2613 | 2655 |
| 2614 child_process_launcher_.reset(); | 2656 child_process_launcher_.reset(); |
| 2615 #if USE_ATTACHMENT_BROKER | 2657 #if USE_ATTACHMENT_BROKER |
| 2616 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 2658 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
| 2617 channel_.get()); | 2659 channel_.get()); |
| 2618 #endif | 2660 #endif |
| 2619 channel_.reset(); | 2661 channel_.reset(); |
| 2620 while (!queued_messages_.empty()) { | 2662 while (!queued_messages_.empty()) |
| 2621 delete queued_messages_.front(); | |
| 2622 queued_messages_.pop(); | 2663 queued_messages_.pop(); |
| 2623 } | |
| 2624 UpdateProcessPriority(); | 2664 UpdateProcessPriority(); |
| 2625 DCHECK(!is_process_backgrounded_); | 2665 DCHECK(!is_process_backgrounded_); |
| 2626 | 2666 |
| 2627 // RenderProcessExited observers and RenderProcessGone handlers might | 2667 // RenderProcessExited observers and RenderProcessGone handlers might |
| 2628 // navigate or perform other actions that require a connection. Ensure that | 2668 // navigate or perform other actions that require a connection. Ensure that |
| 2629 // there is one before calling them. | 2669 // there is one before calling them. |
| 2630 child_token_ = mojo::edk::GenerateRandomToken(); | 2670 child_token_ = mojo::edk::GenerateRandomToken(); |
| 2631 shell::Connector* connector = | 2671 shell::Connector* connector = |
| 2632 BrowserContext::GetShellConnectorFor(browser_context_); | 2672 BrowserContext::GetShellConnectorFor(browser_context_); |
| 2633 if (!connector) | 2673 if (!connector) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2764 // especially don't want to send the RENDERER_PROCESS_CREATED notification, | 2804 // especially don't want to send the RENDERER_PROCESS_CREATED notification, |
| 2765 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to | 2805 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to |
| 2766 // properly cleanup. | 2806 // properly cleanup. |
| 2767 if (deleting_soon_) | 2807 if (deleting_soon_) |
| 2768 return; | 2808 return; |
| 2769 | 2809 |
| 2770 if (child_process_launcher_) { | 2810 if (child_process_launcher_) { |
| 2771 DCHECK(child_process_launcher_->GetProcess().IsValid()); | 2811 DCHECK(child_process_launcher_->GetProcess().IsValid()); |
| 2772 DCHECK(!is_process_backgrounded_); | 2812 DCHECK(!is_process_backgrounded_); |
| 2773 | 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 | |
| 2774 if (mojo_child_connection_) { | 2820 if (mojo_child_connection_) { |
| 2775 mojo_child_connection_->SetProcessHandle( | 2821 mojo_child_connection_->SetProcessHandle( |
| 2776 child_process_launcher_->GetProcess().Handle()); | 2822 child_process_launcher_->GetProcess().Handle()); |
| 2777 } | 2823 } |
| 2778 | 2824 |
| 2779 // Not all platforms launch processes in the same backgrounded state. Make | 2825 // Not all platforms launch processes in the same backgrounded state. Make |
| 2780 // sure |is_process_backgrounded_| reflects this platform's initial process | 2826 // sure |is_process_backgrounded_| reflects this platform's initial process |
| 2781 // state. | 2827 // state. |
| 2782 is_process_backgrounded_ = | 2828 is_process_backgrounded_ = |
| 2783 child_process_launcher_->GetProcess().IsProcessBackgrounded(); | 2829 child_process_launcher_->GetProcess().IsProcessBackgrounded(); |
| 2784 | 2830 |
| 2785 // Disable updating process priority on startup for now as it incorrectly | 2831 // Disable updating process priority on startup for now as it incorrectly |
| 2786 // results in backgrounding foreground navigations until their first commit | 2832 // results in backgrounding foreground navigations until their first commit |
| 2787 // 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 |
| 2788 // visibility at this point. https://crbug.com/560446. | 2834 // visibility at this point. https://crbug.com/560446. |
| 2789 // Except on Android for now because of https://crbug.com/601184 :-(. | 2835 // Except on Android for now because of https://crbug.com/601184 :-(. |
| 2790 #if defined(OS_ANDROID) | 2836 #if defined(OS_ANDROID) |
| 2791 UpdateProcessPriority(); | 2837 UpdateProcessPriority(); |
| 2792 #endif | 2838 #endif |
| 2793 | 2839 |
| 2794 // Share histograms between the renderer and this process. | 2840 // Share histograms between the renderer and this process. |
| 2795 CreateSharedRendererHistogramAllocator(); | 2841 CreateSharedRendererHistogramAllocator(); |
| 2796 } | 2842 } |
| 2797 | 2843 |
| 2798 // NOTE: This needs to be before sending queued messages because | 2844 // NOTE: This needs to be before flushing queued messages, because |
| 2799 // ExtensionService uses this notification to initialize the renderer process | 2845 // ExtensionService uses this notification to initialize the renderer process |
| 2800 // with state that must be there before any JavaScript executes. | 2846 // with state that must be there before any JavaScript executes. |
| 2801 // | 2847 // |
| 2802 // The queued messages contain such things as "navigate". If this notification | 2848 // The queued messages contain such things as "navigate". If this notification |
| 2803 // was after, we can end up executing JavaScript before the initialization | 2849 // was after, we can end up executing JavaScript before the initialization |
| 2804 // happens. | 2850 // happens. |
| 2805 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2851 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 2806 Source<RenderProcessHost>(this), | 2852 Source<RenderProcessHost>(this), |
| 2807 NotificationService::NoDetails()); | 2853 NotificationService::NoDetails()); |
| 2808 | 2854 |
| 2809 while (!queued_messages_.empty()) { | 2855 if (child_process_launcher_) |
| 2810 Send(queued_messages_.front()); | 2856 channel_->Flush(); |
| 2811 queued_messages_.pop(); | |
| 2812 } | |
| 2813 | 2857 |
| 2814 if (IsReady()) { | 2858 if (IsReady()) { |
| 2815 DCHECK(!sent_render_process_ready_); | 2859 DCHECK(!sent_render_process_ready_); |
| 2816 sent_render_process_ready_ = true; | 2860 sent_render_process_ready_ = true; |
| 2817 // Send RenderProcessReady only if the channel is already connected. | 2861 // Send RenderProcessReady only if the channel is already connected. |
| 2818 FOR_EACH_OBSERVER(RenderProcessHostObserver, | 2862 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| 2819 observers_, | 2863 observers_, |
| 2820 RenderProcessReady(this)); | 2864 RenderProcessReady(this)); |
| 2821 } | 2865 } |
| 2822 | 2866 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2965 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3009 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 2966 | 3010 |
| 2967 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 3011 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
| 2968 // 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. |
| 2969 base::debug::Alias(&error); | 3013 base::debug::Alias(&error); |
| 2970 bad_message::ReceivedBadMessage(process.get(), | 3014 bad_message::ReceivedBadMessage(process.get(), |
| 2971 bad_message::RPH_MOJO_PROCESS_ERROR); | 3015 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 2972 } | 3016 } |
| 2973 | 3017 |
| 2974 } // namespace content | 3018 } // namespace content |
| OLD | NEW |