| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 808     ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); | 811     ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); | 
| 809     gpu_observer_registered_ = false; | 812     gpu_observer_registered_ = false; | 
| 810   } | 813   } | 
| 811 | 814 | 
| 812 #if USE_ATTACHMENT_BROKER | 815 #if USE_ATTACHMENT_BROKER | 
| 813   IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 816   IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 
| 814       channel_.get()); | 817       channel_.get()); | 
| 815 #endif | 818 #endif | 
| 816   // We may have some unsent messages at this point, but that's OK. | 819   // We may have some unsent messages at this point, but that's OK. | 
| 817   channel_.reset(); | 820   channel_.reset(); | 
| 818   while (!queued_messages_.empty()) { | 821   queued_messages_ = MessageQueue{}; | 
| 819     delete queued_messages_.front(); |  | 
| 820     queued_messages_.pop(); |  | 
| 821   } |  | 
| 822 | 822 | 
| 823   UnregisterHost(GetID()); | 823   UnregisterHost(GetID()); | 
| 824 | 824 | 
| 825   if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 825   if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 826           switches::kDisableGpuShaderDiskCache)) { | 826           switches::kDisableGpuShaderDiskCache)) { | 
| 827     BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 827     BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 
| 828                             base::Bind(&RemoveShaderInfo, GetID())); | 828                             base::Bind(&RemoveShaderInfo, GetID())); | 
| 829   } | 829   } | 
| 830 } | 830 } | 
| 831 | 831 | 
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 934 | 934 | 
| 935     // Spawn the child process asynchronously to avoid blocking the UI thread. | 935     // Spawn the child process asynchronously to avoid blocking the UI thread. | 
| 936     // As long as there's no renderer prefix, we can use the zygote process | 936     // As long as there's no renderer prefix, we can use the zygote process | 
| 937     // at this stage. | 937     // at this stage. | 
| 938     child_process_launcher_.reset(new ChildProcessLauncher( | 938     child_process_launcher_.reset(new ChildProcessLauncher( | 
| 939         new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, | 939         new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, | 
| 940         GetID(), this, child_token_, | 940         GetID(), this, child_token_, | 
| 941         base::Bind(&RenderProcessHostImpl::OnMojoError, | 941         base::Bind(&RenderProcessHostImpl::OnMojoError, | 
| 942                    weak_factory_.GetWeakPtr(), | 942                    weak_factory_.GetWeakPtr(), | 
| 943                    base::ThreadTaskRunnerHandle::Get()))); | 943                    base::ThreadTaskRunnerHandle::Get()))); | 
|  | 944     channel_->Pause(); | 
| 944 | 945 | 
| 945     fast_shutdown_started_ = false; | 946     fast_shutdown_started_ = false; | 
| 946   } | 947   } | 
| 947 | 948 | 
|  | 949   // Push any pending messages to the channel now. Note that if the child | 
|  | 950   // process is still launching, the channel will be paused and outgoing | 
|  | 951   // messages will be queued internally by the channel. | 
|  | 952   while (!queued_messages_.empty()) { | 
|  | 953     channel_->Send(queued_messages_.front().release()); | 
|  | 954     queued_messages_.pop(); | 
|  | 955   } | 
|  | 956 | 
| 948   if (!gpu_observer_registered_) { | 957   if (!gpu_observer_registered_) { | 
| 949     gpu_observer_registered_ = true; | 958     gpu_observer_registered_ = true; | 
| 950     ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 959     ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 
| 951   } | 960   } | 
| 952 | 961 | 
| 953   power_monitor_broadcaster_.Init(); | 962   power_monitor_broadcaster_.Init(); | 
| 954 | 963 | 
| 955   is_initialized_ = true; | 964   is_initialized_ = true; | 
| 956   init_time_ = base::TimeTicks::Now(); | 965   init_time_ = base::TimeTicks::Now(); | 
| 957   return true; | 966   return true; | 
| 958 } | 967 } | 
| 959 | 968 | 
| 960 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( | 969 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( | 
| 961     const std::string& channel_id) { | 970     const std::string& channel_id) { | 
| 962   scoped_refptr<base::SingleThreadTaskRunner> runner = | 971   scoped_refptr<base::SingleThreadTaskRunner> runner = | 
| 963       BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 972       BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 
| 964   IPC::mojom::ChannelBootstrapPtr bootstrap; | 973   IPC::mojom::ChannelBootstrapPtr bootstrap; | 
| 965   GetRemoteInterfaces()->GetInterface(&bootstrap); | 974   GetRemoteInterfaces()->GetInterface(&bootstrap); | 
| 966   std::unique_ptr<IPC::ChannelFactory> channel_factory = | 975   std::unique_ptr<IPC::ChannelFactory> channel_factory = | 
| 967       IPC::ChannelMojo::CreateServerFactory( | 976       IPC::ChannelMojo::CreateServerFactory( | 
| 968           bootstrap.PassInterface().PassHandle(), runner); | 977           bootstrap.PassInterface().PassHandle(), runner); | 
| 969 | 978 | 
|  | 979   std::unique_ptr<IPC::ChannelProxy> channel; | 
| 970   // Do NOT expand ifdef or run time condition checks here! Synchronous | 980   // Do NOT expand ifdef or run time condition checks here! Synchronous | 
| 971   // IPCs from browser process are banned. It is only narrowly allowed | 981   // IPCs from browser process are banned. It is only narrowly allowed | 
| 972   // for Android WebView to maintain backward compatibility. | 982   // for Android WebView to maintain backward compatibility. | 
| 973   // See crbug.com/526842 for details. | 983   // See crbug.com/526842 for details. | 
| 974 #if defined(OS_ANDROID) | 984 #if defined(OS_ANDROID) | 
| 975   if (GetContentClient()->UsingSynchronousCompositing()) { | 985   if (GetContentClient()->UsingSynchronousCompositing()) | 
| 976     return IPC::SyncChannel::Create( | 986     channel = IPC::SyncChannel::Create(this, runner.get(), &never_signaled_); | 
| 977         std::move(channel_factory), this, runner.get(), true, &never_signaled_); |  | 
| 978   } |  | 
| 979 #endif  // OS_ANDROID | 987 #endif  // OS_ANDROID | 
| 980 | 988   if (!channel) | 
| 981   std::unique_ptr<IPC::ChannelProxy> channel( | 989     channel.reset(new IPC::ChannelProxy(this, runner.get())); | 
| 982       new IPC::ChannelProxy(this, runner.get())); |  | 
| 983 #if USE_ATTACHMENT_BROKER | 990 #if USE_ATTACHMENT_BROKER | 
| 984   IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | 991   IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | 
| 985       channel.get(), runner); | 992       channel.get(), runner); | 
| 986 #endif | 993 #endif | 
| 987   channel->Init(std::move(channel_factory), true); | 994   channel->Init(std::move(channel_factory), true /* create_pipe_now */); | 
|  | 995 | 
| 988   return channel; | 996   return channel; | 
| 989 } | 997 } | 
| 990 | 998 | 
| 991 void RenderProcessHostImpl::CreateMessageFilters() { | 999 void RenderProcessHostImpl::CreateMessageFilters() { | 
| 992   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1000   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 993   AddFilter(new ResourceSchedulerFilter(GetID())); | 1001   AddFilter(new ResourceSchedulerFilter(GetID())); | 
| 994   MediaInternals* media_internals = MediaInternals::GetInstance(); | 1002   MediaInternals* media_internals = MediaInternals::GetInstance(); | 
| 995   // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages | 1003   // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages | 
| 996   // from guests. | 1004   // from guests. | 
| 997   scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( | 1005   scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( | 
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1179 void RenderProcessHostImpl::RegisterMojoInterfaces() { | 1187 void RenderProcessHostImpl::RegisterMojoInterfaces() { | 
| 1180   std::unique_ptr<shell::InterfaceRegistry> registry( | 1188   std::unique_ptr<shell::InterfaceRegistry> registry( | 
| 1181       new shell::InterfaceRegistry); | 1189       new shell::InterfaceRegistry); | 
| 1182 #if defined(OS_ANDROID) | 1190 #if defined(OS_ANDROID) | 
| 1183   interface_registry_android_ = | 1191   interface_registry_android_ = | 
| 1184       InterfaceRegistryAndroid::Create(registry.get()); | 1192       InterfaceRegistryAndroid::Create(registry.get()); | 
| 1185   InterfaceRegistrarAndroid::ExposeInterfacesToRenderer( | 1193   InterfaceRegistrarAndroid::ExposeInterfacesToRenderer( | 
| 1186       interface_registry_android_.get()); | 1194       interface_registry_android_.get()); | 
| 1187 #endif | 1195 #endif | 
| 1188 | 1196 | 
|  | 1197   channel_->AddAssociatedInterface( | 
|  | 1198       base::Bind(&RenderProcessHostImpl::OnRouteProviderRequest, | 
|  | 1199                  base::Unretained(this))); | 
|  | 1200 | 
| 1189 #if !defined(OS_ANDROID) | 1201 #if !defined(OS_ANDROID) | 
| 1190   AddUIThreadInterface( | 1202   AddUIThreadInterface( | 
| 1191       registry.get(), base::Bind(&device::BatteryMonitorImpl::Create)); | 1203       registry.get(), base::Bind(&device::BatteryMonitorImpl::Create)); | 
| 1192 #endif | 1204 #endif | 
| 1193   AddUIThreadInterface( | 1205   AddUIThreadInterface( | 
| 1194       registry.get(), | 1206       registry.get(), | 
| 1195       base::Bind(&PermissionServiceContext::CreateService, | 1207       base::Bind(&PermissionServiceContext::CreateService, | 
| 1196                  base::Unretained(permission_service_context_.get()))); | 1208                  base::Unretained(permission_service_context_.get()))); | 
| 1197   // TODO(mcasas): finalize arguments. | 1209   // TODO(mcasas): finalize arguments. | 
| 1198   AddUIThreadInterface(registry.get(), base::Bind(&ImageCaptureImpl::Create)); | 1210   AddUIThreadInterface(registry.get(), base::Bind(&ImageCaptureImpl::Create)); | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1254   MojoShellConnection* mojo_shell_connection = | 1266   MojoShellConnection* mojo_shell_connection = | 
| 1255       BrowserContext::GetMojoShellConnectionFor(browser_context_); | 1267       BrowserContext::GetMojoShellConnectionFor(browser_context_); | 
| 1256   std::unique_ptr<ConnectionFilterImpl> connection_filter( | 1268   std::unique_ptr<ConnectionFilterImpl> connection_filter( | 
| 1257       new ConnectionFilterImpl(mojo_child_connection_->child_identity(), | 1269       new ConnectionFilterImpl(mojo_child_connection_->child_identity(), | 
| 1258                                std::move(registry))); | 1270                                std::move(registry))); | 
| 1259   connection_filter_controller_ = connection_filter->controller(); | 1271   connection_filter_controller_ = connection_filter->controller(); | 
| 1260   connection_filter_id_ = | 1272   connection_filter_id_ = | 
| 1261       mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); | 1273       mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); | 
| 1262 } | 1274 } | 
| 1263 | 1275 | 
|  | 1276 void RenderProcessHostImpl::GetRoute( | 
|  | 1277     int32_t routing_id, | 
|  | 1278     mojom::AssociatedInterfaceProviderAssociatedRequest request) { | 
|  | 1279   DCHECK(request.is_pending()); | 
|  | 1280   associated_interface_provider_bindings_.AddBinding( | 
|  | 1281       this, std::move(request), | 
|  | 1282       reinterpret_cast<void*>(static_cast<uintptr_t>(routing_id))); | 
|  | 1283 } | 
|  | 1284 | 
|  | 1285 void RenderProcessHostImpl::GetAssociatedInterface( | 
|  | 1286     const std::string& name, | 
|  | 1287     mojom::AssociatedInterfaceAssociatedRequest request) { | 
|  | 1288   int32_t routing_id = static_cast<int32_t>(reinterpret_cast<uintptr_t>( | 
|  | 1289       associated_interface_provider_bindings_.dispatch_context())); | 
|  | 1290   IPC::Listener* listener = listeners_.Lookup(routing_id); | 
|  | 1291   if (listener) | 
|  | 1292     listener->OnAssociatedInterfaceRequest(name, request.PassHandle()); | 
|  | 1293 } | 
|  | 1294 | 
| 1264 void RenderProcessHostImpl::CreateStoragePartitionService( | 1295 void RenderProcessHostImpl::CreateStoragePartitionService( | 
| 1265     mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1296     mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 
| 1266   // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1297   // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 
| 1267   if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1298   if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 1268           switches::kMojoLocalStorage)) { | 1299           switches::kMojoLocalStorage)) { | 
| 1269     storage_partition_impl_->Bind(std::move(request)); | 1300     storage_partition_impl_->Bind(std::move(request)); | 
| 1270   } | 1301   } | 
| 1271 } | 1302 } | 
| 1272 | 1303 | 
| 1273 int RenderProcessHostImpl::GetNextRoutingID() { | 1304 int RenderProcessHostImpl::GetNextRoutingID() { | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1340   DCHECK_GT(worker_ref_count(), 0UL); | 1371   DCHECK_GT(worker_ref_count(), 0UL); | 
| 1341   --shared_worker_ref_count_; | 1372   --shared_worker_ref_count_; | 
| 1342   if (worker_ref_count() == 0) | 1373   if (worker_ref_count() == 0) | 
| 1343     Cleanup(); | 1374     Cleanup(); | 
| 1344 } | 1375 } | 
| 1345 | 1376 | 
| 1346 void RenderProcessHostImpl::PurgeAndSuspend() { | 1377 void RenderProcessHostImpl::PurgeAndSuspend() { | 
| 1347   Send(new ChildProcessMsg_PurgeAndSuspend()); | 1378   Send(new ChildProcessMsg_PurgeAndSuspend()); | 
| 1348 } | 1379 } | 
| 1349 | 1380 | 
|  | 1381 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { | 
|  | 1382   if (!remote_route_provider_) { | 
|  | 1383     DCHECK(channel_); | 
|  | 1384     channel_->GetRemoteAssociatedInterface(&remote_route_provider_); | 
|  | 1385   } | 
|  | 1386   return remote_route_provider_.get(); | 
|  | 1387 } | 
|  | 1388 | 
| 1350 void RenderProcessHostImpl::AddRoute(int32_t routing_id, | 1389 void RenderProcessHostImpl::AddRoute(int32_t routing_id, | 
| 1351                                      IPC::Listener* listener) { | 1390                                      IPC::Listener* listener) { | 
| 1352   CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " | 1391   CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " | 
| 1353                                         << routing_id; | 1392                                         << routing_id; | 
| 1354   listeners_.AddWithID(listener, routing_id); | 1393   listeners_.AddWithID(listener, routing_id); | 
| 1355 } | 1394 } | 
| 1356 | 1395 | 
| 1357 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { | 1396 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { | 
| 1358   DCHECK(listeners_.Lookup(routing_id) != NULL); | 1397   DCHECK(listeners_.Lookup(routing_id) != nullptr); | 
| 1359   listeners_.Remove(routing_id); | 1398   listeners_.Remove(routing_id); | 
| 1360   Cleanup(); | 1399   Cleanup(); | 
| 1361 } | 1400 } | 
| 1362 | 1401 | 
| 1363 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { | 1402 void RenderProcessHostImpl::AddObserver(RenderProcessHostObserver* observer) { | 
| 1364   observers_.AddObserver(observer); | 1403   observers_.AddObserver(observer); | 
| 1365 } | 1404 } | 
| 1366 | 1405 | 
| 1367 void RenderProcessHostImpl::RemoveObserver( | 1406 void RenderProcessHostImpl::RemoveObserver( | 
| 1368     RenderProcessHostObserver* observer) { | 1407     RenderProcessHostObserver* observer) { | 
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1854   // Set this before ProcessDied() so observers can tell if the render process | 1893   // Set this before ProcessDied() so observers can tell if the render process | 
| 1855   // died due to fast shutdown versus another cause. | 1894   // died due to fast shutdown versus another cause. | 
| 1856   fast_shutdown_started_ = true; | 1895   fast_shutdown_started_ = true; | 
| 1857 | 1896 | 
| 1858   ProcessDied(false /* already_dead */, nullptr); | 1897   ProcessDied(false /* already_dead */, nullptr); | 
| 1859   return true; | 1898   return true; | 
| 1860 } | 1899 } | 
| 1861 | 1900 | 
| 1862 bool RenderProcessHostImpl::Send(IPC::Message* msg) { | 1901 bool RenderProcessHostImpl::Send(IPC::Message* msg) { | 
| 1863   TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); | 1902   TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); | 
|  | 1903 | 
|  | 1904   std::unique_ptr<IPC::Message> message(msg); | 
|  | 1905 | 
| 1864 #if !defined(OS_ANDROID) | 1906 #if !defined(OS_ANDROID) | 
| 1865   DCHECK(!msg->is_sync()); | 1907   DCHECK(!message->is_sync()); | 
| 1866 #endif | 1908 #endif | 
| 1867 | 1909 | 
| 1868   if (!channel_) { | 1910   if (!channel_) { | 
| 1869 #if defined(OS_ANDROID) | 1911 #if defined(OS_ANDROID) | 
| 1870     if (msg->is_sync()) { | 1912     if (message->is_sync()) | 
| 1871       delete msg; |  | 
| 1872       return false; | 1913       return false; | 
| 1873     } |  | 
| 1874 #endif | 1914 #endif | 
| 1875     if (!is_initialized_) { | 1915     if (!is_initialized_) { | 
| 1876       queued_messages_.push(msg); | 1916       queued_messages_.emplace(std::move(message)); | 
| 1877       return true; | 1917       return true; | 
| 1878     } else { |  | 
| 1879       delete msg; |  | 
| 1880       return false; |  | 
| 1881     } | 1918     } | 
|  | 1919     return false; | 
| 1882   } | 1920   } | 
| 1883 | 1921 | 
| 1884   if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) { |  | 
| 1885 #if defined(OS_ANDROID) | 1922 #if defined(OS_ANDROID) | 
| 1886     if (msg->is_sync()) { | 1923   if (child_process_launcher_.get() && child_process_launcher_->IsStarting() && | 
| 1887       delete msg; | 1924       message->is_sync()) { | 
| 1888       return false; | 1925     return false; | 
| 1889     } | 1926   } | 
| 1890 #endif | 1927 #endif | 
| 1891     queued_messages_.push(msg); |  | 
| 1892     return true; |  | 
| 1893   } |  | 
| 1894 | 1928 | 
| 1895   return channel_->Send(msg); | 1929   return channel_->Send(message.release()); | 
| 1896 } | 1930 } | 
| 1897 | 1931 | 
| 1898 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 1932 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 
| 1899   // If we're about to be deleted, or have initiated the fast shutdown sequence, | 1933   // If we're about to be deleted, or have initiated the fast shutdown sequence, | 
| 1900   // we ignore incoming messages. | 1934   // we ignore incoming messages. | 
| 1901 | 1935 | 
| 1902   if (deleting_soon_ || fast_shutdown_started_) | 1936   if (deleting_soon_ || fast_shutdown_started_) | 
| 1903     return false; | 1937     return false; | 
| 1904 | 1938 | 
| 1905   mark_child_process_activity_time(); | 1939   mark_child_process_activity_time(); | 
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2541     return; | 2575     return; | 
| 2542   metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( | 2576   metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator( | 
| 2543       std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false)); | 2577       std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false)); | 
| 2544 | 2578 | 
| 2545   base::SharedMemoryHandle shm_handle; | 2579   base::SharedMemoryHandle shm_handle; | 
| 2546   metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle); | 2580   metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle); | 
| 2547   Send(new ChildProcessMsg_SetHistogramMemory( | 2581   Send(new ChildProcessMsg_SetHistogramMemory( | 
| 2548       shm_handle, metrics_allocator_->shared_memory()->mapped_size())); | 2582       shm_handle, metrics_allocator_->shared_memory()->mapped_size())); | 
| 2549 } | 2583 } | 
| 2550 | 2584 | 
|  | 2585 void RenderProcessHostImpl::OnRouteProviderRequest( | 
|  | 2586     mojom::RouteProviderAssociatedRequest request) { | 
|  | 2587   if (route_provider_binding_.is_bound()) | 
|  | 2588     return; | 
|  | 2589   route_provider_binding_.Bind(std::move(request)); | 
|  | 2590 } | 
|  | 2591 | 
| 2551 void RenderProcessHostImpl::ProcessDied(bool already_dead, | 2592 void RenderProcessHostImpl::ProcessDied(bool already_dead, | 
| 2552                                         RendererClosedDetails* known_details) { | 2593                                         RendererClosedDetails* known_details) { | 
| 2553   // Our child process has died.  If we didn't expect it, it's a crash. | 2594   // Our child process has died.  If we didn't expect it, it's a crash. | 
| 2554   // In any case, we need to let everyone know it's gone. | 2595   // In any case, we need to let everyone know it's gone. | 
| 2555   // The OnChannelError notification can fire multiple times due to nested sync | 2596   // The OnChannelError notification can fire multiple times due to nested sync | 
| 2556   // calls to a renderer. If we don't have a valid channel here it means we | 2597   // calls to a renderer. If we don't have a valid channel here it means we | 
| 2557   // already handled the error. | 2598   // already handled the error. | 
| 2558 | 2599 | 
| 2559   // It should not be possible for us to be called re-entrantly. | 2600   // It should not be possible for us to be called re-entrantly. | 
| 2560   DCHECK(!within_process_died_observer_); | 2601   DCHECK(!within_process_died_observer_); | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 2585   } | 2626   } | 
| 2586 | 2627 | 
| 2587   RendererClosedDetails details(status, exit_code); | 2628   RendererClosedDetails details(status, exit_code); | 
| 2588 | 2629 | 
| 2589   child_process_launcher_.reset(); | 2630   child_process_launcher_.reset(); | 
| 2590 #if USE_ATTACHMENT_BROKER | 2631 #if USE_ATTACHMENT_BROKER | 
| 2591   IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 2632   IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 
| 2592       channel_.get()); | 2633       channel_.get()); | 
| 2593 #endif | 2634 #endif | 
| 2594   channel_.reset(); | 2635   channel_.reset(); | 
| 2595   while (!queued_messages_.empty()) { | 2636   queued_messages_ = MessageQueue{}; | 
| 2596     delete queued_messages_.front(); | 2637 | 
| 2597     queued_messages_.pop(); |  | 
| 2598   } |  | 
| 2599   UpdateProcessPriority(); | 2638   UpdateProcessPriority(); | 
| 2600   DCHECK(!is_process_backgrounded_); | 2639   DCHECK(!is_process_backgrounded_); | 
| 2601 | 2640 | 
| 2602   // RenderProcessExited observers and RenderProcessGone handlers might | 2641   // RenderProcessExited observers and RenderProcessGone handlers might | 
| 2603   // navigate or perform other actions that require a connection. Ensure that | 2642   // navigate or perform other actions that require a connection. Ensure that | 
| 2604   // there is one before calling them. | 2643   // there is one before calling them. | 
| 2605   child_token_ = mojo::edk::GenerateRandomToken(); | 2644   child_token_ = mojo::edk::GenerateRandomToken(); | 
| 2606   shell::Connector* connector = | 2645   shell::Connector* connector = | 
| 2607       BrowserContext::GetShellConnectorFor(browser_context_); | 2646       BrowserContext::GetShellConnectorFor(browser_context_); | 
| 2608   if (!connector) | 2647   if (!connector) | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2739   // especially don't want to send the RENDERER_PROCESS_CREATED notification, | 2778   // especially don't want to send the RENDERER_PROCESS_CREATED notification, | 
| 2740   // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to | 2779   // since some clients might expect a RENDERER_PROCESS_TERMINATED afterwards to | 
| 2741   // properly cleanup. | 2780   // properly cleanup. | 
| 2742   if (deleting_soon_) | 2781   if (deleting_soon_) | 
| 2743     return; | 2782     return; | 
| 2744 | 2783 | 
| 2745   if (child_process_launcher_) { | 2784   if (child_process_launcher_) { | 
| 2746     DCHECK(child_process_launcher_->GetProcess().IsValid()); | 2785     DCHECK(child_process_launcher_->GetProcess().IsValid()); | 
| 2747     DCHECK(!is_process_backgrounded_); | 2786     DCHECK(!is_process_backgrounded_); | 
| 2748 | 2787 | 
|  | 2788     // Unpause the channel now that the process is launched. We don't flush it | 
|  | 2789     // yet to ensure that any initialization messages sent here (e.g., things | 
|  | 2790     // done in response to NOTIFICATION_RENDER_PROCESS_CREATED; see below) | 
|  | 2791     // preempt already queued messages. | 
|  | 2792     channel_->Unpause(false /* flush */); | 
|  | 2793 | 
| 2749     if (mojo_child_connection_) { | 2794     if (mojo_child_connection_) { | 
| 2750       mojo_child_connection_->SetProcessHandle( | 2795       mojo_child_connection_->SetProcessHandle( | 
| 2751           child_process_launcher_->GetProcess().Handle()); | 2796           child_process_launcher_->GetProcess().Handle()); | 
| 2752     } | 2797     } | 
| 2753 | 2798 | 
| 2754     // Not all platforms launch processes in the same backgrounded state. Make | 2799     // Not all platforms launch processes in the same backgrounded state. Make | 
| 2755     // sure |is_process_backgrounded_| reflects this platform's initial process | 2800     // sure |is_process_backgrounded_| reflects this platform's initial process | 
| 2756     // state. | 2801     // state. | 
| 2757     is_process_backgrounded_ = | 2802     is_process_backgrounded_ = | 
| 2758         child_process_launcher_->GetProcess().IsProcessBackgrounded(); | 2803         child_process_launcher_->GetProcess().IsProcessBackgrounded(); | 
| 2759 | 2804 | 
| 2760     // Disable updating process priority on startup for now as it incorrectly | 2805     // Disable updating process priority on startup for now as it incorrectly | 
| 2761     // results in backgrounding foreground navigations until their first commit | 2806     // results in backgrounding foreground navigations until their first commit | 
| 2762     // is made. A better long term solution would be to be aware of the tab's | 2807     // is made. A better long term solution would be to be aware of the tab's | 
| 2763     // visibility at this point. https://crbug.com/560446. | 2808     // visibility at this point. https://crbug.com/560446. | 
| 2764     // Except on Android for now because of https://crbug.com/601184 :-(. | 2809     // Except on Android for now because of https://crbug.com/601184 :-(. | 
| 2765 #if defined(OS_ANDROID) | 2810 #if defined(OS_ANDROID) | 
| 2766     UpdateProcessPriority(); | 2811     UpdateProcessPriority(); | 
| 2767 #endif | 2812 #endif | 
| 2768 | 2813 | 
| 2769     // Share histograms between the renderer and this process. | 2814     // Share histograms between the renderer and this process. | 
| 2770     CreateSharedRendererHistogramAllocator(); | 2815     CreateSharedRendererHistogramAllocator(); | 
| 2771   } | 2816   } | 
| 2772 | 2817 | 
| 2773   // NOTE: This needs to be before sending queued messages because | 2818   // NOTE: This needs to be before flushing queued messages, because | 
| 2774   // ExtensionService uses this notification to initialize the renderer process | 2819   // ExtensionService uses this notification to initialize the renderer process | 
| 2775   // with state that must be there before any JavaScript executes. | 2820   // with state that must be there before any JavaScript executes. | 
| 2776   // | 2821   // | 
| 2777   // The queued messages contain such things as "navigate". If this notification | 2822   // The queued messages contain such things as "navigate". If this notification | 
| 2778   // was after, we can end up executing JavaScript before the initialization | 2823   // was after, we can end up executing JavaScript before the initialization | 
| 2779   // happens. | 2824   // happens. | 
| 2780   NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2825   NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 
| 2781                                          Source<RenderProcessHost>(this), | 2826                                          Source<RenderProcessHost>(this), | 
| 2782                                          NotificationService::NoDetails()); | 2827                                          NotificationService::NoDetails()); | 
| 2783 | 2828 | 
| 2784   while (!queued_messages_.empty()) { | 2829   if (child_process_launcher_) | 
| 2785     Send(queued_messages_.front()); | 2830     channel_->Flush(); | 
| 2786     queued_messages_.pop(); |  | 
| 2787   } |  | 
| 2788 | 2831 | 
| 2789   if (IsReady()) { | 2832   if (IsReady()) { | 
| 2790     DCHECK(!sent_render_process_ready_); | 2833     DCHECK(!sent_render_process_ready_); | 
| 2791     sent_render_process_ready_ = true; | 2834     sent_render_process_ready_ = true; | 
| 2792     // Send RenderProcessReady only if the channel is already connected. | 2835     // Send RenderProcessReady only if the channel is already connected. | 
| 2793     FOR_EACH_OBSERVER(RenderProcessHostObserver, | 2836     FOR_EACH_OBSERVER(RenderProcessHostObserver, | 
| 2794                       observers_, | 2837                       observers_, | 
| 2795                       RenderProcessReady(this)); | 2838                       RenderProcessReady(this)); | 
| 2796   } | 2839   } | 
| 2797 | 2840 | 
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2940   LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2983   LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 
| 2941 | 2984 | 
| 2942   // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2985   // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 
| 2943   // enough information here so that we can determine what the bad message was. | 2986   // enough information here so that we can determine what the bad message was. | 
| 2944   base::debug::Alias(&error); | 2987   base::debug::Alias(&error); | 
| 2945   bad_message::ReceivedBadMessage(process.get(), | 2988   bad_message::ReceivedBadMessage(process.get(), | 
| 2946                                   bad_message::RPH_MOJO_PROCESS_ERROR); | 2989                                   bad_message::RPH_MOJO_PROCESS_ERROR); | 
| 2947 } | 2990 } | 
| 2948 | 2991 | 
| 2949 }  // namespace content | 2992 }  // namespace content | 
| OLD | NEW | 
|---|