| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "mojo/public/cpp/system/message_pipe.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" |
| 12 | 12 |
| 13 namespace service_manager { | 13 namespace service_manager { |
| 14 | 14 |
| 15 class InterfaceRegistry; | |
| 16 class ServiceContext; | 15 class ServiceContext; |
| 17 struct ServiceInfo; | 16 struct ServiceInfo; |
| 18 | 17 |
| 19 // The primary contract between a Service and the Service Manager, receiving | 18 // The primary contract between a Service and the Service Manager, receiving |
| 20 // lifecycle notifications and connection requests. | 19 // lifecycle notifications and connection requests. |
| 21 class Service { | 20 class Service { |
| 22 public: | 21 public: |
| 23 Service(); | 22 Service(); |
| 24 virtual ~Service(); | 23 virtual ~Service(); |
| 25 | 24 |
| 26 // Called exactly once when a bidirectional connection with the Service | 25 // Called exactly once when a bidirectional connection with the Service |
| 27 // Manager has been established. No calls to OnConnect() or OnBindInterface() | 26 // Manager has been established. No calls to OnConnect() or OnBindInterface() |
| 28 // will be made before this. | 27 // will be made before this. |
| 29 virtual void OnStart(); | 28 virtual void OnStart(); |
| 30 | 29 |
| 31 // Called each time a connection to this service is brokered by the Service | |
| 32 // Manager. Implement this to expose interfaces to other services. | |
| 33 // | |
| 34 // Return true if the connection should succeed or false if the connection | |
| 35 // should be rejected. | |
| 36 // | |
| 37 // The default implementation returns false. | |
| 38 virtual bool OnConnect(const ServiceInfo& remote_info, | |
| 39 InterfaceRegistry* registry); | |
| 40 | |
| 41 // Called when the service identified by |source_info| requests this service | 30 // Called when the service identified by |source_info| requests this service |
| 42 // bind a request for |interface_name|. If this method has been called, the | 31 // bind a request for |interface_name|. If this method has been called, the |
| 43 // service manager has already determined that policy permits this interface | 32 // service manager has already determined that policy permits this interface |
| 44 // to be bound, so the implementation of this method can trust that it should | 33 // to be bound, so the implementation of this method can trust that it should |
| 45 // just blindly bind it under most conditions. | 34 // just blindly bind it under most conditions. |
| 46 virtual void OnBindInterface(const ServiceInfo& source_info, | 35 virtual void OnBindInterface(const ServiceInfo& source_info, |
| 47 const std::string& interface_name, | 36 const std::string& interface_name, |
| 48 mojo::ScopedMessagePipeHandle interface_pipe); | 37 mojo::ScopedMessagePipeHandle interface_pipe); |
| 49 | 38 |
| 50 // Called when the Service Manager has stopped tracking this instance. The | 39 // Called when the Service Manager has stopped tracking this instance. The |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // TODO(rockot): Remove this. It's here to satisfy a few remaining use cases | 71 // TODO(rockot): Remove this. It's here to satisfy a few remaining use cases |
| 83 // where a Service impl is owned by something other than its ServiceContext. | 72 // where a Service impl is owned by something other than its ServiceContext. |
| 84 class ForwardingService : public Service { | 73 class ForwardingService : public Service { |
| 85 public: | 74 public: |
| 86 // |target| must outlive this object. | 75 // |target| must outlive this object. |
| 87 explicit ForwardingService(Service* target); | 76 explicit ForwardingService(Service* target); |
| 88 ~ForwardingService() override; | 77 ~ForwardingService() override; |
| 89 | 78 |
| 90 // Service: | 79 // Service: |
| 91 void OnStart() override; | 80 void OnStart() override; |
| 92 bool OnConnect(const ServiceInfo& remote_info, | |
| 93 InterfaceRegistry* registry) override; | |
| 94 void OnBindInterface(const ServiceInfo& remote_info, | 81 void OnBindInterface(const ServiceInfo& remote_info, |
| 95 const std::string& interface_name, | 82 const std::string& interface_name, |
| 96 mojo::ScopedMessagePipeHandle interface_pipe) override; | 83 mojo::ScopedMessagePipeHandle interface_pipe) override; |
| 97 bool OnServiceManagerConnectionLost() override; | 84 bool OnServiceManagerConnectionLost() override; |
| 98 | 85 |
| 99 private: | 86 private: |
| 100 void SetContext(ServiceContext* context) override; | 87 void SetContext(ServiceContext* context) override; |
| 101 | 88 |
| 102 Service* const target_ = nullptr; | 89 Service* const target_ = nullptr; |
| 103 | 90 |
| 104 DISALLOW_COPY_AND_ASSIGN(ForwardingService); | 91 DISALLOW_COPY_AND_ASSIGN(ForwardingService); |
| 105 }; | 92 }; |
| 106 | 93 |
| 107 } // namespace service_manager | 94 } // namespace service_manager |
| 108 | 95 |
| 109 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_H_ | 96 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_H_ |
| OLD | NEW |