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