| 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 ServiceContext; | 15 class ServiceContext; |
| 16 struct ServiceInfo; | 16 struct BindSourceInfo; |
| 17 | 17 |
| 18 // The primary contract between a Service and the Service Manager, receiving | 18 // The primary contract between a Service and the Service Manager, receiving |
| 19 // lifecycle notifications and connection requests. | 19 // lifecycle notifications and connection requests. |
| 20 class Service { | 20 class Service { |
| 21 public: | 21 public: |
| 22 Service(); | 22 Service(); |
| 23 virtual ~Service(); | 23 virtual ~Service(); |
| 24 | 24 |
| 25 // Called exactly once when a bidirectional connection with the Service | 25 // Called exactly once when a bidirectional connection with the Service |
| 26 // Manager has been established. No calls to OnConnect() or OnBindInterface() | 26 // Manager has been established. No calls to OnConnect() or OnBindInterface() |
| 27 // will be made before this. | 27 // will be made before this. |
| 28 virtual void OnStart(); | 28 virtual void OnStart(); |
| 29 | 29 |
| 30 // Called when the service identified by |source_info| requests this service | 30 // Called when the service identified by |source.identity| requests this |
| 31 // bind a request for |interface_name|. If this method has been called, the | 31 // service bind a request for |interface_name|. If this method has been |
| 32 // service manager has already determined that policy permits this interface | 32 // called, the service manager has already determined that policy permits this |
| 33 // to be bound, so the implementation of this method can trust that it should | 33 // interface to be bound, so the implementation of this method can trust that |
| 34 // just blindly bind it under most conditions. | 34 // it should just blindly bind it under most conditions. |
| 35 virtual void OnBindInterface(const ServiceInfo& source_info, | 35 virtual void OnBindInterface(const BindSourceInfo& source, |
| 36 const std::string& interface_name, | 36 const std::string& interface_name, |
| 37 mojo::ScopedMessagePipeHandle interface_pipe); | 37 mojo::ScopedMessagePipeHandle interface_pipe); |
| 38 | 38 |
| 39 // Called when the Service Manager has stopped tracking this instance. The | 39 // Called when the Service Manager has stopped tracking this instance. The |
| 40 // service should use this as a signal to shut down, and in fact its process | 40 // service should use this as a signal to shut down, and in fact its process |
| 41 // may be reaped shortly afterward if applicable. | 41 // may be reaped shortly afterward if applicable. |
| 42 // | 42 // |
| 43 // If this returns |true| then QuitNow() will be invoked immediately upon | 43 // If this returns |true| then QuitNow() will be invoked immediately upon |
| 44 // return to the ServiceContext. Otherwise the Service is responsible for | 44 // return to the ServiceContext. Otherwise the Service is responsible for |
| 45 // eventually calling QuitNow(). | 45 // eventually calling QuitNow(). |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 // 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 |
| 72 // 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. |
| 73 class ForwardingService : public Service { | 73 class ForwardingService : public Service { |
| 74 public: | 74 public: |
| 75 // |target| must outlive this object. | 75 // |target| must outlive this object. |
| 76 explicit ForwardingService(Service* target); | 76 explicit ForwardingService(Service* target); |
| 77 ~ForwardingService() override; | 77 ~ForwardingService() override; |
| 78 | 78 |
| 79 // Service: | 79 // Service: |
| 80 void OnStart() override; | 80 void OnStart() override; |
| 81 void OnBindInterface(const ServiceInfo& remote_info, | 81 void OnBindInterface(const BindSourceInfo& source, |
| 82 const std::string& interface_name, | 82 const std::string& interface_name, |
| 83 mojo::ScopedMessagePipeHandle interface_pipe) override; | 83 mojo::ScopedMessagePipeHandle interface_pipe) override; |
| 84 bool OnServiceManagerConnectionLost() override; | 84 bool OnServiceManagerConnectionLost() override; |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 void SetContext(ServiceContext* context) override; | 87 void SetContext(ServiceContext* context) override; |
| 88 | 88 |
| 89 Service* const target_ = nullptr; | 89 Service* const target_ = nullptr; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(ForwardingService); | 91 DISALLOW_COPY_AND_ASSIGN(ForwardingService); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 } // namespace service_manager | 94 } // namespace service_manager |
| 95 | 95 |
| 96 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_H_ | 96 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_H_ |
| OLD | NEW |