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

Side by Side Diff: services/service_manager/service_manager.h

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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef SERVICES_SERVICE_MANAGER_SERVICE_MANAGER_H_ 5 #ifndef SERVICES_SERVICE_MANAGER_SERVICE_MANAGER_H_
6 #define SERVICES_SERVICE_MANAGER_SERVICE_MANAGER_H_ 6 #define SERVICES_SERVICE_MANAGER_SERVICE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "mojo/public/cpp/bindings/binding_set.h" 14 #include "mojo/public/cpp/bindings/binding_set.h"
15 #include "mojo/public/cpp/bindings/interface_ptr_set.h" 15 #include "mojo/public/cpp/bindings/interface_ptr_set.h"
16 #include "services/service_manager/connect_params.h" 16 #include "services/service_manager/connect_params.h"
17 #include "services/service_manager/native_runner.h" 17 #include "services/service_manager/native_runner.h"
18 #include "services/service_manager/public/cpp/identity.h" 18 #include "services/service_manager/public/cpp/identity.h"
19 #include "services/service_manager/public/cpp/interface_factory.h" 19 #include "services/service_manager/public/cpp/interface_factory.h"
20 #include "services/service_manager/public/cpp/interface_provider_spec.h" 20 #include "services/service_manager/public/cpp/interface_provider_spec.h"
21 #include "services/service_manager/public/cpp/service.h"
22 #include "services/service_manager/public/interfaces/connector.mojom.h" 21 #include "services/service_manager/public/interfaces/connector.mojom.h"
23 #include "services/service_manager/public/interfaces/interface_provider.mojom.h" 22 #include "services/service_manager/public/interfaces/interface_provider.mojom.h"
24 #include "services/service_manager/public/interfaces/resolver.mojom.h" 23 #include "services/service_manager/public/interfaces/resolver.mojom.h"
25 #include "services/service_manager/public/interfaces/service.mojom.h" 24 #include "services/service_manager/public/interfaces/service.mojom.h"
26 #include "services/service_manager/public/interfaces/service_factory.mojom.h" 25 #include "services/service_manager/public/interfaces/service_factory.mojom.h"
27 #include "services/service_manager/public/interfaces/service_manager.mojom.h" 26 #include "services/service_manager/public/interfaces/service_manager.mojom.h"
28 #include "services/service_manager/service_overrides.h" 27 #include "services/service_manager/service_overrides.h"
29 28
30 namespace service_manager { 29 namespace service_manager {
30
31 class ServiceContext; 31 class ServiceContext;
32 32
33 // Creates an identity for the Service Manager, used when the Service Manager 33 // Creates an identity for the Service Manager, used when the Service Manager
34 // connects to services. 34 // connects to services.
35 Identity CreateServiceManagerIdentity(); 35 Identity CreateServiceManagerIdentity();
36 36
37 class ServiceManager : public Service { 37 class ServiceManager {
38 public: 38 public:
39 // API for testing. 39 // API for testing.
40 class TestAPI { 40 class TestAPI {
41 public: 41 public:
42 explicit TestAPI(ServiceManager* service_manager); 42 explicit TestAPI(ServiceManager* service_manager);
43 ~TestAPI(); 43 ~TestAPI();
44 44
45 // Returns true if there is a Instance for this name. 45 // Returns true if there is a Instance for this name.
46 bool HasRunningInstanceForName(const std::string& name) const; 46 bool HasRunningInstanceForName(const std::string& name) const;
47 private: 47 private:
48 ServiceManager* service_manager_; 48 ServiceManager* service_manager_;
49 49
50 DISALLOW_COPY_AND_ASSIGN(TestAPI); 50 DISALLOW_COPY_AND_ASSIGN(TestAPI);
51 }; 51 };
52 52
53 // |native_runner_factory| is an instance of an object capable of vending 53 // |native_runner_factory| is an instance of an object capable of vending
54 // implementations of NativeRunner, e.g. for in or out-of-process execution. 54 // implementations of NativeRunner, e.g. for in or out-of-process execution.
55 // See native_runner.h and RunNativeApplication(). 55 // See native_runner.h and RunNativeApplication().
56 // |file_task_runner| provides access to a thread to perform file copy 56 // |file_task_runner| provides access to a thread to perform file copy
57 // operations on. 57 // operations on.
58 ServiceManager(std::unique_ptr<NativeRunnerFactory> native_runner_factory, 58 ServiceManager(std::unique_ptr<NativeRunnerFactory> native_runner_factory,
59 mojom::ServicePtr catalog); 59 mojom::ServicePtr catalog);
60 ~ServiceManager() override; 60 ~ServiceManager();
61 61
62 // Sets overrides for service executable and package resolution. Must be 62 // Sets overrides for service executable and package resolution. Must be
63 // called before any services are launched. 63 // called before any services are launched.
64 void SetServiceOverrides(std::unique_ptr<ServiceOverrides> overrides); 64 void SetServiceOverrides(std::unique_ptr<ServiceOverrides> overrides);
65 65
66 // Provide a callback to be notified whenever an instance is destroyed. 66 // Provide a callback to be notified whenever an instance is destroyed.
67 // Typically the creator of the Service Manager will use this to determine 67 // Typically the creator of the Service Manager will use this to determine
68 // when some set of services it created are destroyed, so it can shut down. 68 // when some set of services it created are destroyed, so it can shut down.
69 void SetInstanceQuitCallback(base::Callback<void(const Identity&)> callback); 69 void SetInstanceQuitCallback(base::Callback<void(const Identity&)> callback);
70 70
71 // Completes a connection between a source and target application as defined 71 // Completes a connection between a source and target application as defined
72 // by |params|, exchanging InterfaceProviders between them. If no existing 72 // by |params|, exchanging InterfaceProviders between them. If no existing
73 // instance of the target application is running, one will be loaded. 73 // instance of the target application is running, one will be loaded.
74 void Connect(std::unique_ptr<ConnectParams> params); 74 void Connect(std::unique_ptr<ConnectParams> params);
75 75
76 // Creates a new Instance identified as |name|. This is intended for use by 76 // Creates a new Instance identified as |name|. This is intended for use by
77 // the Service Manager's embedder to register itself. This must only be called 77 // the Service Manager's embedder to register itself. This must only be called
78 // once. 78 // once.
79 mojom::ServiceRequest StartEmbedderService(const std::string& name); 79 mojom::ServiceRequest StartEmbedderService(const std::string& name);
80 80
81 private: 81 private:
82 class Instance; 82 class Instance;
83 83 class ServiceImpl;
84 // Service:
85 bool OnConnect(const ServiceInfo& remote_info,
86 InterfaceRegistry* registry) override;
87 84
88 void InitCatalog(mojom::ServicePtr catalog); 85 void InitCatalog(mojom::ServicePtr catalog);
89 86
90 // Returns the resolver to use for the specified identity. 87 // Returns the resolver to use for the specified identity.
91 // NOTE: Resolvers are cached to ensure we service requests in order. If 88 // NOTE: Resolvers are cached to ensure we service requests in order. If
92 // we use a separate Resolver for each request ordering is not 89 // we use a separate Resolver for each request ordering is not
93 // guaranteed and can lead to random flake. 90 // guaranteed and can lead to random flake.
94 mojom::Resolver* GetResolver(const Identity& identity); 91 mojom::Resolver* GetResolver(const Identity& identity);
95 92
96 // Called when |instance| encounters an error. Deletes |instance|. 93 // Called when |instance| encounters an error. Deletes |instance|.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 base::WeakPtrFactory<ServiceManager> weak_ptr_factory_; 184 base::WeakPtrFactory<ServiceManager> weak_ptr_factory_;
188 185
189 DISALLOW_COPY_AND_ASSIGN(ServiceManager); 186 DISALLOW_COPY_AND_ASSIGN(ServiceManager);
190 }; 187 };
191 188
192 mojom::Connector::ConnectCallback EmptyConnectCallback(); 189 mojom::Connector::ConnectCallback EmptyConnectCallback();
193 190
194 } // namespace service_manager 191 } // namespace service_manager
195 192
196 #endif // SERVICES_SERVICE_MANAGER_SERVICE_MANAGER_H_ 193 #endif // SERVICES_SERVICE_MANAGER_SERVICE_MANAGER_H_
OLDNEW
« no previous file with comments | « services/service_manager/runner/child/test_native_main.cc ('k') | services/service_manager/service_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698