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