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

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

Issue 2420253002: Rename shell namespace to service_manager (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Represents the browser side of the browser <--> renderer communication 5 // Represents the browser side of the browser <--> renderer communication
6 // channel. There will be one RenderProcessHost per renderer process. 6 // channel. There will be one RenderProcessHost per renderer process.
7 7
8 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 511
512 base::Lock lock_; 512 base::Lock lock_;
513 ConnectionFilterImpl* filter_; 513 ConnectionFilterImpl* filter_;
514 }; 514 };
515 515
516 // Held by the RPH's BrowserContext's ServiceManagerConnection, ownership 516 // Held by the RPH's BrowserContext's ServiceManagerConnection, ownership
517 // transferred back to RPH upon RPH destruction. 517 // transferred back to RPH upon RPH destruction.
518 class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter { 518 class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {
519 public: 519 public:
520 ConnectionFilterImpl( 520 ConnectionFilterImpl(
521 const shell::Identity& child_identity, 521 const service_manager::Identity& child_identity,
522 std::unique_ptr<shell::InterfaceRegistry> registry) 522 std::unique_ptr<service_manager::InterfaceRegistry> registry)
523 : child_identity_(child_identity), 523 : child_identity_(child_identity),
524 registry_(std::move(registry)), 524 registry_(std::move(registry)),
525 controller_(new ConnectionFilterController(this)), 525 controller_(new ConnectionFilterController(this)),
526 weak_factory_(this) { 526 weak_factory_(this) {
527 // Registration of this filter may race with browser shutdown, in which case 527 // Registration of this filter may race with browser shutdown, in which case
528 // it's possible for this filter to be destroyed on the main thread. This 528 // it's possible for this filter to be destroyed on the main thread. This
529 // is fine as long as the filter hasn't been used on the IO thread yet. We 529 // is fine as long as the filter hasn't been used on the IO thread yet. We
530 // detach the ThreadChecker initially and the first use of the filter will 530 // detach the ThreadChecker initially and the first use of the filter will
531 // bind it. 531 // bind it.
532 thread_checker_.DetachFromThread(); 532 thread_checker_.DetachFromThread();
533 } 533 }
534 534
535 ~ConnectionFilterImpl() override { 535 ~ConnectionFilterImpl() override {
536 DCHECK(thread_checker_.CalledOnValidThread()); 536 DCHECK(thread_checker_.CalledOnValidThread());
537 controller_->Detach(); 537 controller_->Detach();
538 } 538 }
539 539
540 scoped_refptr<ConnectionFilterController> controller() { return controller_; } 540 scoped_refptr<ConnectionFilterController> controller() { return controller_; }
541 541
542 void Disable() { 542 void Disable() {
543 base::AutoLock lock(enabled_lock_); 543 base::AutoLock lock(enabled_lock_);
544 enabled_ = false; 544 enabled_ = false;
545 } 545 }
546 546
547 private: 547 private:
548 // ConnectionFilter: 548 // ConnectionFilter:
549 bool OnConnect(const shell::Identity& remote_identity, 549 bool OnConnect(const service_manager::Identity& remote_identity,
550 shell::InterfaceRegistry* registry, 550 service_manager::InterfaceRegistry* registry,
551 shell::Connector* connector) override { 551 service_manager::Connector* connector) override {
552 DCHECK(thread_checker_.CalledOnValidThread()); 552 DCHECK(thread_checker_.CalledOnValidThread());
553 DCHECK_CURRENTLY_ON(BrowserThread::IO); 553 DCHECK_CURRENTLY_ON(BrowserThread::IO);
554 // We only fulfill connections from the renderer we host. 554 // We only fulfill connections from the renderer we host.
555 if (child_identity_.name() != remote_identity.name() || 555 if (child_identity_.name() != remote_identity.name() ||
556 child_identity_.instance() != remote_identity.instance()) { 556 child_identity_.instance() != remote_identity.instance()) {
557 return false; 557 return false;
558 } 558 }
559 559
560 base::AutoLock lock(enabled_lock_); 560 base::AutoLock lock(enabled_lock_);
561 if (!enabled_) 561 if (!enabled_)
562 return false; 562 return false;
563 563
564 std::set<std::string> interface_names; 564 std::set<std::string> interface_names;
565 registry_->GetInterfaceNames(&interface_names); 565 registry_->GetInterfaceNames(&interface_names);
566 for (auto& interface_name : interface_names) { 566 for (auto& interface_name : interface_names) {
567 // Note that the added callbacks may outlive this object, which is 567 // Note that the added callbacks may outlive this object, which is
568 // destroyed in RPH::Cleanup(). 568 // destroyed in RPH::Cleanup().
569 registry->AddInterface(interface_name, 569 registry->AddInterface(interface_name,
570 base::Bind(&ConnectionFilterImpl::GetInterface, 570 base::Bind(&ConnectionFilterImpl::GetInterface,
571 weak_factory_.GetWeakPtr(), 571 weak_factory_.GetWeakPtr(),
572 interface_name)); 572 interface_name));
573 } 573 }
574 return true; 574 return true;
575 } 575 }
576 576
577 void GetInterface(const std::string& interface_name, 577 void GetInterface(const std::string& interface_name,
578 mojo::ScopedMessagePipeHandle handle) { 578 mojo::ScopedMessagePipeHandle handle) {
579 DCHECK(thread_checker_.CalledOnValidThread()); 579 DCHECK(thread_checker_.CalledOnValidThread());
580 DCHECK_CURRENTLY_ON(BrowserThread::IO); 580 DCHECK_CURRENTLY_ON(BrowserThread::IO);
581 shell::mojom::InterfaceProvider* provider = registry_.get(); 581 service_manager::mojom::InterfaceProvider* provider = registry_.get();
582 582
583 base::AutoLock lock(enabled_lock_); 583 base::AutoLock lock(enabled_lock_);
584 if (enabled_) 584 if (enabled_)
585 provider->GetInterface(interface_name, std::move(handle)); 585 provider->GetInterface(interface_name, std::move(handle));
586 } 586 }
587 587
588 base::ThreadChecker thread_checker_; 588 base::ThreadChecker thread_checker_;
589 shell::Identity child_identity_; 589 service_manager::Identity child_identity_;
590 std::unique_ptr<shell::InterfaceRegistry> registry_; 590 std::unique_ptr<service_manager::InterfaceRegistry> registry_;
591 scoped_refptr<ConnectionFilterController> controller_; 591 scoped_refptr<ConnectionFilterController> controller_;
592 592
593 // Guards |enabled_|. 593 // Guards |enabled_|.
594 base::Lock enabled_lock_; 594 base::Lock enabled_lock_;
595 bool enabled_ = true; 595 bool enabled_ = true;
596 596
597 base::WeakPtrFactory<ConnectionFilterImpl> weak_factory_; 597 base::WeakPtrFactory<ConnectionFilterImpl> weak_factory_;
598 598
599 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); 599 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl);
600 }; 600 };
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 946
947 void RenderProcessHostImpl::InitializeChannelProxy() { 947 void RenderProcessHostImpl::InitializeChannelProxy() {
948 // Generate a token used to identify the new child process. 948 // Generate a token used to identify the new child process.
949 child_token_ = mojo::edk::GenerateRandomToken(); 949 child_token_ = mojo::edk::GenerateRandomToken();
950 950
951 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = 951 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner =
952 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); 952 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
953 953
954 // Acquire a Connector which will route connections to a new instance of the 954 // Acquire a Connector which will route connections to a new instance of the
955 // renderer service. 955 // renderer service.
956 shell::Connector* connector = 956 service_manager::Connector* connector =
957 BrowserContext::GetConnectorFor(browser_context_); 957 BrowserContext::GetConnectorFor(browser_context_);
958 if (!connector) { 958 if (!connector) {
959 // Note that some embedders (e.g. Android WebView) may not initialize a 959 // Note that some embedders (e.g. Android WebView) may not initialize a
960 // Connector per BrowserContext. In those cases we fall back to the 960 // Connector per BrowserContext. In those cases we fall back to the
961 // browser-wide Connector. 961 // browser-wide Connector.
962 if (!ServiceManagerConnection::GetForProcess()) { 962 if (!ServiceManagerConnection::GetForProcess()) {
963 // Additionally, some test code may not initialize the process-wide 963 // Additionally, some test code may not initialize the process-wide
964 // ServiceManagerConnection prior to this point. This class of test code 964 // ServiceManagerConnection prior to this point. This class of test code
965 // doesn't care about render processes, so we can initialize a dummy 965 // doesn't care about render processes, so we can initialize a dummy
966 // connection. 966 // connection.
967 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); 967 service_manager::mojom::ServiceRequest request =
968 mojo::GetProxy(&test_service_);
968 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( 969 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create(
969 std::move(request), io_task_runner)); 970 std::move(request), io_task_runner));
970 } 971 }
971 connector = ServiceManagerConnection::GetForProcess()->GetConnector(); 972 connector = ServiceManagerConnection::GetForProcess()->GetConnector();
972 } 973 }
973 974
974 // Establish a ServiceManager connection for the new render service instance. 975 // Establish a ServiceManager connection for the new render service instance.
975 child_connection_.reset(new ChildConnection( 976 child_connection_.reset(new ChildConnection(
976 kRendererServiceName, 977 kRendererServiceName,
977 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, 978 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector,
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 AddFilter(new HistogramMessageFilter()); 1219 AddFilter(new HistogramMessageFilter());
1219 AddFilter(new MemoryMessageFilter(this)); 1220 AddFilter(new MemoryMessageFilter(this));
1220 AddFilter(new PushMessagingMessageFilter( 1221 AddFilter(new PushMessagingMessageFilter(
1221 GetID(), storage_partition_impl_->GetServiceWorkerContext())); 1222 GetID(), storage_partition_impl_->GetServiceWorkerContext()));
1222 #if defined(OS_ANDROID) 1223 #if defined(OS_ANDROID)
1223 AddFilter(new ScreenOrientationMessageFilterAndroid()); 1224 AddFilter(new ScreenOrientationMessageFilterAndroid());
1224 #endif 1225 #endif
1225 } 1226 }
1226 1227
1227 void RenderProcessHostImpl::RegisterMojoInterfaces() { 1228 void RenderProcessHostImpl::RegisterMojoInterfaces() {
1228 std::unique_ptr<shell::InterfaceRegistry> registry( 1229 std::unique_ptr<service_manager::InterfaceRegistry> registry(
1229 new shell::InterfaceRegistry); 1230 new service_manager::InterfaceRegistry);
1230 1231
1231 channel_->AddAssociatedInterface( 1232 channel_->AddAssociatedInterface(
1232 base::Bind(&RenderProcessHostImpl::OnRouteProviderRequest, 1233 base::Bind(&RenderProcessHostImpl::OnRouteProviderRequest,
1233 base::Unretained(this))); 1234 base::Unretained(this)));
1234 1235
1235 #if defined(OS_ANDROID) 1236 #if defined(OS_ANDROID)
1236 AddUIThreadInterface(registry.get(), 1237 AddUIThreadInterface(registry.get(),
1237 GetGlobalJavaInterfaces() 1238 GetGlobalJavaInterfaces()
1238 ->CreateInterfaceFactory<device::BatteryMonitor>()); 1239 ->CreateInterfaceFactory<device::BatteryMonitor>());
1239 #else 1240 #else
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 1353
1353 int RenderProcessHostImpl::GetNextRoutingID() { 1354 int RenderProcessHostImpl::GetNextRoutingID() {
1354 return widget_helper_->GetNextRoutingID(); 1355 return widget_helper_->GetNextRoutingID();
1355 } 1356 }
1356 1357
1357 void RenderProcessHostImpl::ResumeDeferredNavigation( 1358 void RenderProcessHostImpl::ResumeDeferredNavigation(
1358 const GlobalRequestID& request_id) { 1359 const GlobalRequestID& request_id) {
1359 widget_helper_->ResumeDeferredNavigation(request_id); 1360 widget_helper_->ResumeDeferredNavigation(request_id);
1360 } 1361 }
1361 1362
1362 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { 1363 service_manager::InterfaceProvider*
1364 RenderProcessHostImpl::GetRemoteInterfaces() {
1363 return child_connection_->GetRemoteInterfaces(); 1365 return child_connection_->GetRemoteInterfaces();
1364 } 1366 }
1365 1367
1366 std::unique_ptr<base::SharedPersistentMemoryAllocator> 1368 std::unique_ptr<base::SharedPersistentMemoryAllocator>
1367 RenderProcessHostImpl::TakeMetricsAllocator() { 1369 RenderProcessHostImpl::TakeMetricsAllocator() {
1368 return std::move(metrics_allocator_); 1370 return std::move(metrics_allocator_);
1369 } 1371 }
1370 1372
1371 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() 1373 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics()
1372 const { 1374 const {
(...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 3036 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
3035 3037
3036 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 3038 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
3037 // enough information here so that we can determine what the bad message was. 3039 // enough information here so that we can determine what the bad message was.
3038 base::debug::Alias(&error); 3040 base::debug::Alias(&error);
3039 bad_message::ReceivedBadMessage(render_process_id, 3041 bad_message::ReceivedBadMessage(render_process_id,
3040 bad_message::RPH_MOJO_PROCESS_ERROR); 3042 bad_message::RPH_MOJO_PROCESS_ERROR);
3041 } 3043 }
3042 3044
3043 } // namespace content 3045 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/browser/service_manager/service_manager_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698