Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 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. |
| 40 // It also keeps the references to various Chromium components (e.g. message | |
| 41 // loops and task runners) that must outlive any use of the network stack. | |
|
Wez
2013/07/11 22:32:08
Why is the ClientUserInterface maintaining message
solb
2013/07/11 23:59:09
Done.
| |
| 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. | |
|
Wez
2013/07/11 22:32:08
See style guide re comment style: e.g. Returns the
solb
2013/07/11 23:59:09
This will be addressed in a separate CL that separ
Wez
2013/07/12 00:24:48
OK, but please address the comment style issue.
| |
| 42 static ChromotingJNIInstance* GetInstance(); | 47 static ChromotingJNIInstance* GetInstance(); |
| 43 | 48 |
| 44 // Call from UI thread. | |
| 45 void ConnectToHost( | 49 void ConnectToHost( |
|
Wez
2013/07/11 22:32:08
Add comments to explain the semantics of these thr
solb
2013/07/11 23:59:09
Done.
Wez
2013/07/12 00:24:48
Chromium comments on methods are things like:
"Sta
| |
| 46 jstring username, | 50 const char* username, |
| 47 jstring auth_token, | 51 const char* auth_token, |
| 48 jstring host_jid, | 52 const char* host_jid, |
| 49 jstring host_id, | 53 const char* host_id, |
| 50 jstring host_pubkey); | 54 const char* host_pubkey); |
| 51 | 55 |
| 52 // Call from UI thread. | |
| 53 void DisconnectFromHost(); | 56 void DisconnectFromHost(); |
| 54 | 57 |
| 55 // Call from UI thread. | 58 void AuthenticateWithPin(const char* pin); |
| 56 void AuthenticateWithPin(jstring pin); | |
| 57 | 59 |
| 58 // Called by client authenticator. | 60 // Called by client authenticator. |
| 59 // Gets notified if the user needs to enter a PIN, and notifies Java in turn. | 61 // Gets notified if the user needs to enter a PIN, and notifies Java in turn. |
|
Wez
2013/07/11 22:32:08
Suggest: Calls to Java to prompt the user for an a
solb
2013/07/11 23:59:09
Done.
| |
| 60 void FetchSecret(bool pairable, | 62 void FetchSecret(bool pairable, |
| 61 const protocol::SecretFetchedCallback& callback_encore); | 63 const protocol::SecretFetchedCallback& callback); |
| 62 | 64 |
| 63 // ClientUserInterface implementation: | 65 // ClientUserInterface implementation. |
| 64 virtual void OnConnectionState( | 66 virtual void OnConnectionState( |
| 65 protocol::ConnectionToHost::State state, | 67 protocol::ConnectionToHost::State state, |
| 66 protocol::ErrorCode error) OVERRIDE; | 68 protocol::ErrorCode error) OVERRIDE; |
| 67 virtual void OnConnectionReady(bool ready) OVERRIDE; | 69 virtual void OnConnectionReady(bool ready) OVERRIDE; |
| 68 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; | 70 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; |
| 69 virtual void SetPairingResponse( | 71 virtual void SetPairingResponse( |
| 70 const protocol::PairingResponse& response) OVERRIDE; | 72 const protocol::PairingResponse& response) OVERRIDE; |
| 71 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; | 73 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; |
| 72 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; | 74 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; |
| 73 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | 75 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
| 74 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; | 76 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 ChromotingJNIInstance(); | 79 ChromotingJNIInstance(); |
| 78 virtual ~ChromotingJNIInstance(); | 80 virtual ~ChromotingJNIInstance(); |
| 79 | 81 |
| 80 void ConnectToHostOnDisplayThread(); | 82 void ConnectToHostOnDisplayThread(); |
| 81 void ConnectToHostOnNetworkThread(); | 83 void ConnectToHostOnNetworkThread(); |
| 82 | 84 |
| 83 void DisconnectFromHostOnNetworkThread(); | 85 // The below variables are reused across consecutive sessions. |
| 84 | 86 |
| 85 // Reusable between sessions: | 87 // Reference to the Java class into which we make JNI calls. |
| 86 jclass class_; // Reference to the Java class into which we make JNI calls. | 88 jclass class_; |
| 89 | |
| 87 scoped_ptr<base::AtExitManager> collector_; | 90 scoped_ptr<base::AtExitManager> collector_; |
|
Wez
2013/07/11 22:32:08
nit: Add a comment to explain this.
Does it reall
solb
2013/07/11 23:59:09
Done. It's a scoped_ptr to avoid keeping a bare po
Wez
2013/07/12 00:24:48
Why is it not just a member, since it has the same
| |
| 91 | |
| 92 // Chromium code's connection to the Java message loop. | |
| 88 scoped_ptr<base::MessageLoopForUI> ui_loop_; | 93 scoped_ptr<base::MessageLoopForUI> ui_loop_; |
| 89 scoped_refptr<AutoThreadTaskRunner> ui_runner_; | 94 |
| 90 scoped_refptr<AutoThreadTaskRunner> net_runner_; | 95 // Runners that allow posting tasks to the various native threads. |
| 91 scoped_refptr<AutoThreadTaskRunner> disp_runner_; | 96 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
| 97 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
| 98 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; | |
| 99 | |
| 92 scoped_refptr<net::URLRequestContextGetter> url_requester_; | 100 scoped_refptr<net::URLRequestContextGetter> url_requester_; |
| 93 scoped_refptr<FrameConsumerProxy> frames_; | 101 scoped_refptr<FrameConsumerProxy> frames_; |
|
Wez
2013/07/11 22:32:08
frame_consumer_
solb
2013/07/11 23:59:09
Done.
| |
| 94 | 102 |
| 95 // Specific to each session: | 103 // The below variables are specific to each connection. |
|
Wez
2013/07/11 22:32:08
Why are per-session variables mixed in with global
solb
2013/07/11 23:59:09
This is for that other CL I referenced above.
| |
| 96 scoped_ptr<ClientConfig> client_config_; | 104 scoped_ptr<ClientConfig> client_config_; |
| 97 scoped_ptr<ClientContext> client_context_; | 105 scoped_ptr<ClientContext> client_context_; |
| 98 scoped_ptr<protocol::ConnectionToHost> connection_; | 106 scoped_ptr<protocol::ConnectionToHost> connection_; |
| 99 scoped_ptr<ChromotingClient> client_; | 107 scoped_ptr<ChromotingClient> client_; |
| 100 scoped_ptr<XmppSignalStrategy::XmppServerConfig> chat_config_; | 108 scoped_ptr<XmppSignalStrategy::XmppServerConfig> chat_config_; |
|
Wez
2013/07/11 22:32:08
chat_config_ -> signalling_config_
solb
2013/07/11 23:59:09
Done.
| |
| 101 scoped_ptr<XmppSignalStrategy> chat_; // must outlive client_ | 109 scoped_ptr<XmppSignalStrategy> chat_; // must outlive client_ |
|
Wez
2013/07/11 22:32:08
chat_ -> signalling_
Wez
2013/07/11 22:32:08
If this must out-live |client_| then why does it a
solb
2013/07/11 23:59:09
Done.
solb
2013/07/11 23:59:09
It's actually manually reset in DisconnectFromHost
| |
| 102 scoped_ptr<NetworkSettings> netset_; | 110 scoped_ptr<NetworkSettings> netset_; |
|
Wez
2013/07/11 22:32:08
network_settings_
solb
2013/07/11 23:59:09
Done.
| |
| 103 protocol::SecretFetchedCallback announce_secret_; | 111 protocol::SecretFetchedCallback announce_secret_; |
|
Wez
2013/07/11 22:32:08
Why is this called |announce_secret_|?
solb
2013/07/11 23:59:09
Done.
| |
| 104 | 112 |
| 105 // Java string handles: | 113 // These strings describe the current connection, and are not reused. |
| 106 jstring username_jstr_; | 114 std::string username_; |
| 107 jstring auth_token_jstr_; | 115 std::string auth_token_; |
| 108 jstring host_jid_jstr_; | 116 std::string host_jid_; |
| 109 jstring host_id_jstr_; | 117 std::string host_id_; |
| 110 jstring host_pubkey_jstr_; | 118 std::string host_pubkey_; |
| 111 jstring pin_jstr_; | 119 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 | 120 |
| 121 friend struct DefaultSingletonTraits<ChromotingJNIInstance>; | 121 friend struct DefaultSingletonTraits<ChromotingJNIInstance>; |
| 122 | 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance); | 123 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 } // namespace remoting | 126 } // namespace remoting |
| 127 | 127 |
| 128 #endif | 128 #endif |
| OLD | NEW |