OLD | NEW |
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_SHELL_PUBLIC_CPP_SERVICE_H_ | 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ |
6 #define SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ | 6 #define SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "services/shell/public/cpp/connection.h" | 12 #include "services/shell/public/cpp/interface_registry.h" |
13 #include "services/shell/public/cpp/identity.h" | |
14 | 13 |
15 namespace shell { | 14 namespace shell { |
16 | 15 |
17 class Connector; | 16 class Connector; |
| 17 class Identity; |
| 18 class InterfaceRegistry; |
18 class ServiceContext; | 19 class ServiceContext; |
19 | 20 |
20 // The primary contract between a Service and the Service Manager, receiving | 21 // The primary contract between a Service and the Service Manager, receiving |
21 // lifecycle notifications and connection requests. | 22 // lifecycle notifications and connection requests. |
22 class Service { | 23 class Service { |
23 public: | 24 public: |
24 Service(); | 25 Service(); |
25 virtual ~Service(); | 26 virtual ~Service(); |
26 | 27 |
27 // Called once a bidirectional connection with the Service Manager has been | 28 // Called once a bidirectional connection with the Service Manager has been |
28 // established. | 29 // established. |
29 // |identity| is the identity of the service instance. | 30 // |identity| is the identity of the service instance. |
30 // Called exactly once before any other method. | 31 // Called exactly once before any other method. |
31 virtual void OnStart(const Identity& identity); | 32 virtual void OnStart(const Identity& identity); |
32 | 33 |
33 // Called when a connection to this service is brokered by the Service | 34 // Called when a connection to this service is brokered by the Service |
34 // Manager. Override to expose interfaces to the remote service. Return true | 35 // Manager. Override to expose interfaces to the remote service. Return true |
35 // if the connection should succeed. Return false if the connection should | 36 // if the connection should succeed. Return false if the connection should |
36 // be rejected and the underlying pipe closed. The default implementation | 37 // be rejected and the underlying pipe closed. The default implementation |
37 // returns false. | 38 // returns false. |
38 virtual bool OnConnect(Connection* connection); | 39 virtual bool OnConnect(const Identity& remote_identity, |
| 40 InterfaceRegistry* registry); |
39 | 41 |
40 // Called when the Service Manager has stopped tracking this instance. The | 42 // Called when the Service Manager has stopped tracking this instance. The |
41 // service should use this as a signal to exit, and in fact its process may | 43 // service should use this as a signal to exit, and in fact its process may |
42 // be reaped shortly afterward. | 44 // be reaped shortly afterward. |
43 // Return true from this method to tell the ServiceContext to run its | 45 // Return true from this method to tell the ServiceContext to run its |
44 // connection lost closure if it has one, false to prevent it from being run. | 46 // connection lost closure if it has one, false to prevent it from being run. |
45 // The default implementation returns true. | 47 // The default implementation returns true. |
46 // When used in conjunction with ApplicationRunner, returning true here quits | 48 // When used in conjunction with ApplicationRunner, returning true here quits |
47 // the message loop created by ApplicationRunner, which results in the service | 49 // the message loop created by ApplicationRunner, which results in the service |
48 // quitting. | 50 // quitting. |
49 virtual bool OnStop(); | 51 virtual bool OnStop(); |
50 | 52 |
51 // TODO(rockot): remove | |
52 virtual InterfaceProvider* GetInterfaceProviderForConnection(); | |
53 virtual InterfaceRegistry* GetInterfaceRegistryForConnection(); | |
54 | |
55 Connector* connector(); | 53 Connector* connector(); |
56 ServiceContext* context(); | 54 ServiceContext* context(); |
57 void set_context(std::unique_ptr<ServiceContext> context); | 55 void set_context(std::unique_ptr<ServiceContext> context); |
58 | 56 |
59 private: | 57 private: |
60 std::unique_ptr<ServiceContext> context_; | 58 std::unique_ptr<ServiceContext> context_; |
61 | 59 |
62 DISALLOW_COPY_AND_ASSIGN(Service); | 60 DISALLOW_COPY_AND_ASSIGN(Service); |
63 }; | 61 }; |
64 | 62 |
65 } // namespace shell | 63 } // namespace shell |
66 | 64 |
67 #endif // SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ | 65 #endif // SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ |
OLD | NEW |