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

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: Connection/disconnection state machine and moar comments 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..5c34a53fb782602ba30edbac61039d5bd62ba613 100644
--- a/remoting/client/jni/chromoting_jni_instance.h
+++ b/remoting/client/jni/chromoting_jni_instance.h
@@ -37,30 +37,33 @@ const bool CHAT_USE_TLS = true;
const char* const CHAT_AUTH_METHOD = "oauth2";
// ClientUserInterface that makes and (indirectly) receives JNI calls.
+// It also keeps the references to various Chromium components (e.g. message
+// loops and task runners) that must outlive any use of the rest of Chromoting.
Wez 2013/07/12 00:24:48 This still doesn't explain why; IIUC this object s
solb 2013/07/12 01:14:22 Right.
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.
+ // Should only be called while disconnected.
void ConnectToHost(
- jstring username,
- jstring auth_token,
- jstring host_jid,
- jstring host_id,
- jstring host_pubkey);
+ const char* username,
+ const char* auth_token,
+ const char* host_jid,
+ const char* host_id,
+ const char* host_pubkey);
- // Call from UI thread.
+ // Must only be called during a successful or failed connection.
Wez 2013/07/12 00:24:48 See above.
solb 2013/07/12 01:14:22 As covered in another comment, it's not racy becau
void DisconnectFromHost();
- // Call from UI thread.
- void AuthenticateWithPin(jstring pin);
+ void AuthenticateWithPin(const char* pin);
Wez 2013/07/12 00:24:48 Comment to explain this, please!
solb 2013/07/12 01:14:22 Done.
- // Called by client authenticator.
- // Gets notified if the user needs to enter a PIN, and notifies Java in turn.
+ // Called by client authenticator. Calls to Java to prompt for the ser's PIN.
void FetchSecret(bool pairable,
- const protocol::SecretFetchedCallback& callback_encore);
+ const protocol::SecretFetchedCallback& callback);
- // ClientUserInterface implementation:
+ // ClientUserInterface implementation.
virtual void OnConnectionState(
protocol::ConnectionToHost::State state,
protocol::ErrorCode error) OVERRIDE;
@@ -75,6 +78,9 @@ class ChromotingJNIInstance : public ClientUserInterface {
private:
ChromotingJNIInstance();
+
+ // Any existing or attempted connection must have been terminated using
+ // DisconnectFromHost() before this singleton is destroyed.
virtual ~ChromotingJNIInstance();
void ConnectToHostOnDisplayThread();
@@ -82,41 +88,48 @@ 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.
+
+ // Whether we're in the connected state, meaning we're attempting to connect,
+ // we're currently connected, or the connection has failed somehow.
Wez 2013/07/12 00:24:48 Chromium comment style would be something like: "T
solb 2013/07/12 01:14:22 Done.
+ bool connected_;
- // 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