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

Side by Side Diff: remoting/client/jni/chromoting_jni_instance.h

Issue 19253003: Separate singleton out of ChromotingJNIInstance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move constants into anonymous namespaces 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
« no previous file with comments | « remoting/client/jni/chromoting_jni.cc ('k') | remoting/client/jni/chromoting_jni_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
9 #include <string> 8 #include <string>
10 9
11 #include "base/at_exit.h"
12 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
15 #include "net/url_request/url_request_context_getter.h"
16 #include "remoting/base/auto_thread.h"
17 #include "remoting/client/chromoting_client.h" 13 #include "remoting/client/chromoting_client.h"
18 #include "remoting/client/client_config.h" 14 #include "remoting/client/client_config.h"
19 #include "remoting/client/client_context.h" 15 #include "remoting/client/client_context.h"
20 #include "remoting/client/client_user_interface.h" 16 #include "remoting/client/client_user_interface.h"
21 #include "remoting/client/frame_consumer_proxy.h" 17 #include "remoting/client/frame_consumer_proxy.h"
22 #include "remoting/jingle_glue/network_settings.h" 18 #include "remoting/jingle_glue/network_settings.h"
23 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 19 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
24 #include "remoting/protocol/connection_to_host.h" 20 #include "remoting/protocol/connection_to_host.h"
25 21
26 template<typename T> struct DefaultSingletonTraits; 22 namespace remoting {
23 class ChromotingJni;
27 24
28 namespace remoting { 25 // ClientUserInterface that indirectly makes and receives JNI calls.
29 26 class ChromotingJniInstance
30 // Class and package name of the Java class supporting the methods we call. 27 : public ClientUserInterface,
31 const char* const JAVA_CLASS = "org/chromium/chromoting/jni/JNIInterface"; 28 public base::RefCountedThreadSafe<ChromotingJniInstance> {
32
33 // TODO(solb) Move into location shared with client plugin.
34 const char* const CHAT_SERVER = "talk.google.com";
35 const int CHAT_PORT = 5222;
36 const bool CHAT_USE_TLS = true;
37 const char* const CHAT_AUTH_METHOD = "oauth2";
38
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).
42 class ChromotingJNIInstance : public ClientUserInterface {
43 public: 29 public:
44 // This class is instantiated at process initialization and persists until 30 // Initiates a connection with the specified host. Call from the UI thread.
45 // we close. It reuses many of its components between connections (i.e. when 31 ChromotingJniInstance(
46 // a DisconnectFromHost() call is followed by a ConnectToHost() one.
47 static ChromotingJNIInstance* GetInstance();
48
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.
51 void ConnectToHost(
52 const char* username, 32 const char* username,
53 const char* auth_token, 33 const char* auth_token,
54 const char* host_jid, 34 const char* host_jid,
55 const char* host_id, 35 const char* host_id,
56 const char* host_pubkey); 36 const char* host_pubkey);
57 37
58 // Terminates the current connection (if it hasn't already failed) and clean 38 // Terminates the current connection (if it hasn't already failed) and cleans
59 // up. This may only be called when |connected_|, and only from the UI thread. 39 // up. Must be called before destruction.
60 void DisconnectFromHost(); 40 void Cleanup();
61 41
62 // Provides the user's PIN and resumes the host authentication attempt. Call 42 // Provides the user's PIN and resumes the host authentication attempt. Call
63 // on the UI thread once the user has finished entering this PIN into the UI, 43 // 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()). 44 // but only after the UI has been asked to provide a PIN (via FetchSecret()).
65 void ProvideSecret(const char* pin); 45 void ProvideSecret(const char* pin);
66 46
67 // ClientUserInterface implementation. 47 // ClientUserInterface implementation.
68 virtual void OnConnectionState( 48 virtual void OnConnectionState(
69 protocol::ConnectionToHost::State state, 49 protocol::ConnectionToHost::State state,
70 protocol::ErrorCode error) OVERRIDE; 50 protocol::ErrorCode error) OVERRIDE;
71 virtual void OnConnectionReady(bool ready) OVERRIDE; 51 virtual void OnConnectionReady(bool ready) OVERRIDE;
72 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; 52 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE;
73 virtual void SetPairingResponse( 53 virtual void SetPairingResponse(
74 const protocol::PairingResponse& response) OVERRIDE; 54 const protocol::PairingResponse& response) OVERRIDE;
75 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; 55 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE;
76 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; 56 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE;
77 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> 57 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
78 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; 58 GetTokenFetcher(const std::string& host_public_key) OVERRIDE;
79 59
80 private: 60 private:
81 ChromotingJNIInstance(); 61 // This object is ref-counted, so it cleans itself up.
82 62 virtual ~ChromotingJniInstance();
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.
88 virtual ~ChromotingJNIInstance();
89 63
90 void ConnectToHostOnDisplayThread(); 64 void ConnectToHostOnDisplayThread();
91 void ConnectToHostOnNetworkThread(); 65 void ConnectToHostOnNetworkThread();
92 66
93 void DisconnectFromHostOnNetworkThread();
94
95 // Notifies the user interface that the user needs to enter a PIN. The 67 // Notifies the user interface that the user needs to enter a PIN. The
96 // current authentication attempt is put on hold until |callback| is invoked. 68 // current authentication attempt is put on hold until |callback| is invoked.
97 void FetchSecret(bool pairable, 69 void FetchSecret(bool pairable,
98 const protocol::SecretFetchedCallback& callback); 70 const protocol::SecretFetchedCallback& callback);
99 71
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.
107 scoped_ptr<base::AtExitManager> collector_;
108
109 // Chromium code's connection to the Java message loop.
110 scoped_ptr<base::MessageLoopForUI> ui_loop_;
111
112 // Runners that allow posting tasks to the various native threads.
113 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
114 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
115 scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
116
117 scoped_refptr<net::URLRequestContextGetter> url_requester_;
118 scoped_refptr<FrameConsumerProxy> frame_consumer_; 72 scoped_refptr<FrameConsumerProxy> frame_consumer_;
119 73
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. 74 // This group of variables is to be used on the network thread.
129 scoped_ptr<ClientConfig> client_config_; 75 scoped_ptr<ClientConfig> client_config_;
130 scoped_ptr<ClientContext> client_context_; 76 scoped_ptr<ClientContext> client_context_;
131 scoped_ptr<protocol::ConnectionToHost> connection_; 77 scoped_ptr<protocol::ConnectionToHost> connection_;
132 scoped_ptr<ChromotingClient> client_; 78 scoped_ptr<ChromotingClient> client_;
133 scoped_ptr<XmppSignalStrategy::XmppServerConfig> signaling_config_; 79 scoped_ptr<XmppSignalStrategy::XmppServerConfig> signaling_config_;
134 scoped_ptr<XmppSignalStrategy> signaling_; // Must outlive client_ 80 scoped_ptr<XmppSignalStrategy> signaling_; // Must outlive client_
135 scoped_ptr<NetworkSettings> network_settings_; 81 scoped_ptr<NetworkSettings> network_settings_;
136 82
137 // Pass this the user's PIN once we have it. To be assigned and accessed on 83 // Pass this the user's PIN once we have it. To be assigned and accessed on
138 // the UI thread, but must be posted to the network thread to call it. 84 // the UI thread, but must be posted to the network thread to call it.
139 protocol::SecretFetchedCallback pin_callback_; 85 protocol::SecretFetchedCallback pin_callback_;
140 86
141 // These strings describe the current connection, and are not reused. They 87 // These strings describe the current connection, and are not reused. They
142 // are initialized in ConnectionToHost(), but thereafter are only to be used 88 // are initialized in ConnectionToHost(), but thereafter are only to be used
143 // on the network thread. (This is safe because ConnectionToHost()'s finishes 89 // on the network thread. (This is safe because ConnectionToHost()'s finishes
144 // using them on the UI thread before they are ever touched from network.) 90 // using them on the UI thread before they are ever touched from network.)
145 std::string username_; 91 std::string username_;
146 std::string auth_token_; 92 std::string auth_token_;
147 std::string host_jid_; 93 std::string host_jid_;
148 std::string host_id_; 94 std::string host_id_;
149 std::string host_pubkey_; 95 std::string host_pubkey_;
150 96
151 friend struct DefaultSingletonTraits<ChromotingJNIInstance>; 97 friend class base::RefCountedThreadSafe<ChromotingJniInstance>;
152 98
153 DISALLOW_COPY_AND_ASSIGN(ChromotingJNIInstance); 99 DISALLOW_COPY_AND_ASSIGN(ChromotingJniInstance);
154 }; 100 };
155 101
156 } // namespace remoting 102 } // namespace remoting
157 103
158 #endif 104 #endif
OLDNEW
« no previous file with comments | « remoting/client/jni/chromoting_jni.cc ('k') | remoting/client/jni/chromoting_jni_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698