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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 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.
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 // Should only be called while disconnected.
45 void ConnectToHost( 50 void ConnectToHost(
46 jstring username, 51 const char* username,
47 jstring auth_token, 52 const char* auth_token,
48 jstring host_jid, 53 const char* host_jid,
49 jstring host_id, 54 const char* host_id,
50 jstring host_pubkey); 55 const char* host_pubkey);
51 56
52 // Call from UI thread. 57 // 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
53 void DisconnectFromHost(); 58 void DisconnectFromHost();
54 59
55 // Call from UI thread. 60 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.
56 void AuthenticateWithPin(jstring pin);
57 61
58 // Called by client authenticator. 62 // Called by client authenticator. Calls to Java to prompt for the ser's PIN.
59 // Gets notified if the user needs to enter a PIN, and notifies Java in turn.
60 void FetchSecret(bool pairable, 63 void FetchSecret(bool pairable,
61 const protocol::SecretFetchedCallback& callback_encore); 64 const protocol::SecretFetchedCallback& callback);
62 65
63 // ClientUserInterface implementation: 66 // ClientUserInterface implementation.
64 virtual void OnConnectionState( 67 virtual void OnConnectionState(
65 protocol::ConnectionToHost::State state, 68 protocol::ConnectionToHost::State state,
66 protocol::ErrorCode error) OVERRIDE; 69 protocol::ErrorCode error) OVERRIDE;
67 virtual void OnConnectionReady(bool ready) OVERRIDE; 70 virtual void OnConnectionReady(bool ready) OVERRIDE;
68 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; 71 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE;
69 virtual void SetPairingResponse( 72 virtual void SetPairingResponse(
70 const protocol::PairingResponse& response) OVERRIDE; 73 const protocol::PairingResponse& response) OVERRIDE;
71 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; 74 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE;
72 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; 75 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE;
73 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> 76 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
74 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; 77 GetTokenFetcher(const std::string& host_public_key) OVERRIDE;
75 78
76 private: 79 private:
77 ChromotingJNIInstance(); 80 ChromotingJNIInstance();
81
82 // Any existing or attempted connection must have been terminated using
83 // DisconnectFromHost() before this singleton is destroyed.
78 virtual ~ChromotingJNIInstance(); 84 virtual ~ChromotingJNIInstance();
79 85
80 void ConnectToHostOnDisplayThread(); 86 void ConnectToHostOnDisplayThread();
81 void ConnectToHostOnNetworkThread(); 87 void ConnectToHostOnNetworkThread();
82 88
83 void DisconnectFromHostOnNetworkThread(); 89 void DisconnectFromHostOnNetworkThread();
84 90
85 // Reusable between sessions: 91 // The below variables are reused across consecutive sessions.
86 jclass class_; // Reference to the Java class into which we make JNI calls. 92
93 // Reference to the Java class into which we make JNI calls.
94 jclass class_;
95
96 // Used by the Chromium libraries to clean up the base and net libraries' JNI
97 // bindings. It must persist for the lifetime of the singleton.
87 scoped_ptr<base::AtExitManager> collector_; 98 scoped_ptr<base::AtExitManager> collector_;
99
100 // Chromium code's connection to the Java message loop.
88 scoped_ptr<base::MessageLoopForUI> ui_loop_; 101 scoped_ptr<base::MessageLoopForUI> ui_loop_;
89 scoped_refptr<AutoThreadTaskRunner> ui_runner_; 102
90 scoped_refptr<AutoThreadTaskRunner> net_runner_; 103 // Runners that allow posting tasks to the various native threads.
91 scoped_refptr<AutoThreadTaskRunner> disp_runner_; 104 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
105 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
106 scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
107
92 scoped_refptr<net::URLRequestContextGetter> url_requester_; 108 scoped_refptr<net::URLRequestContextGetter> url_requester_;
93 scoped_refptr<FrameConsumerProxy> frames_; 109 scoped_refptr<FrameConsumerProxy> frame_consumer_;
94 110
95 // Specific to each session: 111 // The below variables are specific to each connection.
112
113 // Whether we're in the connected state, meaning we're attempting to connect,
114 // 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.
115 bool connected_;
116
96 scoped_ptr<ClientConfig> client_config_; 117 scoped_ptr<ClientConfig> client_config_;
97 scoped_ptr<ClientContext> client_context_; 118 scoped_ptr<ClientContext> client_context_;
98 scoped_ptr<protocol::ConnectionToHost> connection_; 119 scoped_ptr<protocol::ConnectionToHost> connection_;
99 scoped_ptr<ChromotingClient> client_; 120 scoped_ptr<ChromotingClient> client_;
100 scoped_ptr<XmppSignalStrategy::XmppServerConfig> chat_config_; 121 scoped_ptr<XmppSignalStrategy::XmppServerConfig> signaling_config_;
101 scoped_ptr<XmppSignalStrategy> chat_; // must outlive client_ 122 scoped_ptr<XmppSignalStrategy> signaling_; // must outlive client_
102 scoped_ptr<NetworkSettings> netset_; 123 scoped_ptr<NetworkSettings> network_settings_;
103 protocol::SecretFetchedCallback announce_secret_; 124 protocol::SecretFetchedCallback pin_callback_;
104 125
105 // Java string handles: 126 // These strings describe the current connection, and are not reused.
106 jstring username_jstr_; 127 std::string username_;
107 jstring auth_token_jstr_; 128 std::string auth_token_;
108 jstring host_jid_jstr_; 129 std::string host_jid_;
109 jstring host_id_jstr_; 130 std::string host_id_;
110 jstring host_pubkey_jstr_; 131 std::string host_pubkey_;
111 jstring pin_jstr_; 132 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 133
121 friend struct DefaultSingletonTraits<ChromotingJNIInstance>; 134 friend struct DefaultSingletonTraits<ChromotingJNIInstance>;
122 135
123 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance); 136 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance);
124 }; 137 };
125 138
126 } // namespace remoting 139 } // namespace remoting
127 140
128 #endif 141 #endif
OLDNEW
« 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