Index: services/shell/public/cpp/service.h |
diff --git a/services/shell/public/cpp/service.h b/services/shell/public/cpp/service.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4e015e4510504a1dd2060a3618d135d71c517c7d |
--- /dev/null |
+++ b/services/shell/public/cpp/service.h |
@@ -0,0 +1,64 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ |
+#define SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ |
+ |
+#include <stdint.h> |
+#include <string> |
+ |
+#include "base/macros.h" |
+#include "services/shell/public/cpp/connection.h" |
+#include "services/shell/public/cpp/identity.h" |
+ |
+namespace shell { |
+ |
+class Connector; |
+ |
+// The primary contract between a Service and the Service Manager, receiving |
+// lifecycle notifications and connection requests. |
+class Service { |
+ public: |
+ Service(); |
+ virtual ~Service(); |
+ |
+ // Called once a bidirectional connection with the Service Manager has been |
+ // established. |
+ // |identity| is the identity of the service instance. |
+ // |id| is a unique identifier the Service Manager uses to identify this |
+ // specific instance of the service. |
+ // Called exactly once before any other method. |
+ virtual void OnStart(Connector* connector, |
+ const Identity& identity, |
+ uint32_t id); |
+ |
+ // Called when a connection to this service is brokered by the Service |
+ // Manager. Override to expose interfaces to the remote service. Return true |
+ // if the connection should succeed. Return false if the connection should |
+ // be rejected and the underlying pipe closed. The default implementation |
+ // returns false. |
+ virtual bool OnConnect(Connection* connection); |
+ |
+ // Called when the Service Manager has stopped tracking this instance. The |
+ // service should use this as a signal to exit, and in fact its process may |
+ // be reaped shortly afterward. |
+ // Return true from this method to tell the ShellConnection to run its |
+ // connection lost closure if it has one, false to prevent it from being run. |
+ // The default implementation returns true. |
+ // When used in conjunction with ApplicationRunner, returning true here quits |
+ // the message loop created by ApplicationRunner, which results in the service |
+ // quitting. |
+ virtual bool OnStop(); |
+ |
+ // TODO(rockot): remove |
+ virtual InterfaceProvider* GetInterfaceProviderForConnection(); |
+ virtual InterfaceRegistry* GetInterfaceRegistryForConnection(); |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(Service); |
+}; |
+ |
+} // namespace shell |
+ |
+#endif // SERVICES_SHELL_PUBLIC_CPP_SERVICE_H_ |