| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // The primary contract between a Service and the Service Manager, receiving | 21 // The primary contract between a Service and the Service Manager, receiving |
| 22 // lifecycle notifications and connection requests. | 22 // lifecycle notifications and connection requests. |
| 23 class Service { | 23 class Service { |
| 24 public: | 24 public: |
| 25 Service(); | 25 Service(); |
| 26 virtual ~Service(); | 26 virtual ~Service(); |
| 27 | 27 |
| 28 // Called once a bidirectional connection with the Service Manager has been | 28 // Called once a bidirectional connection with the Service Manager has been |
| 29 // established. | 29 // established. |
| 30 // |identity| is the identity of the service instance. | 30 // |identity| is the identity of the service instance. |
| 31 // Called exactly once before any other method. | 31 // Called exactly once before any calls to OnConnect(). |
| 32 virtual void OnStart(const Identity& identity); | 32 virtual void OnStart(const Identity& identity); |
| 33 | 33 |
| 34 // 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 |
| 35 // Manager. Override to expose interfaces to the remote service. Return true | 35 // Manager. Override to expose interfaces to the remote service. Return true |
| 36 // if the connection should succeed. Return false if the connection should | 36 // if the connection should succeed. Return false if the connection should |
| 37 // be rejected and the underlying pipe closed. The default implementation | 37 // be rejected and the underlying pipe closed. The default implementation |
| 38 // returns false. | 38 // returns false. |
| 39 virtual bool OnConnect(const Identity& remote_identity, | 39 virtual bool OnConnect(const Identity& remote_identity, |
| 40 InterfaceRegistry* registry); | 40 InterfaceRegistry* registry); |
| 41 | 41 |
| 42 // Called when the Service Manager has stopped tracking this instance. The | 42 // Called when the Service Manager has stopped tracking this instance. The |
| 43 // 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 |
| 44 // be reaped shortly afterward. | 44 // be reaped shortly afterward. |
| 45 // 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 |
| 46 // 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. |
| 47 // The default implementation returns true. | 47 // The default implementation returns true. |
| 48 // When used in conjunction with ApplicationRunner, returning true here quits | 48 // When used in conjunction with ApplicationRunner, returning true here quits |
| 49 // the message loop created by ApplicationRunner, which results in the service | 49 // the message loop created by ApplicationRunner, which results in the service |
| 50 // quitting. | 50 // quitting. |
| 51 // No calls to either OnStart() nor OnConnect() may be received after this is |
| 52 // called. It is however possible for this to be called without OnStart() ever |
| 53 // having been called. |
| 51 virtual bool OnStop(); | 54 virtual bool OnStop(); |
| 52 | 55 |
| 53 Connector* connector(); | 56 Connector* connector(); |
| 54 ServiceContext* context(); | 57 ServiceContext* context(); |
| 55 void set_context(std::unique_ptr<ServiceContext> context); | 58 void set_context(std::unique_ptr<ServiceContext> context); |
| 56 | 59 |
| 57 private: | 60 private: |
| 58 std::unique_ptr<ServiceContext> context_; | 61 std::unique_ptr<ServiceContext> context_; |
| 59 | 62 |
| 60 DISALLOW_COPY_AND_ASSIGN(Service); | 63 DISALLOW_COPY_AND_ASSIGN(Service); |
| 61 }; | 64 }; |
| 62 | 65 |
| 63 } // namespace shell | 66 } // namespace shell |
| 64 | 67 |
| 65 #endif // SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ | 68 #endif // SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ |
| OLD | NEW |