OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ | 5 #ifndef REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ |
6 #define REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ | 6 #define REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... | |
29 | 29 |
30 // Class and package name of the Java class supporting the methods we call. | 30 // Class and package name of the Java class supporting the methods we call. |
31 const char* const JAVA_CLASS = "org/chromium/chromoting/jni/JNIInterface"; | 31 const char* const JAVA_CLASS = "org/chromium/chromoting/jni/JNIInterface"; |
32 | 32 |
33 // TODO(solb) Move into location shared with client plugin. | 33 // TODO(solb) Move into location shared with client plugin. |
34 const char* const CHAT_SERVER = "talk.google.com"; | 34 const char* const CHAT_SERVER = "talk.google.com"; |
35 const int CHAT_PORT = 5222; | 35 const int CHAT_PORT = 5222; |
36 const bool CHAT_USE_TLS = true; | 36 const bool CHAT_USE_TLS = true; |
37 const char* const CHAT_AUTH_METHOD = "oauth2"; | 37 const char* const CHAT_AUTH_METHOD = "oauth2"; |
38 | 38 |
39 // ClientUserInterface that makes and (indirectly) receives JNI calls. | 39 // ClientUserInterface that makes and (indirectly) receives JNI calls. It also |
40 // contains global resources on which the Chromoting components run | |
41 // (e.g. message loops and task runners). | |
40 class ChromotingJNIInstance : public ClientUserInterface { | 42 class ChromotingJNIInstance : public ClientUserInterface { |
41 public: | 43 public: |
44 // This class is instantiated at process initialization and persists until | |
45 // we close. It reuses many of its components between connections (i.e. when | |
46 // a DisconnectFromHost() call is followed by a ConnectToHost() one. | |
42 static ChromotingJNIInstance* GetInstance(); | 47 static ChromotingJNIInstance* GetInstance(); |
43 | 48 |
44 // Call from UI thread. | 49 // Initiates a connection with the specified host. This may only be called |
50 // when |connected_| is false, and must be invoked on the UI thread. | |
45 void ConnectToHost( | 51 void ConnectToHost( |
46 jstring username, | 52 const char* username, |
47 jstring auth_token, | 53 const char* auth_token, |
48 jstring host_jid, | 54 const char* host_jid, |
49 jstring host_id, | 55 const char* host_id, |
50 jstring host_pubkey); | 56 const char* host_pubkey); |
51 | 57 |
52 // Call from UI thread. | 58 // Terminates the current connection (if it hasn't already failed) and clean |
59 // up. This may only be called when |connected_|, and only from the UI thread. | |
53 void DisconnectFromHost(); | 60 void DisconnectFromHost(); |
54 | 61 |
55 // Call from UI thread. | 62 // Provides the user's PIN and resumes the host authentication attempt. Call |
56 void AuthenticateWithPin(jstring pin); | 63 // once the user has finished entering this PIN into the UI. |
64 void AuthenticateWithPin(const char* pin); | |
Wez
2013/07/12 20:13:41
IIUC correctly, this API should be called by Java
solb
2013/07/12 21:10:54
Done.
| |
57 | 65 |
58 // Called by client authenticator. | 66 // Notifies the user interface that the user needs to enter a PIN. The |
59 // Gets notified if the user needs to enter a PIN, and notifies Java in turn. | 67 // current authentication attempt is put on hold until |callback| is invoked. |
Wez
2013/07/12 20:13:41
When you say _is_ put on hold, do you mean _should
solb
2013/07/12 21:10:54
No; I mean that the Chromoting authentication code
| |
60 void FetchSecret(bool pairable, | 68 void FetchSecret(bool pairable, |
61 const protocol::SecretFetchedCallback& callback_encore); | 69 const protocol::SecretFetchedCallback& callback); |
Wez
2013/07/12 20:13:41
This method seems to be an internal implementation
solb
2013/07/12 21:10:54
Done.
| |
62 | 70 |
63 // ClientUserInterface implementation: | 71 // ClientUserInterface implementation. |
64 virtual void OnConnectionState( | 72 virtual void OnConnectionState( |
65 protocol::ConnectionToHost::State state, | 73 protocol::ConnectionToHost::State state, |
66 protocol::ErrorCode error) OVERRIDE; | 74 protocol::ErrorCode error) OVERRIDE; |
67 virtual void OnConnectionReady(bool ready) OVERRIDE; | 75 virtual void OnConnectionReady(bool ready) OVERRIDE; |
68 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; | 76 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; |
69 virtual void SetPairingResponse( | 77 virtual void SetPairingResponse( |
70 const protocol::PairingResponse& response) OVERRIDE; | 78 const protocol::PairingResponse& response) OVERRIDE; |
71 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; | 79 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; |
72 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; | 80 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; |
73 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | 81 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
74 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; | 82 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; |
75 | 83 |
76 private: | 84 private: |
77 ChromotingJNIInstance(); | 85 ChromotingJNIInstance(); |
86 | |
87 // Any existing or attempted connection must have been terminated using | |
88 // DisconnectFromHost() before this singleton is destroyed. Because | |
89 // destruction only occurs at application exit after all connections have | |
90 // terminated, it is safe to make unretained cross-thread calls on the class. | |
78 virtual ~ChromotingJNIInstance(); | 91 virtual ~ChromotingJNIInstance(); |
79 | 92 |
80 void ConnectToHostOnDisplayThread(); | 93 void ConnectToHostOnDisplayThread(); |
81 void ConnectToHostOnNetworkThread(); | 94 void ConnectToHostOnNetworkThread(); |
82 | 95 |
83 void DisconnectFromHostOnNetworkThread(); | 96 void DisconnectFromHostOnNetworkThread(); |
84 | 97 |
85 // Reusable between sessions: | 98 // The below variables are reused across consecutive sessions. |
86 jclass class_; // Reference to the Java class into which we make JNI calls. | 99 |
100 // Reference to the Java class into which we make JNI calls. | |
101 jclass class_; | |
102 | |
103 // Used by the Chromium libraries to clean up the base and net libraries' JNI | |
104 // bindings. It must persist for the lifetime of the singleton. | |
87 scoped_ptr<base::AtExitManager> collector_; | 105 scoped_ptr<base::AtExitManager> collector_; |
106 | |
107 // Chromium code's connection to the Java message loop. | |
88 scoped_ptr<base::MessageLoopForUI> ui_loop_; | 108 scoped_ptr<base::MessageLoopForUI> ui_loop_; |
89 scoped_refptr<AutoThreadTaskRunner> ui_runner_; | 109 |
90 scoped_refptr<AutoThreadTaskRunner> net_runner_; | 110 // Runners that allow posting tasks to the various native threads. |
91 scoped_refptr<AutoThreadTaskRunner> disp_runner_; | 111 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
112 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
113 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; | |
114 | |
92 scoped_refptr<net::URLRequestContextGetter> url_requester_; | 115 scoped_refptr<net::URLRequestContextGetter> url_requester_; |
93 scoped_refptr<FrameConsumerProxy> frames_; | 116 scoped_refptr<FrameConsumerProxy> frame_consumer_; |
94 | 117 |
95 // Specific to each session: | 118 // The below variables are specific to each connection. |
119 | |
120 // True iff ConnectToHost() has been called without a subsequent | |
121 // call to DisconnectFromHost() (i.e. while connecting, once connected, and | |
122 // between the time a connection fails and DisconnectFromHost() is called). | |
123 bool connected_; | |
Wez
2013/07/12 20:13:41
For this and the rest of the members below, you sh
solb
2013/07/12 21:10:54
Done.
| |
124 | |
96 scoped_ptr<ClientConfig> client_config_; | 125 scoped_ptr<ClientConfig> client_config_; |
97 scoped_ptr<ClientContext> client_context_; | 126 scoped_ptr<ClientContext> client_context_; |
98 scoped_ptr<protocol::ConnectionToHost> connection_; | 127 scoped_ptr<protocol::ConnectionToHost> connection_; |
99 scoped_ptr<ChromotingClient> client_; | 128 scoped_ptr<ChromotingClient> client_; |
100 scoped_ptr<XmppSignalStrategy::XmppServerConfig> chat_config_; | 129 scoped_ptr<XmppSignalStrategy::XmppServerConfig> signaling_config_; |
101 scoped_ptr<XmppSignalStrategy> chat_; // must outlive client_ | 130 scoped_ptr<XmppSignalStrategy> signaling_; // must outlive client_ |
102 scoped_ptr<NetworkSettings> netset_; | 131 scoped_ptr<NetworkSettings> network_settings_; |
103 protocol::SecretFetchedCallback announce_secret_; | 132 protocol::SecretFetchedCallback pin_callback_; |
104 | 133 |
105 // Java string handles: | 134 // These strings describe the current connection, and are not reused. |
106 jstring username_jstr_; | 135 std::string username_; |
107 jstring auth_token_jstr_; | 136 std::string auth_token_; |
108 jstring host_jid_jstr_; | 137 std::string host_jid_; |
109 jstring host_id_jstr_; | 138 std::string host_id_; |
110 jstring host_pubkey_jstr_; | 139 std::string host_pubkey_; |
111 jstring pin_jstr_; | 140 std::string pin_; |
112 | |
113 // C string pointers: | |
114 const char* username_cstr_; | |
115 const char* auth_token_cstr_; | |
116 const char* host_jid_cstr_; | |
117 const char* host_id_cstr_; | |
118 const char* host_pubkey_cstr_; | |
119 const char* pin_cstr_; | |
120 | 141 |
121 friend struct DefaultSingletonTraits<ChromotingJNIInstance>; | 142 friend struct DefaultSingletonTraits<ChromotingJNIInstance>; |
122 | 143 |
123 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance); | 144 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance); |
124 }; | 145 }; |
125 | 146 |
126 } // namespace remoting | 147 } // namespace remoting |
127 | 148 |
128 #endif | 149 #endif |
OLD | NEW |