| 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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 BrowserContext* browser_context, | 665 BrowserContext* browser_context, |
| 666 StoragePartitionImpl* storage_partition_impl, | 666 StoragePartitionImpl* storage_partition_impl, |
| 667 bool is_for_guests_only) | 667 bool is_for_guests_only) |
| 668 : fast_shutdown_started_(false), | 668 : fast_shutdown_started_(false), |
| 669 deleting_soon_(false), | 669 deleting_soon_(false), |
| 670 #ifndef NDEBUG | 670 #ifndef NDEBUG |
| 671 is_self_deleted_(false), | 671 is_self_deleted_(false), |
| 672 #endif | 672 #endif |
| 673 pending_views_(0), | 673 pending_views_(0), |
| 674 child_token_(mojo::edk::GenerateRandomToken()), | 674 child_token_(mojo::edk::GenerateRandomToken()), |
| 675 route_provider_binding_(this), |
| 675 visible_widgets_(0), | 676 visible_widgets_(0), |
| 676 is_process_backgrounded_(false), | 677 is_process_backgrounded_(false), |
| 677 is_initialized_(false), | 678 is_initialized_(false), |
| 678 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 679 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
| 679 browser_context_(browser_context), | 680 browser_context_(browser_context), |
| 680 storage_partition_impl_(storage_partition_impl), | 681 storage_partition_impl_(storage_partition_impl), |
| 681 sudden_termination_allowed_(true), | 682 sudden_termination_allowed_(true), |
| 682 ignore_input_events_(false), | 683 ignore_input_events_(false), |
| 683 is_for_guests_only_(is_for_guests_only), | 684 is_for_guests_only_(is_for_guests_only), |
| 684 gpu_observer_registered_(false), | 685 gpu_observer_registered_(false), |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); | 821 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); |
| 821 gpu_observer_registered_ = false; | 822 gpu_observer_registered_ = false; |
| 822 } | 823 } |
| 823 | 824 |
| 824 #if USE_ATTACHMENT_BROKER | 825 #if USE_ATTACHMENT_BROKER |
| 825 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 826 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
| 826 channel_.get()); | 827 channel_.get()); |
| 827 #endif | 828 #endif |
| 828 // We may have some unsent messages at this point, but that's OK. | 829 // We may have some unsent messages at this point, but that's OK. |
| 829 channel_.reset(); | 830 channel_.reset(); |
| 830 while (!queued_messages_.empty()) { | 831 while (!queued_messages_.empty()) |
| 831 delete queued_messages_.front(); | |
| 832 queued_messages_.pop(); | 832 queued_messages_.pop(); |
| 833 } | |
| 834 | 833 |
| 835 UnregisterHost(GetID()); | 834 UnregisterHost(GetID()); |
| 836 | 835 |
| 837 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 836 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 838 switches::kDisableGpuShaderDiskCache)) { | 837 switches::kDisableGpuShaderDiskCache)) { |
| 839 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 838 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 840 base::Bind(&RemoveShaderInfo, GetID())); | 839 base::Bind(&RemoveShaderInfo, GetID())); |
| 841 } | 840 } |
| 842 } | 841 } |
| 843 | 842 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( | 971 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( |
| 973 const std::string& channel_id) { | 972 const std::string& channel_id) { |
| 974 scoped_refptr<base::SingleThreadTaskRunner> runner = | 973 scoped_refptr<base::SingleThreadTaskRunner> runner = |
| 975 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 974 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
| 976 IPC::mojom::ChannelBootstrapPtr bootstrap; | 975 IPC::mojom::ChannelBootstrapPtr bootstrap; |
| 977 GetRemoteInterfaces()->GetInterface(&bootstrap); | 976 GetRemoteInterfaces()->GetInterface(&bootstrap); |
| 978 std::unique_ptr<IPC::ChannelFactory> channel_factory = | 977 std::unique_ptr<IPC::ChannelFactory> channel_factory = |
| 979 IPC::ChannelMojo::CreateServerFactory( | 978 IPC::ChannelMojo::CreateServerFactory( |
| 980 bootstrap.PassInterface().PassHandle(), runner); | 979 bootstrap.PassInterface().PassHandle(), runner); |
| 981 | 980 |
| 981 std::unique_ptr<IPC::ChannelProxy> channel; |
| 982 // Do NOT expand ifdef or run time condition checks here! Synchronous | 982 // Do NOT expand ifdef or run time condition checks here! Synchronous |
| 983 // IPCs from browser process are banned. It is only narrowly allowed | 983 // IPCs from browser process are banned. It is only narrowly allowed |
| 984 // for Android WebView to maintain backward compatibility. | 984 // for Android WebView to maintain backward compatibility. |
| 985 // See crbug.com/526842 for details. | 985 // See crbug.com/526842 for details. |
| 986 #if defined(OS_ANDROID) | 986 #if defined(OS_ANDROID) |
| 987 if (GetContentClient()->UsingSynchronousCompositing()) { | 987 if (GetContentClient()->UsingSynchronousCompositing()) |
| 988 return IPC::SyncChannel::Create( | 988 channel = IPC::SyncChannel::Create(this, runner.get(), &never_signaled_); |
| 989 std::move(channel_factory), this, runner.get(), true, &never_signaled_); | |
| 990 } | |
| 991 #endif // OS_ANDROID | 989 #endif // OS_ANDROID |
| 992 | 990 if (!channel) |
| 993 std::unique_ptr<IPC::ChannelProxy> channel( | 991 channel.reset(new IPC::ChannelProxy(this, runner.get())); |
| 994 new IPC::ChannelProxy(this, runner.get())); | |
| 995 #if USE_ATTACHMENT_BROKER | 992 #if USE_ATTACHMENT_BROKER |
| 996 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | 993 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( |
| 997 channel.get(), runner); | 994 channel.get(), runner); |
| 998 #endif | 995 #endif |
| 999 channel->Init(std::move(channel_factory), true); | 996 // The channel remains paused until OnProcessLaunched() so we can allow some |
| 997 // initialization messages there to preempt all other messages. |
| 998 channel->Init(std::move(channel_factory), true /* create_pipe_now */, |
| 999 true /* create_paused */); |
| 1000 |
| 1001 // Queue all pending messages in the channel now. This allows them to be |
| 1002 // ordered with respect to Mojo interface requests and method calls. |
| 1003 while (!queued_messages_.empty()) { |
| 1004 channel->Send(queued_messages_.front().release()); |
| 1005 queued_messages_.pop(); |
| 1006 } |
| 1007 |
| 1000 return channel; | 1008 return channel; |
| 1001 } | 1009 } |
| 1002 | 1010 |
| 1003 void RenderProcessHostImpl::CreateMessageFilters() { | 1011 void RenderProcessHostImpl::CreateMessageFilters() { |
| 1004 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1012 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1005 AddFilter(new ResourceSchedulerFilter(GetID())); | 1013 AddFilter(new ResourceSchedulerFilter(GetID())); |
| 1006 MediaInternals* media_internals = MediaInternals::GetInstance(); | 1014 MediaInternals* media_internals = MediaInternals::GetInstance(); |
| 1007 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages | 1015 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages |
| 1008 // from guests. | 1016 // from guests. |
| 1009 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( | 1017 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 void RenderProcessHostImpl::RegisterMojoInterfaces() { | 1199 void RenderProcessHostImpl::RegisterMojoInterfaces() { |
| 1192 std::unique_ptr<shell::InterfaceRegistry> registry( | 1200 std::unique_ptr<shell::InterfaceRegistry> registry( |
| 1193 new shell::InterfaceRegistry); | 1201 new shell::InterfaceRegistry); |
| 1194 #if defined(OS_ANDROID) | 1202 #if defined(OS_ANDROID) |
| 1195 interface_registry_android_ = | 1203 interface_registry_android_ = |
| 1196 InterfaceRegistryAndroid::Create(registry.get()); | 1204 InterfaceRegistryAndroid::Create(registry.get()); |
| 1197 InterfaceRegistrarAndroid::ExposeInterfacesToRenderer( | 1205 InterfaceRegistrarAndroid::ExposeInterfacesToRenderer( |
| 1198 interface_registry_android_.get()); | 1206 interface_registry_android_.get()); |
| 1199 #endif | 1207 #endif |
| 1200 | 1208 |
| 1209 channel_->AddAssociatedInterface( |
| 1210 base::Bind(&RenderProcessHostImpl::OnRouteProviderRequest, |
| 1211 base::Unretained(this))); |
| 1212 |
| 1201 #if !defined(OS_ANDROID) | 1213 #if !defined(OS_ANDROID) |
| 1202 AddUIThreadInterface( | 1214 AddUIThreadInterface( |
| 1203 registry.get(), base::Bind(&device::BatteryMonitorImpl::Create)); | 1215 registry.get(), base::Bind(&device::BatteryMonitorImpl::Create)); |
| 1204 #endif | 1216 #endif |
| 1205 AddUIThreadInterface( | 1217 AddUIThreadInterface( |
| 1206 registry.get(), | 1218 registry.get(), |
| 1207 base::Bind(&PermissionServiceContext::CreateService, | 1219 base::Bind(&PermissionServiceContext::CreateService, |
| 1208 base::Unretained(permission_service_context_.get()))); | 1220 base::Unretained(permission_service_context_.get()))); |
| 1209 // TODO(mcasas): finalize arguments. | 1221 // TODO(mcasas): finalize arguments. |
| 1210 AddUIThreadInterface(registry.get(), base::Bind(&ImageCaptureImpl::Create)); | 1222 AddUIThreadInterface(registry.get(), base::Bind(&ImageCaptureImpl::Create)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 MojoShellConnection* mojo_shell_connection = | 1276 MojoShellConnection* mojo_shell_connection = |
| 1265 BrowserContext::GetMojoShellConnectionFor(browser_context_); | 1277 BrowserContext::GetMojoShellConnectionFor(browser_context_); |
| 1266 std::unique_ptr<ConnectionFilterImpl> connection_filter( | 1278 std::unique_ptr<ConnectionFilterImpl> connection_filter( |
| 1267 new ConnectionFilterImpl(mojo_child_connection_->child_identity(), | 1279 new ConnectionFilterImpl(mojo_child_connection_->child_identity(), |
| 1268 std::move(registry))); | 1280 std::move(registry))); |
| 1269 connection_filter_controller_ = connection_filter->controller(); | 1281 connection_filter_controller_ = connection_filter->controller(); |
| 1270 connection_filter_id_ = | 1282 connection_filter_id_ = |
| 1271 mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); | 1283 mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); |
| 1272 } | 1284 } |
| 1273 | 1285 |
| 1286 void RenderProcessHostImpl::GetRoutedInterfaces( |
| 1287 int32_t routing_id, |
| 1288 mojom::RoutedInterfaceProviderAssociatedRequest request) { |
| 1289 auto it = routed_interface_providers_.find(routing_id); |
| 1290 if (it == routed_interface_providers_.end()) |
| 1291 return; |
| 1292 DCHECK(request.is_pending()); |
| 1293 routed_interface_provider_bindings_.AddBinding(it->second, |
| 1294 std::move(request)); |
| 1295 } |
| 1296 |
| 1274 void RenderProcessHostImpl::CreateStoragePartitionService( | 1297 void RenderProcessHostImpl::CreateStoragePartitionService( |
| 1275 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1298 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
| 1276 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1299 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
| 1277 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1300 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1278 switches::kMojoLocalStorage)) { | 1301 switches::kMojoLocalStorage)) { |
| 1279 storage_partition_impl_->Bind(std::move(request)); | 1302 storage_partition_impl_->Bind(std::move(request)); |
| 1280 } | 1303 } |
| 1281 } | 1304 } |
| 1282 | 1305 |
| 1283 int RenderProcessHostImpl::GetNextRoutingID() { | 1306 int RenderProcessHostImpl::GetNextRoutingID() { |
| 1284 return widget_helper_->GetNextRoutingID(); | 1307 return widget_helper_->GetNextRoutingID(); |
| 1285 } | 1308 } |
| 1286 | 1309 |
| 1287 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1310 void RenderProcessHostImpl::ResumeDeferredNavigation( |
| 1288 const GlobalRequestID& request_id) { | 1311 const GlobalRequestID& request_id) { |
| 1289 widget_helper_->ResumeDeferredNavigation(request_id); | 1312 widget_helper_->ResumeDeferredNavigation(request_id); |
| 1290 } | 1313 } |
| 1291 | 1314 |
| 1292 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1315 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
| 1293 Send(new ViewMsg_TimezoneChange(zone_id)); | 1316 Send(new ViewMsg_TimezoneChange(zone_id)); |
| 1294 } | 1317 } |
| 1295 | 1318 |
| 1296 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { | 1319 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { |
| 1297 return mojo_child_connection_->GetRemoteInterfaces(); | 1320 return mojo_child_connection_->GetRemoteInterfaces(); |
| 1298 } | 1321 } |
| 1299 | 1322 |
| 1323 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { |
| 1324 if (!remote_route_provider_) { |
| 1325 DCHECK(channel_); |
| 1326 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); |
| 1327 } |
| 1328 return remote_route_provider_.get(); |
| 1329 } |
| 1330 |
| 1300 std::unique_ptr<base::SharedPersistentMemoryAllocator> | 1331 std::unique_ptr<base::SharedPersistentMemoryAllocator> |
| 1301 RenderProcessHostImpl::TakeMetricsAllocator() { | 1332 RenderProcessHostImpl::TakeMetricsAllocator() { |
| 1302 return std::move(metrics_allocator_); | 1333 return std::move(metrics_allocator_); |
| 1303 } | 1334 } |
| 1304 | 1335 |
| 1305 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1336 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
| 1306 const { | 1337 const { |
| 1307 return init_time_; | 1338 return init_time_; |
| 1308 } | 1339 } |
| 1309 | 1340 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 } | 1374 } |
| 1344 | 1375 |
| 1345 void RenderProcessHostImpl::AddRoute(int32_t routing_id, | 1376 void RenderProcessHostImpl::AddRoute(int32_t routing_id, |
| 1346 IPC::Listener* listener) { | 1377 IPC::Listener* listener) { |
| 1347 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " | 1378 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " |
| 1348 << routing_id; | 1379 << routing_id; |
| 1349 listeners_.AddWithID(listener, routing_id); | 1380 listeners_.AddWithID(listener, routing_id); |
| 1350 } | 1381 } |
| 1351 | 1382 |
| 1352 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { | 1383 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { |
| 1353 DCHECK(listeners_.Lookup(routing_id) != NULL); | 1384 DCHECK(listeners_.Lookup(routing_id) != nullptr); |
| 1354 listeners_.Remove(routing_id); | 1385 listeners_.Remove(routing_id); |
| 1386 routed_interface_providers_.erase(routing_id); |
| 1355 Cleanup(); | 1387 Cleanup(); |
| 1356 } | 1388 } |
| 1357 | 1389 |
| 1390 void RenderProcessHostImpl::AddRoutedInterfaces( |
| 1391 int32_t routing_id, |
| 1392 mojom::RoutedInterfaceProvider* provider) { |
| 1393 auto result = |
| 1394 routed_interface_providers_.insert(std::make_pair(routing_id, provider)); |
| 1395 DCHECK(result.second); |
| 1396 } |
| 1397 |
| 1398 mojo::AssociatedGroup* RenderProcessHostImpl::GetRoutedInterfaceGroup() { |
| 1399 // Ensure that our route provider interface is bound. |
| 1400 ignore_result(GetRemoteInterfaces()); |
| 1401 DCHECK(remote_route_provider_); |
| 1402 return remote_route_provider_.associated_group(); |
| 1403 } |
| 1404 |
| 1358 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { | 1405 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { |
| 1359 observers_.AddObserver(observer); | 1406 observers_.AddObserver(observer); |
| 1360 } | 1407 } |
| 1361 | 1408 |
| 1362 void RenderProcessHostImpl::RemoveObserver( | 1409 void RenderProcessHostImpl::RemoveObserver( |
| 1363 RenderProcessHostObserver* observer) { | 1410 RenderProcessHostObserver* observer) { |
| 1364 observers_.RemoveObserver(observer); | 1411 observers_.RemoveObserver(observer); |
| 1365 } | 1412 } |
| 1366 | 1413 |
| 1367 void RenderProcessHostImpl::ShutdownForBadMessage() { | 1414 void RenderProcessHostImpl::ShutdownForBadMessage() { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1848 // Set this before ProcessDied() so observers can tell if the render process | 1895 // Set this before ProcessDied() so observers can tell if the render process |
| 1849 // died due to fast shutdown versus another cause. | 1896 // died due to fast shutdown versus another cause. |
| 1850 fast_shutdown_started_ = true; | 1897 fast_shutdown_started_ = true; |
| 1851 | 1898 |
| 1852 ProcessDied(false /* already_dead */, nullptr); | 1899 ProcessDied(false /* already_dead */, nullptr); |
| 1853 return true; | 1900 return true; |
| 1854 } | 1901 } |
| 1855 | 1902 |
| 1856 bool RenderProcessHostImpl::Send(IPC::Message* msg) { | 1903 bool RenderProcessHostImpl::Send(IPC::Message* msg) { |
| 1857 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); | 1904 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); |
| 1905 |
| 1906 std::unique_ptr<IPC::Message> message(msg); |
| 1907 |
| 1858 #if !defined(OS_ANDROID) | 1908 #if !defined(OS_ANDROID) |
| 1859 DCHECK(!msg->is_sync()); | 1909 DCHECK(!message->is_sync()); |
| 1860 #endif | 1910 #endif |
| 1861 | 1911 |
| 1862 if (!channel_) { | 1912 if (!channel_) { |
| 1863 #if defined(OS_ANDROID) | 1913 #if defined(OS_ANDROID) |
| 1864 if (msg->is_sync()) { | 1914 if (message->is_sync()) |
| 1865 delete msg; | |
| 1866 return false; | 1915 return false; |
| 1867 } | |
| 1868 #endif | 1916 #endif |
| 1869 if (!is_initialized_) { | 1917 if (!is_initialized_) { |
| 1870 queued_messages_.push(msg); | 1918 queued_messages_.emplace(std::move(message)); |
| 1871 return true; | 1919 return true; |
| 1872 } else { | |
| 1873 delete msg; | |
| 1874 return false; | |
| 1875 } | 1920 } |
| 1921 return false; |
| 1876 } | 1922 } |
| 1877 | 1923 |
| 1878 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) { | |
| 1879 #if defined(OS_ANDROID) | 1924 #if defined(OS_ANDROID) |
| 1880 if (msg->is_sync()) { | 1925 if (child_process_launcher_.get() && child_process_launcher_->IsStarting() && |
| 1881 delete msg; | 1926 message->is_sync()) { |
| 1882 return false; | 1927 return false; |
| 1883 } | 1928 } |
| 1884 #endif | 1929 #endif |
| 1885 queued_messages_.push(msg); | |
| 1886 return true; | |
| 1887 } | |
| 1888 | 1930 |
| 1889 return channel_->Send(msg); | 1931 return channel_->Send(message.release()); |
| 1890 } | 1932 } |
| 1891 | 1933 |
| 1892 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 1934 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
| 1893 // If we're about to be deleted, or have initiated the fast shutdown sequence, | 1935 // If we're about to be deleted, or have initiated the fast shutdown sequence, |
| 1894 // we ignore incoming messages. | 1936 // we ignore incoming messages. |
| 1895 | 1937 |
| 1896 if (deleting_soon_ || fast_shutdown_started_) | 1938 if (deleting_soon_ || fast_shutdown_started_) |
| 1897 return false; | 1939 return false; |
| 1898 | 1940 |
| 1899 mark_child_process_activity_time(); | 1941 mark_child_process_activity_time(); |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2535 return; | 2577 return; |
| 2536 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( | 2578 metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( |
| 2537 std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false)); | 2579 std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false)); |
| 2538 | 2580 |
| 2539 base::SharedMemoryHandle shm_handle; | 2581 base::SharedMemoryHandle shm_handle; |
| 2540 metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle); | 2582 metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle); |
| 2541 Send(new ChildProcessMsg_SetHistogramMemory( | 2583 Send(new ChildProcessMsg_SetHistogramMemory( |
| 2542 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); | 2584 shm_handle, metrics_allocator_->shared_memory()->mapped_size())); |
| 2543 } | 2585 } |
| 2544 | 2586 |
| 2587 void RenderProcessHostImpl::OnRouteProviderRequest( |
| 2588 mojom::RouteProviderAssociatedRequest request) { |
| 2589 if (route_provider_binding_.is_bound()) |
| 2590 return; |
| 2591 route_provider_binding_.Bind(std::move(request)); |
| 2592 } |
| 2593 |
| 2545 void RenderProcessHostImpl::ProcessDied(bool already_dead, | 2594 void RenderProcessHostImpl::ProcessDied(bool already_dead, |
| 2546 RendererClosedDetails* known_details) { | 2595 RendererClosedDetails* known_details) { |
| 2547 // Our child process has died. If we didn't expect it, it's a crash. | 2596 // Our child process has died. If we didn't expect it, it's a crash. |
| 2548 // In any case, we need to let everyone know it's gone. | 2597 // In any case, we need to let everyone know it's gone. |
| 2549 // The OnChannelError notification can fire multiple times due to nested sync | 2598 // The OnChannelError notification can fire multiple times due to nested sync |
| 2550 // calls to a renderer. If we don't have a valid channel here it means we | 2599 // calls to a renderer. If we don't have a valid channel here it means we |
| 2551 // already handled the error. | 2600 // already handled the error. |
| 2552 | 2601 |
| 2553 // It should not be possible for us to be called re-entrantly. | 2602 // It should not be possible for us to be called re-entrantly. |
| 2554 DCHECK(!within_process_died_observer_); | 2603 DCHECK(!within_process_died_observer_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2579 } | 2628 } |
| 2580 | 2629 |
| 2581 RendererClosedDetails details(status, exit_code); | 2630 RendererClosedDetails details(status, exit_code); |
| 2582 | 2631 |
| 2583 child_process_launcher_.reset(); | 2632 child_process_launcher_.reset(); |
| 2584 #if USE_ATTACHMENT_BROKER | 2633 #if USE_ATTACHMENT_BROKER |
| 2585 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 2634 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
| 2586 channel_.get()); | 2635 channel_.get()); |
| 2587 #endif | 2636 #endif |
| 2588 channel_.reset(); | 2637 channel_.reset(); |
| 2589 while (!queued_messages_.empty()) { | 2638 while (!queued_messages_.empty()) |
| 2590 delete queued_messages_.front(); | |
| 2591 queued_messages_.pop(); | 2639 queued_messages_.pop(); |
| 2592 } | |
| 2593 UpdateProcessPriority(); | 2640 UpdateProcessPriority(); |
| 2594 DCHECK(!is_process_backgrounded_); | 2641 DCHECK(!is_process_backgrounded_); |
| 2595 | 2642 |
| 2596 // RenderProcessExited observers and RenderProcessGone handlers might | 2643 // RenderProcessExited observers and RenderProcessGone handlers might |
| 2597 // navigate or perform other actions that require a connection. Ensure that | 2644 // navigate or perform other actions that require a connection. Ensure that |
| 2598 // there is one before calling them. | 2645 // there is one before calling them. |
| 2599 child_token_ = mojo::edk::GenerateRandomToken(); | 2646 child_token_ = mojo::edk::GenerateRandomToken(); |
| 2600 shell::Connector* connector = | 2647 shell::Connector* connector = |
| 2601 BrowserContext::GetShellConnectorFor(browser_context_); | 2648 BrowserContext::GetShellConnectorFor(browser_context_); |
| 2602 if (!connector) | 2649 if (!connector) |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2729 } | 2776 } |
| 2730 | 2777 |
| 2731 void RenderProcessHostImpl::OnProcessLaunched() { | 2778 void RenderProcessHostImpl::OnProcessLaunched() { |
| 2732 // No point doing anything, since this object will be destructed soon. We | 2779 // No point doing anything, since this object will be destructed soon. We |
| 2733 // especially don't want to send the RENDERER_PROCESS_CREATED notification, | 2780 // especially don't want to send the RENDERER_PROCESS_CREATED notification, |
| 2734 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to | 2781 // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to |
| 2735 // properly cleanup. | 2782 // properly cleanup. |
| 2736 if (deleting_soon_) | 2783 if (deleting_soon_) |
| 2737 return; | 2784 return; |
| 2738 | 2785 |
| 2786 // Unpause the channel now that the process is launched. We don't flush it yet |
| 2787 // to ensure that any initialization messages sent here (e.g., things done in |
| 2788 // response to NOTIFICATION_RENDER_PROCESS_CREATED; see below) preempt already |
| 2789 // queued messages. |
| 2790 channel_->Unpause(false /* flush */); |
| 2791 |
| 2739 if (child_process_launcher_) { | 2792 if (child_process_launcher_) { |
| 2740 DCHECK(child_process_launcher_->GetProcess().IsValid()); | 2793 DCHECK(child_process_launcher_->GetProcess().IsValid()); |
| 2741 DCHECK(!is_process_backgrounded_); | 2794 DCHECK(!is_process_backgrounded_); |
| 2742 | 2795 |
| 2743 if (mojo_child_connection_) { | 2796 if (mojo_child_connection_) { |
| 2744 mojo_child_connection_->SetProcessHandle( | 2797 mojo_child_connection_->SetProcessHandle( |
| 2745 child_process_launcher_->GetProcess().Handle()); | 2798 child_process_launcher_->GetProcess().Handle()); |
| 2746 } | 2799 } |
| 2747 | 2800 |
| 2748 // Not all platforms launch processes in the same backgrounded state. Make | 2801 // Not all platforms launch processes in the same backgrounded state. Make |
| 2749 // sure |is_process_backgrounded_| reflects this platform's initial process | 2802 // sure |is_process_backgrounded_| reflects this platform's initial process |
| 2750 // state. | 2803 // state. |
| 2751 is_process_backgrounded_ = | 2804 is_process_backgrounded_ = |
| 2752 child_process_launcher_->GetProcess().IsProcessBackgrounded(); | 2805 child_process_launcher_->GetProcess().IsProcessBackgrounded(); |
| 2753 | 2806 |
| 2754 // Disable updating process priority on startup for now as it incorrectly | 2807 // Disable updating process priority on startup for now as it incorrectly |
| 2755 // results in backgrounding foreground navigations until their first commit | 2808 // results in backgrounding foreground navigations until their first commit |
| 2756 // is made. A better long term solution would be to be aware of the tab's | 2809 // is made. A better long term solution would be to be aware of the tab's |
| 2757 // visibility at this point. https://crbug.com/560446. | 2810 // visibility at this point. https://crbug.com/560446. |
| 2758 // Except on Android for now because of https://crbug.com/601184 :-(. | 2811 // Except on Android for now because of https://crbug.com/601184 :-(. |
| 2759 #if defined(OS_ANDROID) | 2812 #if defined(OS_ANDROID) |
| 2760 UpdateProcessPriority(); | 2813 UpdateProcessPriority(); |
| 2761 #endif | 2814 #endif |
| 2762 | 2815 |
| 2763 // Share histograms between the renderer and this process. | 2816 // Share histograms between the renderer and this process. |
| 2764 CreateSharedRendererHistogramAllocator(); | 2817 CreateSharedRendererHistogramAllocator(); |
| 2765 } | 2818 } |
| 2766 | 2819 |
| 2767 // NOTE: This needs to be before sending queued messages because | 2820 // NOTE: This needs to be before flushing queued messages, because |
| 2768 // ExtensionService uses this notification to initialize the renderer process | 2821 // ExtensionService uses this notification to initialize the renderer process |
| 2769 // with state that must be there before any JavaScript executes. | 2822 // with state that must be there before any JavaScript executes. |
| 2770 // | 2823 // |
| 2771 // The queued messages contain such things as "navigate". If this notification | 2824 // The queued messages contain such things as "navigate". If this notification |
| 2772 // was after, we can end up executing JavaScript before the initialization | 2825 // was after, we can end up executing JavaScript before the initialization |
| 2773 // happens. | 2826 // happens. |
| 2774 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2827 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 2775 Source<RenderProcessHost>(this), | 2828 Source<RenderProcessHost>(this), |
| 2776 NotificationService::NoDetails()); | 2829 NotificationService::NoDetails()); |
| 2777 | 2830 |
| 2778 while (!queued_messages_.empty()) { | 2831 channel_->Flush(); |
| 2779 Send(queued_messages_.front()); | |
| 2780 queued_messages_.pop(); | |
| 2781 } | |
| 2782 | 2832 |
| 2783 if (IsReady()) { | 2833 if (IsReady()) { |
| 2784 DCHECK(!sent_render_process_ready_); | 2834 DCHECK(!sent_render_process_ready_); |
| 2785 sent_render_process_ready_ = true; | 2835 sent_render_process_ready_ = true; |
| 2786 // Send RenderProcessReady only if the channel is already connected. | 2836 // Send RenderProcessReady only if the channel is already connected. |
| 2787 FOR_EACH_OBSERVER(RenderProcessHostObserver, | 2837 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
| 2788 observers_, | 2838 observers_, |
| 2789 RenderProcessReady(this)); | 2839 RenderProcessReady(this)); |
| 2790 } | 2840 } |
| 2791 | 2841 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2934 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2984 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 2935 | 2985 |
| 2936 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2986 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
| 2937 // enough information here so that we can determine what the bad message was. | 2987 // enough information here so that we can determine what the bad message was. |
| 2938 base::debug::Alias(&error); | 2988 base::debug::Alias(&error); |
| 2939 bad_message::ReceivedBadMessage(process.get(), | 2989 bad_message::ReceivedBadMessage(process.get(), |
| 2940 bad_message::RPH_MOJO_PROCESS_ERROR); | 2990 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 2941 } | 2991 } |
| 2942 | 2992 |
| 2943 } // namespace content | 2993 } // namespace content |
| OLD | NEW |