@@ -675,6 +675,9 @@ RenderProcessHostImpl::RenderProcessHostImpl(
675
675
child_token_(mojo::edk::GenerateRandomToken()),
676
676
service_worker_ref_count_(0 ),
677
677
shared_worker_ref_count_(0 ),
678
+ route_provider_binding_(this ),
679
+ associated_interface_provider_bindings_(
680
+ mojo::BindingSetDispatchMode::WITH_CONTEXT),
678
681
visible_widgets_(0 ),
679
682
is_process_backgrounded_(false ),
680
683
is_initialized_(false ),
@@ -815,10 +818,7 @@ RenderProcessHostImpl::~RenderProcessHostImpl() {
815
818
#endif
816
819
// We may have some unsent messages at this point, but that's OK.
817
820
channel_.reset ();
818
- while (!queued_messages_.empty ()) {
819
- delete queued_messages_.front ();
820
- queued_messages_.pop ();
821
- }
821
+ queued_messages_ = MessageQueue{};
822
822
823
823
UnregisterHost (GetID ());
824
824
@@ -941,10 +941,19 @@ bool RenderProcessHostImpl::Init() {
941
941
base::Bind (&RenderProcessHostImpl::OnMojoError,
942
942
weak_factory_.GetWeakPtr (),
943
943
base::ThreadTaskRunnerHandle::Get ())));
944
+ channel_->Pause ();
944
945
945
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
957
if (!gpu_observer_registered_) {
949
958
gpu_observer_registered_ = true ;
950
959
ui::GpuSwitchingManager::GetInstance ()->AddObserver (this );
@@ -967,24 +976,23 @@ std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy(
967
976
IPC::ChannelMojo::CreateServerFactory (
968
977
bootstrap.PassInterface ().PassHandle (), runner);
969
978
979
+ std::unique_ptr<IPC::ChannelProxy> channel;
970
980
// Do NOT expand ifdef or run time condition checks here! Synchronous
971
981
// IPCs from browser process are banned. It is only narrowly allowed
972
982
// for Android WebView to maintain backward compatibility.
973
983
// See crbug.com/526842 for details.
974
984
#if defined(OS_ANDROID)
975
- if (GetContentClient ()->UsingSynchronousCompositing ()) {
976
- return IPC::SyncChannel::Create (
977
- std::move (channel_factory), this , runner.get (), true , &never_signaled_);
978
- }
985
+ if (GetContentClient ()->UsingSynchronousCompositing ())
986
+ channel = IPC::SyncChannel::Create (this , runner.get (), &never_signaled_);
979
987
#endif // OS_ANDROID
980
-
981
- std::unique_ptr<IPC::ChannelProxy> channel (
982
- new IPC::ChannelProxy (this , runner.get ()));
988
+ if (!channel)
989
+ channel.reset (new IPC::ChannelProxy (this , runner.get ()));
983
990
#if USE_ATTACHMENT_BROKER
984
991
IPC::AttachmentBroker::GetGlobal ()->RegisterCommunicationChannel (
985
992
channel.get (), runner);
986
993
#endif
987
- channel->Init (std::move (channel_factory), true );
994
+ channel->Init (std::move (channel_factory), true /* create_pipe_now */ );
995
+
988
996
return channel;
989
997
}
990
998
@@ -1186,6 +1194,10 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
1186
1194
interface_registry_android_.get ());
1187
1195
#endif
1188
1196
1197
+ channel_->AddAssociatedInterface (
1198
+ base::Bind (&RenderProcessHostImpl::OnRouteProviderRequest,
1199
+ base::Unretained (this )));
1200
+
1189
1201
#if !defined(OS_ANDROID)
1190
1202
AddUIThreadInterface (
1191
1203
registry.get (), base::Bind (&device::BatteryMonitorImpl::Create));
@@ -1261,6 +1273,25 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
1261
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
1295
void RenderProcessHostImpl::CreateStoragePartitionService (
1265
1296
mojo::InterfaceRequest<mojom::StoragePartitionService> request) {
1266
1297
// DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW!
@@ -1347,6 +1378,14 @@ void RenderProcessHostImpl::PurgeAndSuspend() {
1347
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
1389
void RenderProcessHostImpl::AddRoute (int32_t routing_id,
1351
1390
IPC::Listener* listener) {
1352
1391
CHECK (!listeners_.Lookup (routing_id)) << " Found Routing ID Conflict: "
@@ -1355,7 +1394,7 @@ void RenderProcessHostImpl::AddRoute(int32_t routing_id,
1355
1394
}
1356
1395
1357
1396
void RenderProcessHostImpl::RemoveRoute (int32_t routing_id) {
1358
- DCHECK (listeners_.Lookup (routing_id) != NULL );
1397
+ DCHECK (listeners_.Lookup (routing_id) != nullptr );
1359
1398
listeners_.Remove (routing_id);
1360
1399
Cleanup ();
1361
1400
}
@@ -1861,38 +1900,33 @@ bool RenderProcessHostImpl::FastShutdownIfPossible() {
1861
1900
1862
1901
bool RenderProcessHostImpl::Send (IPC::Message* msg) {
1863
1902
TRACE_EVENT0 (" renderer_host" , " RenderProcessHostImpl::Send" );
1903
+
1904
+ std::unique_ptr<IPC::Message> message (msg);
1905
+
1864
1906
#if !defined(OS_ANDROID)
1865
- DCHECK (!msg ->is_sync ());
1907
+ DCHECK (!message ->is_sync ());
1866
1908
#endif
1867
1909
1868
1910
if (!channel_) {
1869
1911
#if defined(OS_ANDROID)
1870
- if (msg->is_sync ()) {
1871
- delete msg;
1912
+ if (message->is_sync ())
1872
1913
return false ;
1873
- }
1874
1914
#endif
1875
1915
if (!is_initialized_) {
1876
- queued_messages_.push (msg );
1916
+ queued_messages_.emplace ( std::move (message) );
1877
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
1922
#if defined(OS_ANDROID)
1886
- if (msg->is_sync ()) {
1887
- delete msg;
1888
- return false ;
1889
- }
1890
- #endif
1891
- queued_messages_.push (msg);
1892
- return true ;
1923
+ if (child_process_launcher_.get () && child_process_launcher_->IsStarting () &&
1924
+ message->is_sync ()) {
1925
+ return false ;
1893
1926
}
1927
+ #endif
1894
1928
1895
- return channel_->Send (msg );
1929
+ return channel_->Send (message. release () );
1896
1930
}
1897
1931
1898
1932
bool RenderProcessHostImpl::OnMessageReceived (const IPC::Message& msg) {
@@ -2548,6 +2582,13 @@ void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() {
2548
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
2592
void RenderProcessHostImpl::ProcessDied (bool already_dead,
2552
2593
RendererClosedDetails* known_details) {
2553
2594
// Our child process has died. If we didn't expect it, it's a crash.
@@ -2592,10 +2633,8 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead,
2592
2633
channel_.get ());
2593
2634
#endif
2594
2635
channel_.reset ();
2595
- while (!queued_messages_.empty ()) {
2596
- delete queued_messages_.front ();
2597
- queued_messages_.pop ();
2598
- }
2636
+ queued_messages_ = MessageQueue{};
2637
+
2599
2638
UpdateProcessPriority ();
2600
2639
DCHECK (!is_process_backgrounded_);
2601
2640
@@ -2746,6 +2785,12 @@ void RenderProcessHostImpl::OnProcessLaunched() {
2746
2785
DCHECK (child_process_launcher_->GetProcess ().IsValid ());
2747
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
2794
if (mojo_child_connection_) {
2750
2795
mojo_child_connection_->SetProcessHandle (
2751
2796
child_process_launcher_->GetProcess ().Handle ());
@@ -2770,7 +2815,7 @@ void RenderProcessHostImpl::OnProcessLaunched() {
2770
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
2819
// ExtensionService uses this notification to initialize the renderer process
2775
2820
// with state that must be there before any JavaScript executes.
2776
2821
//
@@ -2781,10 +2826,8 @@ void RenderProcessHostImpl::OnProcessLaunched() {
2781
2826
Source<RenderProcessHost>(this ),
2782
2827
NotificationService::NoDetails ());
2783
2828
2784
- while (!queued_messages_.empty ()) {
2785
- Send (queued_messages_.front ());
2786
- queued_messages_.pop ();
2787
- }
2829
+ if (child_process_launcher_)
2830
+ channel_->Flush ();
2788
2831
2789
2832
if (IsReady ()) {
2790
2833
DCHECK (!sent_render_process_ready_);
0 commit comments