| 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 MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_ |
| 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "mojo/public/cpp/system/macros.h" | 11 #include "mojo/public/cpp/system/macros.h" |
| 12 #include "mojo/shell/public/cpp/connection.h" | 12 #include "mojo/shell/public/cpp/connection.h" |
| 13 #include "mojo/shell/public/cpp/identity.h" |
| 13 | 14 |
| 14 namespace mojo { | 15 namespace mojo { |
| 15 | 16 |
| 16 class Connector; | 17 class Connector; |
| 17 | 18 |
| 18 // An interface representing an instance "known to the Mojo Shell". The | 19 // An interface representing an instance "known to the Mojo Shell". The |
| 19 // implementation receives lifecycle messages for the instance and gets the | 20 // implementation receives lifecycle messages for the instance and gets the |
| 20 // opportunity to handle inbound connections brokered by the Shell. Every client | 21 // opportunity to handle inbound connections brokered by the Shell. Every client |
| 21 // of ShellConnection must implement this interface, and instances of this | 22 // of ShellConnection must implement this interface, and instances of this |
| 22 // interface must outlive the ShellConnection. | 23 // interface must outlive the ShellConnection. |
| 23 class ShellClient { | 24 class ShellClient { |
| 24 public: | 25 public: |
| 25 ShellClient(); | 26 ShellClient(); |
| 26 virtual ~ShellClient(); | 27 virtual ~ShellClient(); |
| 27 | 28 |
| 28 // Called once a bidirectional connection with the shell has been established. | 29 // Called once a bidirectional connection with the shell has been established. |
| 29 // |name| is the name used to start the application. | 30 // |identity| is the identity of the instance. |
| 30 // |id| is a unique identifier the shell uses to identify this specific | 31 // |id| is a unique identifier the shell uses to identify this specific |
| 31 // instance of the application. | 32 // instance of the application. |
| 32 // |user_id| identifies the user this instance is run as. | |
| 33 // Called exactly once before any other method. | 33 // Called exactly once before any other method. |
| 34 virtual void Initialize(Connector* connector, | 34 virtual void Initialize(Connector* connector, |
| 35 const std::string& name, | 35 const Identity& identity, |
| 36 const std::string& user_id, | |
| 37 uint32_t id); | 36 uint32_t id); |
| 38 | 37 |
| 39 // Called when a connection to this client is brokered by the shell. Override | 38 // Called when a connection to this client is brokered by the shell. Override |
| 40 // to expose services to the remote application. Return true if the connection | 39 // to expose services to the remote application. Return true if the connection |
| 41 // should succeed. Return false if the connection should be rejected and the | 40 // should succeed. Return false if the connection should be rejected and the |
| 42 // underlying pipe closed. The default implementation returns false. | 41 // underlying pipe closed. The default implementation returns false. |
| 43 virtual bool AcceptConnection(Connection* connection); | 42 virtual bool AcceptConnection(Connection* connection); |
| 44 | 43 |
| 45 // Called when ShellConnection's ShellClient binding (i.e. the pipe the | 44 // Called when ShellConnection's ShellClient binding (i.e. the pipe the |
| 46 // Mojo Shell has to talk to us over) is closed. A shell client may use this | 45 // Mojo Shell has to talk to us over) is closed. A shell client may use this |
| 47 // as a signal to terminate. | 46 // as a signal to terminate. |
| 48 virtual void ShellConnectionLost(); | 47 virtual void ShellConnectionLost(); |
| 49 | 48 |
| 50 private: | 49 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(ShellClient); | 50 DISALLOW_COPY_AND_ASSIGN(ShellClient); |
| 52 }; | 51 }; |
| 53 | 52 |
| 54 } // namespace mojo | 53 } // namespace mojo |
| 55 | 54 |
| 56 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_ | 55 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_ |
| OLD | NEW |