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

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: Documentation and guards against using variables on the wrong 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 on which the Chromoting components run
41 // (e.g. message loops and task runners).
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 // Initiates a connection with the specified host. This may only be called
50 // when |connected_| is false, and must be invoked on the UI thread.
45 void ConnectToHost( 51 void ConnectToHost(
46 jstring username, 52 const char* username,
47 jstring auth_token, 53 const char* auth_token,
48 jstring host_jid, 54 const char* host_jid,
49 jstring host_id, 55 const char* host_id,
50 jstring host_pubkey); 56 const char* host_pubkey);
51 57
52 // Call from UI thread. 58 // Terminates the current connection (if it hasn't already failed) and clean
59 // up. This may only be called when |connected_|, and only from the UI thread.
53 void DisconnectFromHost(); 60 void DisconnectFromHost();
54 61
55 // Call from UI thread. 62 // Provides the user's PIN and resumes the host authentication attempt. Call
56 void AuthenticateWithPin(jstring pin); 63 // on the UI thread once the user has finished entering this PIN into the UI,
64 // but only after the UI has been asked to provide a PIN (via FetchSecret()).
65 void ProvideSecret(const char* pin);
57 66
58 // Called by client authenticator. 67 // ClientUserInterface implementation.
59 // Gets notified if the user needs to enter a PIN, and notifies Java in turn.
60 void FetchSecret(bool pairable,
61 const protocol::SecretFetchedCallback& callback_encore);
62
63 // ClientUserInterface implementation:
64 virtual void OnConnectionState( 68 virtual void OnConnectionState(
65 protocol::ConnectionToHost::State state, 69 protocol::ConnectionToHost::State state,
66 protocol::ErrorCode error) OVERRIDE; 70 protocol::ErrorCode error) OVERRIDE;
67 virtual void OnConnectionReady(bool ready) OVERRIDE; 71 virtual void OnConnectionReady(bool ready) OVERRIDE;
68 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; 72 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE;
69 virtual void SetPairingResponse( 73 virtual void SetPairingResponse(
70 const protocol::PairingResponse& response) OVERRIDE; 74 const protocol::PairingResponse& response) OVERRIDE;
71 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; 75 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE;
72 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; 76 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE;
73 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> 77 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
74 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; 78 GetTokenFetcher(const std::string& host_public_key) OVERRIDE;
75 79
76 private: 80 private:
77 ChromotingJNIInstance(); 81 ChromotingJNIInstance();
82
83 // Any existing or attempted connection must have been terminated using
84 // DisconnectFromHost() before this singleton is destroyed. Because
85 // destruction only occurs at application exit after all connections have
86 // terminated, it is safe to make unretained cross-thread calls on the class.
87 // As a singleton, this object must be destroyed on the main (UI) thread.
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 // Notifies the user interface that the user needs to enter a PIN. The
86 jclass class_; // Reference to the Java class into which we make JNI calls. 96 // current authentication attempt is put on hold until |callback| is invoked.
97 void FetchSecret(bool pairable,
98 const protocol::SecretFetchedCallback& callback);
99
100 // The below variables are reused across consecutive sessions.
101
102 // Reference to the Java class into which we make JNI calls.
103 jclass class_;
104
105 // Used by the Chromium libraries to clean up the base and net libraries' JNI
106 // bindings. It must persist for the lifetime of the singleton.
87 scoped_ptr<base::AtExitManager> collector_; 107 scoped_ptr<base::AtExitManager> collector_;
108
109 // Chromium code's connection to the Java message loop.
88 scoped_ptr<base::MessageLoopForUI> ui_loop_; 110 scoped_ptr<base::MessageLoopForUI> ui_loop_;
89 scoped_refptr<AutoThreadTaskRunner> ui_runner_; 111
90 scoped_refptr<AutoThreadTaskRunner> net_runner_; 112 // Runners that allow posting tasks to the various native threads.
91 scoped_refptr<AutoThreadTaskRunner> disp_runner_; 113 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
114 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
115 scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
116
92 scoped_refptr<net::URLRequestContextGetter> url_requester_; 117 scoped_refptr<net::URLRequestContextGetter> url_requester_;
93 scoped_refptr<FrameConsumerProxy> frames_; 118 scoped_refptr<FrameConsumerProxy> frame_consumer_;
94 119
95 // Specific to each session: 120 // All below variables are specific to each connection.
121
122 // True iff ConnectToHost() has been called without a subsequent
123 // call to DisconnectFromHost() (i.e. while connecting, once connected, and
124 // between the time a connection fails and DisconnectFromHost() is called).
125 // To be used on the UI thread.
126 bool connected_;
127
128 // This group of variables is to be used on the network thread.
96 scoped_ptr<ClientConfig> client_config_; 129 scoped_ptr<ClientConfig> client_config_;
97 scoped_ptr<ClientContext> client_context_; 130 scoped_ptr<ClientContext> client_context_;
98 scoped_ptr<protocol::ConnectionToHost> connection_; 131 scoped_ptr<protocol::ConnectionToHost> connection_;
99 scoped_ptr<ChromotingClient> client_; 132 scoped_ptr<ChromotingClient> client_;
100 scoped_ptr<XmppSignalStrategy::XmppServerConfig> chat_config_; 133 scoped_ptr<XmppSignalStrategy::XmppServerConfig> signaling_config_;
101 scoped_ptr<XmppSignalStrategy> chat_; // must outlive client_ 134 scoped_ptr<XmppSignalStrategy> signaling_; // Must outlive client_
102 scoped_ptr<NetworkSettings> netset_; 135 scoped_ptr<NetworkSettings> network_settings_;
103 protocol::SecretFetchedCallback announce_secret_;
104 136
105 // Java string handles: 137 // Pass this the user's PIN once we have it. To be assigned and accessed on
106 jstring username_jstr_; 138 // the UI thread, but must be posted to the network thread to call it.
107 jstring auth_token_jstr_; 139 protocol::SecretFetchedCallback pin_callback_;
108 jstring host_jid_jstr_;
109 jstring host_id_jstr_;
110 jstring host_pubkey_jstr_;
111 jstring pin_jstr_;
112 140
113 // C string pointers: 141 // These strings describe the current connection, and are not reused. They
114 const char* username_cstr_; 142 // are initialized in ConnectionToHost(), but thereafter are only to be used
115 const char* auth_token_cstr_; 143 // on the network thread. (This is safe because ConnectionToHost()'s finishes
116 const char* host_jid_cstr_; 144 // using them on the UI thread before they are ever touched from network.)
117 const char* host_id_cstr_; 145 std::string username_;
118 const char* host_pubkey_cstr_; 146 std::string auth_token_;
119 const char* pin_cstr_; 147 std::string host_jid_;
148 std::string host_id_;
149 std::string host_pubkey_;
120 150
121 friend struct DefaultSingletonTraits<ChromotingJNIInstance>; 151 friend struct DefaultSingletonTraits<ChromotingJNIInstance>;
122 152
123 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance); 153 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance);
124 }; 154 };
125 155
126 } // namespace remoting 156 } // namespace remoting
127 157
128 #endif 158 #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