Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: remoting/client/jni/chromoting_jni_instance.h

Issue 18612018: Restructure chromoting_jni_instance handling of Java strings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase atop trunk Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/client/jni/chromoting_jni_instance.h
diff --git a/remoting/client/jni/chromoting_jni_instance.h b/remoting/client/jni/chromoting_jni_instance.h
index 75ef56bd87f10c12073bd3a77202e69422bc9ef9..091a0c1f8d404428cddbb98078212b2813d7d29d 100644
--- a/remoting/client/jni/chromoting_jni_instance.h
+++ b/remoting/client/jni/chromoting_jni_instance.h
@@ -36,31 +36,39 @@ const int CHAT_PORT = 5222;
const bool CHAT_USE_TLS = true;
const char* const CHAT_AUTH_METHOD = "oauth2";
-// ClientUserInterface that makes and (indirectly) receives JNI calls.
+// ClientUserInterface that makes and (indirectly) receives JNI calls. It also
+// contains global resources on which the Chromoting components run
+// (e.g. message loops and task runners).
class ChromotingJNIInstance : public ClientUserInterface {
public:
+ // This class is instantiated at process initialization and persists until
+ // we close. It reuses many of its components between connections (i.e. when
+ // a DisconnectFromHost() call is followed by a ConnectToHost() one.
static ChromotingJNIInstance* GetInstance();
- // Call from UI thread.
+ // Initiates a connection with the specified host. This may only be called
+ // when |connected_| is false, and must be invoked on the UI thread.
void ConnectToHost(
- jstring username,
- jstring auth_token,
- jstring host_jid,
- jstring host_id,
- jstring host_pubkey);
-
- // Call from UI thread.
+ const char* username,
+ const char* auth_token,
+ const char* host_jid,
+ const char* host_id,
+ const char* host_pubkey);
+
+ // Terminates the current connection (if it hasn't already failed) and clean
+ // up. This may only be called when |connected_|, and only from the UI thread.
void DisconnectFromHost();
- // Call from UI thread.
- void AuthenticateWithPin(jstring pin);
+ // Provides the user's PIN and resumes the host authentication attempt. Call
+ // once the user has finished entering this PIN into the UI.
+ 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.
- // Called by client authenticator.
- // Gets notified if the user needs to enter a PIN, and notifies Java in turn.
+ // Notifies the user interface that the user needs to enter a PIN. The
+ // 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
void FetchSecret(bool pairable,
- const protocol::SecretFetchedCallback& callback_encore);
+ 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.
- // ClientUserInterface implementation:
+ // ClientUserInterface implementation.
virtual void OnConnectionState(
protocol::ConnectionToHost::State state,
protocol::ErrorCode error) OVERRIDE;
@@ -75,6 +83,11 @@ class ChromotingJNIInstance : public ClientUserInterface {
private:
ChromotingJNIInstance();
+
+ // Any existing or attempted connection must have been terminated using
+ // DisconnectFromHost() before this singleton is destroyed. Because
+ // destruction only occurs at application exit after all connections have
+ // terminated, it is safe to make unretained cross-thread calls on the class.
virtual ~ChromotingJNIInstance();
void ConnectToHostOnDisplayThread();
@@ -82,41 +95,49 @@ class ChromotingJNIInstance : public ClientUserInterface {
void DisconnectFromHostOnNetworkThread();
- // Reusable between sessions:
- jclass class_; // Reference to the Java class into which we make JNI calls.
+ // The below variables are reused across consecutive sessions.
+
+ // Reference to the Java class into which we make JNI calls.
+ jclass class_;
+
+ // Used by the Chromium libraries to clean up the base and net libraries' JNI
+ // bindings. It must persist for the lifetime of the singleton.
scoped_ptr<base::AtExitManager> collector_;
+
+ // Chromium code's connection to the Java message loop.
scoped_ptr<base::MessageLoopForUI> ui_loop_;
- scoped_refptr<AutoThreadTaskRunner> ui_runner_;
- scoped_refptr<AutoThreadTaskRunner> net_runner_;
- scoped_refptr<AutoThreadTaskRunner> disp_runner_;
+
+ // Runners that allow posting tasks to the various native threads.
+ scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
+ scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
+
scoped_refptr<net::URLRequestContextGetter> url_requester_;
- scoped_refptr<FrameConsumerProxy> frames_;
+ scoped_refptr<FrameConsumerProxy> frame_consumer_;
+
+ // The below variables are specific to each connection.
+
+ // True iff ConnectToHost() has been called without a subsequent
+ // call to DisconnectFromHost() (i.e. while connecting, once connected, and
+ // between the time a connection fails and DisconnectFromHost() is called).
+ 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.
- // Specific to each session:
scoped_ptr<ClientConfig> client_config_;
scoped_ptr<ClientContext> client_context_;
scoped_ptr<protocol::ConnectionToHost> connection_;
scoped_ptr<ChromotingClient> client_;
- scoped_ptr<XmppSignalStrategy::XmppServerConfig> chat_config_;
- scoped_ptr<XmppSignalStrategy> chat_; // must outlive client_
- scoped_ptr<NetworkSettings> netset_;
- protocol::SecretFetchedCallback announce_secret_;
-
- // Java string handles:
- jstring username_jstr_;
- jstring auth_token_jstr_;
- jstring host_jid_jstr_;
- jstring host_id_jstr_;
- jstring host_pubkey_jstr_;
- jstring pin_jstr_;
-
- // C string pointers:
- const char* username_cstr_;
- const char* auth_token_cstr_;
- const char* host_jid_cstr_;
- const char* host_id_cstr_;
- const char* host_pubkey_cstr_;
- const char* pin_cstr_;
+ scoped_ptr<XmppSignalStrategy::XmppServerConfig> signaling_config_;
+ scoped_ptr<XmppSignalStrategy> signaling_; // must outlive client_
+ scoped_ptr<NetworkSettings> network_settings_;
+ protocol::SecretFetchedCallback pin_callback_;
+
+ // These strings describe the current connection, and are not reused.
+ std::string username_;
+ std::string auth_token_;
+ std::string host_jid_;
+ std::string host_id_;
+ std::string host_pubkey_;
+ std::string pin_;
friend struct DefaultSingletonTraits<ChromotingJNIInstance>;
« no previous file with comments | « no previous file | remoting/client/jni/chromoting_jni_instance.cc » ('j') | remoting/client/jni/chromoting_jni_instance.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698