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 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 | 15 |
16 class Shell; | 16 class Connector; |
17 | 17 |
18 // An interface representing an instance "known to the Mojo Shell". The | 18 // An interface representing an instance "known to the Mojo Shell". The |
19 // implementation receives lifecycle messages for the instance and gets the | 19 // implementation receives lifecycle messages for the instance and gets the |
20 // opportunity to handle inbound connections brokered by the Shell. Every client | 20 // opportunity to handle inbound connections brokered by the Shell. Every client |
21 // of ShellConnection must implement this interface, and instances of this | 21 // of ShellConnection must implement this interface, and instances of this |
22 // interface must outlive the ShellConnection. | 22 // interface must outlive the ShellConnection. |
23 class ShellClient { | 23 class ShellClient { |
24 public: | 24 public: |
25 ShellClient(); | 25 ShellClient(); |
26 virtual ~ShellClient(); | 26 virtual ~ShellClient(); |
27 | 27 |
28 // Called once a bidirectional connection with the shell has been established. | 28 // Called once a bidirectional connection with the shell has been established. |
29 // |url| is the URL used to start the application. | 29 // |url| is the URL used to start the application. |
30 // |id| is a unique identifier the shell uses to identify this specific | 30 // |id| is a unique identifier the shell uses to identify this specific |
31 // instance of the application. | 31 // instance of the application. |
32 // |user_id| identifies the user this instance is run as. | 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(Shell* shell, | 34 virtual void Initialize(Connector* connector, |
35 const std::string& url, | 35 const std::string& url, |
36 uint32_t id, | 36 uint32_t id, |
37 uint32_t user_id = 0); | 37 uint32_t user_id = 0); |
38 | 38 |
39 // Called when a connection to this client is brokered by the shell. Override | 39 // 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 | 40 // 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 | 41 // should succeed. Return false if the connection should be rejected and the |
42 // underlying pipe closed. The default implementation returns false. | 42 // underlying pipe closed. The default implementation returns false. |
43 virtual bool AcceptConnection(Connection* connection); | 43 virtual bool AcceptConnection(Connection* connection); |
44 | 44 |
45 // Called when ShellConnection's pipe to the Mojo Shell is closed. | 45 // Called when ShellConnection's pipe to the Mojo Shell is closed. |
46 // | 46 // |
47 // Returning true from this method will cause the ShellConnection instance to | 47 // Returning true from this method will cause ... |
48 // call this instance back via Quit(), and then run the termination closure | |
49 // passed to it (which may do cleanup like, for example, quitting a run loop). | |
50 // Returning false from this method will not do any of this. The client is | |
51 // then responsible for calling Shell::QuitNow() when it is ready to close. | |
52 // The client may do this if it wishes to continue servicing connections other | |
53 // than the Shell. | |
54 // The default implementation returns true. | 48 // The default implementation returns true. |
55 virtual bool ShellConnectionLost(); | 49 virtual bool ShellConnectionLost(); |
56 | 50 |
57 // Called before ShellConnection::QuitNow(). After returning from this call | |
58 // the delegate can no longer rely on the main run loop still running. | |
59 virtual void Quit(); | |
60 | |
61 private: | 51 private: |
62 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellClient); | 52 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellClient); |
63 }; | 53 }; |
64 | 54 |
65 } // namespace mojo | 55 } // namespace mojo |
66 | 56 |
67 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_ | 57 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_ |
OLD | NEW |