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

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: Ensure connect and disconnect are called on the same thread 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 18 matching lines...) Expand all
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 (e.g. message loops and task runners) on which the
Wez 2013/07/12 01:25:44 nit: Either move the bracket to the end of the lin
solb 2013/07/12 02:31:49 Done.
41 // Chromium components run.
Wez 2013/07/12 01:25:44 nit: Chromium -> Chromoting
solb 2013/07/12 02:31:49 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.
42 static ChromotingJNIInstance* GetInstance(); 47 static ChromotingJNIInstance* GetInstance();
43 48
44 // Call from UI thread. 49 // Should only be called while disconnected. Must be invoked on UI thread.
Wez 2013/07/12 01:25:44 Please see http://google-styleguide.googlecode.com
solb 2013/07/12 02:31:49 Done.
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. Must be
58 // invoked on UI thread.
Wez 2013/07/12 01:25:44 See http://google-styleguide.googlecode.com/svn/tr
solb 2013/07/12 02:31:49 Done.
53 void DisconnectFromHost(); 59 void DisconnectFromHost();
54 60
55 // Call from UI thread. 61 // To be called once the user has provided a PIN to the user interface.
Wez 2013/07/12 01:25:44 See http://google-styleguide.googlecode.com/svn/tr
solb 2013/07/12 02:31:49 Done.
56 void AuthenticateWithPin(jstring pin); 62 void AuthenticateWithPin(const char* pin);
57 63
58 // Called by client authenticator. 64 // Called by client authenticator. Calls to Java to prompt for the user's PIN.
Wez 2013/07/12 01:25:44 See http://google-styleguide.googlecode.com/svn/tr
solb 2013/07/12 02:31:49 Done.
59 // Gets notified if the user needs to enter a PIN, and notifies Java in turn.
60 void FetchSecret(bool pairable, 65 void FetchSecret(bool pairable,
61 const protocol::SecretFetchedCallback& callback_encore); 66 const protocol::SecretFetchedCallback& callback);
62 67
63 // ClientUserInterface implementation: 68 // ClientUserInterface implementation.
64 virtual void OnConnectionState( 69 virtual void OnConnectionState(
65 protocol::ConnectionToHost::State state, 70 protocol::ConnectionToHost::State state,
66 protocol::ErrorCode error) OVERRIDE; 71 protocol::ErrorCode error) OVERRIDE;
67 virtual void OnConnectionReady(bool ready) OVERRIDE; 72 virtual void OnConnectionReady(bool ready) OVERRIDE;
68 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; 73 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE;
69 virtual void SetPairingResponse( 74 virtual void SetPairingResponse(
70 const protocol::PairingResponse& response) OVERRIDE; 75 const protocol::PairingResponse& response) OVERRIDE;
71 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; 76 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE;
72 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; 77 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE;
73 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> 78 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
74 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; 79 GetTokenFetcher(const std::string& host_public_key) OVERRIDE;
75 80
76 private: 81 private:
77 ChromotingJNIInstance(); 82 ChromotingJNIInstance();
83
84 // Any existing or attempted connection must have been terminated using
85 // DisconnectFromHost() before this singleton is destroyed. Because
86 // destruction only occurs at application exit after all connections have
87 // terminated, it is safe to make unretained cross-thread calls on the class.
78 virtual ~ChromotingJNIInstance(); 88 virtual ~ChromotingJNIInstance();
79 89
80 void ConnectToHostOnDisplayThread(); 90 void ConnectToHostOnDisplayThread();
81 void ConnectToHostOnNetworkThread(); 91 void ConnectToHostOnNetworkThread();
82 92
83 void DisconnectFromHostOnNetworkThread(); 93 void DisconnectFromHostOnNetworkThread();
84 94
85 // Reusable between sessions: 95 // The below variables are reused across consecutive sessions.
86 jclass class_; // Reference to the Java class into which we make JNI calls. 96
97 // Reference to the Java class into which we make JNI calls.
98 jclass class_;
99
100 // Used by the Chromium libraries to clean up the base and net libraries' JNI
101 // bindings. It must persist for the lifetime of the singleton.
87 scoped_ptr<base::AtExitManager> collector_; 102 scoped_ptr<base::AtExitManager> collector_;
103
104 // Chromium code's connection to the Java message loop.
88 scoped_ptr<base::MessageLoopForUI> ui_loop_; 105 scoped_ptr<base::MessageLoopForUI> ui_loop_;
89 scoped_refptr<AutoThreadTaskRunner> ui_runner_; 106
90 scoped_refptr<AutoThreadTaskRunner> net_runner_; 107 // Runners that allow posting tasks to the various native threads.
91 scoped_refptr<AutoThreadTaskRunner> disp_runner_; 108 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
109 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
110 scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
111
92 scoped_refptr<net::URLRequestContextGetter> url_requester_; 112 scoped_refptr<net::URLRequestContextGetter> url_requester_;
93 scoped_refptr<FrameConsumerProxy> frames_; 113 scoped_refptr<FrameConsumerProxy> frame_consumer_;
94 114
95 // Specific to each session: 115 // The below variables are specific to each connection.
116
117 // True iff ConnectToHost() has been called without a subsequent
118 // call to DisconnectFromHost() (i.e. while connecting, once connected, and
119 // between the time a connection fails and DisconnectFromHost() is called).
120 bool connected_;
121
96 scoped_ptr<ClientConfig> client_config_; 122 scoped_ptr<ClientConfig> client_config_;
97 scoped_ptr<ClientContext> client_context_; 123 scoped_ptr<ClientContext> client_context_;
98 scoped_ptr<protocol::ConnectionToHost> connection_; 124 scoped_ptr<protocol::ConnectionToHost> connection_;
99 scoped_ptr<ChromotingClient> client_; 125 scoped_ptr<ChromotingClient> client_;
100 scoped_ptr<XmppSignalStrategy::XmppServerConfig> chat_config_; 126 scoped_ptr<XmppSignalStrategy::XmppServerConfig> signaling_config_;
101 scoped_ptr<XmppSignalStrategy> chat_; // must outlive client_ 127 scoped_ptr<XmppSignalStrategy> signaling_; // must outlive client_
102 scoped_ptr<NetworkSettings> netset_; 128 scoped_ptr<NetworkSettings> network_settings_;
103 protocol::SecretFetchedCallback announce_secret_; 129 protocol::SecretFetchedCallback pin_callback_;
104 130
105 // Java string handles: 131 // These strings describe the current connection, and are not reused.
106 jstring username_jstr_; 132 std::string username_;
107 jstring auth_token_jstr_; 133 std::string auth_token_;
108 jstring host_jid_jstr_; 134 std::string host_jid_;
109 jstring host_id_jstr_; 135 std::string host_id_;
110 jstring host_pubkey_jstr_; 136 std::string host_pubkey_;
111 jstring pin_jstr_; 137 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 138
121 friend struct DefaultSingletonTraits<ChromotingJNIInstance>; 139 friend struct DefaultSingletonTraits<ChromotingJNIInstance>;
122 140
123 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance); 141 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance);
124 }; 142 };
125 143
126 } // namespace remoting 144 } // namespace remoting
127 145
128 #endif 146 #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