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

Unified Diff: services/service_manager/service_manager.cc

Issue 2476063002: Service Manager: Rework Service and ServiceContext lifetime (Closed)
Patch Set: . Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: services/service_manager/service_manager.cc
diff --git a/services/service_manager/service_manager.cc b/services/service_manager/service_manager.cc
index fa8101b7a603a50678a73498aa3da28e7e430156..cf7885640b29c737956c34133a516480f590eecb 100644
--- a/services/service_manager/service_manager.cc
+++ b/services/service_manager/service_manager.cc
@@ -23,7 +23,9 @@
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/connect_util.h"
#include "services/service_manager/public/cpp/connector.h"
+#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/names.h"
+#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/interfaces/connector.mojom.h"
#include "services/service_manager/public/interfaces/service.mojom.h"
@@ -452,6 +454,37 @@ class ServiceManager::Instance
DISALLOW_COPY_AND_ASSIGN(Instance);
};
+class ServiceManager::ServiceImpl : public Service {
+ public:
+ explicit ServiceImpl(ServiceManager* service_manager)
+ : service_manager_(service_manager) {}
+ ~ServiceImpl() override {}
+
+ // Service:
+ bool OnConnect(const ServiceInfo& remote_info,
+ InterfaceRegistry* registry) override {
+ // The only interface ServiceManager exposes is mojom::ServiceManager, and
+ // access to this interface is brokered by a policy specific to each caller,
+ // managed by the caller's instance. Here we look to see who's calling,
+ // and forward to the caller's instance to continue.
+ Instance* instance = nullptr;
+ for (const auto& entry : service_manager_->identity_to_instance_) {
+ if (entry.first == remote_info.identity) {
+ instance = entry.second;
+ break;
+ }
+ }
+
+ DCHECK(instance);
+ return instance->OnConnect(remote_info, registry);
+ }
+
+ private:
+ ServiceManager* const service_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(ServiceImpl);
+};
+
// static
ServiceManager::TestAPI::TestAPI(ServiceManager* service_manager)
: service_manager_(service_manager) {}
@@ -490,7 +523,8 @@ ServiceManager::ServiceManager(
CreateInstance(Identity(), CreateServiceManagerIdentity(), specs);
service_manager_instance_->StartWithService(std::move(service));
singletons_.insert(kServiceManagerName);
- service_context_.reset(new ServiceContext(this, std::move(request)));
+ service_context_.reset(new ServiceContext(
+ base::MakeUnique<ServiceImpl>(this), std::move(request)));
if (catalog)
InitCatalog(std::move(catalog));
@@ -538,26 +572,6 @@ mojom::ServiceRequest ServiceManager::StartEmbedderService(
}
////////////////////////////////////////////////////////////////////////////////
-// ServiceManager, Service implementation:
-
-bool ServiceManager::OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) {
- // The only interface we expose is mojom::ServiceManager, and access to this
- // interface is brokered by a policy specific to each caller, managed by the
- // caller's instance. Here we look to see who's calling, and forward to the
- // caller's instance to continue.
- Instance* instance = nullptr;
- for (const auto& entry : identity_to_instance_) {
- if (entry.first == remote_info.identity) {
- instance = entry.second;
- break;
- }
- }
- DCHECK(instance);
- return instance->OnConnect(remote_info, registry);
-}
-
-////////////////////////////////////////////////////////////////////////////////
// ServiceManager, private:
void ServiceManager::InitCatalog(mojom::ServicePtr catalog) {
« no previous file with comments | « services/service_manager/service_manager.h ('k') | services/service_manager/tests/connect/connect_test_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698