OLD | NEW |
---|---|
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 #include "remoting/client/jni/chromoting_jni_instance.h" | 5 #include "remoting/client/jni/chromoting_jni_instance.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "remoting/client/audio_player.h" | 9 #include "remoting/client/audio_player.h" |
10 #include "remoting/client/jni/chromoting_jni.h" | 10 #include "remoting/client/jni/chromoting_jni.h" |
11 #include "remoting/protocol/libjingle_transport_factory.h" | 11 #include "remoting/protocol/libjingle_transport_factory.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 // TODO(solb) Move into location shared with client plugin. | 14 // TODO(solb) Move into location shared with client plugin. |
15 const char* const CHAT_SERVER = "talk.google.com"; | 15 const char* const CHAT_SERVER = "talk.google.com"; |
Wez
2013/07/16 18:45:53
IIRC 'const' at file scope is implicitly static-li
solb
2013/07/16 21:35:41
Done.
| |
16 const int CHAT_PORT = 5222; | 16 const int CHAT_PORT = 5222; |
17 const bool CHAT_USE_TLS = true; | 17 const bool CHAT_USE_TLS = true; |
18 const char* const CHAT_AUTH_METHOD = "oauth2"; | 18 const char* const CHAT_AUTH_METHOD = "oauth2"; |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 namespace remoting { | 21 namespace remoting { |
22 | 22 |
23 ChromotingJniInstance::ChromotingJniInstance(const char* username, | 23 ChromotingJniInstance::ChromotingJniInstance(const char* username, |
24 const char* auth_token, | 24 const char* auth_token, |
Wez
2013/07/16 18:45:53
nit: Indentation
solb
2013/07/16 21:35:41
Done.
| |
25 const char* host_jid, | 25 const char* host_jid, |
26 const char* host_id, | 26 const char* host_id, |
27 const char* host_pubkey) { | 27 const char* host_pubkey) { |
28 DCHECK(ChromotingJni::GetInstance()-> | 28 DCHECK(ChromotingJni::GetInstance()-> |
29 ui_task_runner()->BelongsToCurrentThread()); | 29 ui_task_runner()->BelongsToCurrentThread()); |
30 | 30 |
31 username_ = username; | 31 username_ = username; |
32 auth_token_ = auth_token; | 32 auth_token_ = auth_token; |
33 host_jid_ = host_jid; | 33 host_jid_ = host_jid; |
34 host_id_ = host_id; | 34 host_id_ = host_id; |
35 host_pubkey_ = host_pubkey; | 35 host_pubkey_ = host_pubkey; |
36 | 36 |
37 ChromotingJni::GetInstance()->display_task_runner()->PostTask( | 37 ChromotingJni::GetInstance()->display_task_runner()->PostTask( |
38 FROM_HERE, | 38 FROM_HERE, |
39 base::Bind(&ChromotingJniInstance::ConnectToHostOnDisplayThread, | 39 base::Bind(&ChromotingJniInstance::ConnectToHostOnDisplayThread, |
40 this)); | 40 this)); |
41 } | 41 } |
42 | 42 |
43 ChromotingJniInstance::~ChromotingJniInstance() {} | 43 ChromotingJniInstance::~ChromotingJniInstance() { |
44 // Invalidate weak pointers to |view_| before it is destroyed. | |
45 view_weak_factory_->InvalidateWeakPtrs(); | |
Wez
2013/07/16 18:45:53
nit: Since you only grab a WeakPtr to the view at
solb
2013/07/16 21:35:41
Done.
| |
46 } | |
44 | 47 |
45 void ChromotingJniInstance::Cleanup() { | 48 void ChromotingJniInstance::Cleanup() { |
46 if (!ChromotingJni::GetInstance()-> | 49 if (!ChromotingJni::GetInstance()-> |
47 network_task_runner()->BelongsToCurrentThread()) { | 50 network_task_runner()->BelongsToCurrentThread()) { |
48 ChromotingJni::GetInstance()->network_task_runner()->PostTask( | 51 ChromotingJni::GetInstance()->network_task_runner()->PostTask( |
49 FROM_HERE, | 52 FROM_HERE, |
50 base::Bind(&ChromotingJniInstance::Cleanup, this)); | 53 base::Bind(&ChromotingJniInstance::Cleanup, this)); |
51 return; | 54 return; |
52 } | 55 } |
53 | 56 |
54 username_ = ""; | 57 username_ = ""; |
55 auth_token_ = ""; | 58 auth_token_ = ""; |
56 host_jid_ = ""; | 59 host_jid_ = ""; |
57 host_id_ = ""; | 60 host_id_ = ""; |
58 host_pubkey_ = ""; | 61 host_pubkey_ = ""; |
59 | 62 |
60 // |client_| must be torn down before |signaling_|. | 63 // We reset these manually because they must be destroyed on the network |
64 // thread. |client_| must be torn down before |signaling_|. | |
61 pin_callback_.Reset(); | 65 pin_callback_.Reset(); |
62 client_.reset(); | 66 client_.reset(); |
63 connection_.reset(); | 67 connection_.reset(); |
64 client_context_.reset(); | 68 client_context_.reset(); |
65 client_config_.reset(); | 69 client_config_.reset(); |
66 signaling_.reset(); | 70 signaling_.reset(); |
67 signaling_config_.reset(); | 71 signaling_config_.reset(); |
68 network_settings_.reset(); | 72 network_settings_.reset(); |
69 } | 73 } |
70 | 74 |
71 void ChromotingJniInstance::ProvideSecret(const char* pin) { | 75 void ChromotingJniInstance::ProvideSecret(const char* pin) { |
72 DCHECK(ChromotingJni::GetInstance()-> | 76 DCHECK(ChromotingJni::GetInstance()-> |
73 ui_task_runner()->BelongsToCurrentThread()); | 77 ui_task_runner()->BelongsToCurrentThread()); |
74 DCHECK(!pin_callback_.is_null()); | 78 DCHECK(!pin_callback_.is_null()); |
75 | 79 |
76 // We invoke the string constructor to ensure |pin| gets copied *before* the | 80 // We invoke the string constructor to ensure |pin| gets copied *before* the |
77 // asynchronous run, since Java might want it back as soon as we return. | 81 // asynchronous run, since Java might want it back as soon as we return. |
78 ChromotingJni::GetInstance()->network_task_runner()->PostTask(FROM_HERE, | 82 ChromotingJni::GetInstance()->network_task_runner()->PostTask(FROM_HERE, |
79 base::Bind(pin_callback_, pin)); | 83 base::Bind(pin_callback_, pin)); |
80 } | 84 } |
81 | 85 |
86 void ChromotingJniInstance::RedrawDesktop() { | |
87 if (!ChromotingJni::GetInstance()-> | |
88 display_task_runner()->BelongsToCurrentThread()) { | |
89 ChromotingJni::GetInstance()->display_task_runner()->PostTask( | |
90 FROM_HERE, | |
91 base::Bind(&ChromotingJniInstance::RedrawDesktop, | |
92 this)); | |
93 return; | |
94 } | |
95 | |
96 ChromotingJni::GetInstance()->RedrawCanvas(); | |
97 } | |
98 | |
82 void ChromotingJniInstance::OnConnectionState( | 99 void ChromotingJniInstance::OnConnectionState( |
83 protocol::ConnectionToHost::State state, | 100 protocol::ConnectionToHost::State state, |
84 protocol::ErrorCode error) { | 101 protocol::ErrorCode error) { |
85 if (!ChromotingJni::GetInstance()-> | 102 if (!ChromotingJni::GetInstance()-> |
86 ui_task_runner()->BelongsToCurrentThread()) { | 103 ui_task_runner()->BelongsToCurrentThread()) { |
87 ChromotingJni::GetInstance()-> | 104 ChromotingJni::GetInstance()-> |
88 ui_task_runner()->PostTask( | 105 ui_task_runner()->PostTask( |
89 FROM_HERE, | 106 FROM_HERE, |
90 base::Bind(&ChromotingJniInstance::OnConnectionState, | 107 base::Bind(&ChromotingJniInstance::OnConnectionState, |
91 this, | 108 this, |
(...skipping 29 matching lines...) Expand all Loading... | |
121 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | 138 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
122 ChromotingJniInstance::GetTokenFetcher(const std::string& host_public_key) { | 139 ChromotingJniInstance::GetTokenFetcher(const std::string& host_public_key) { |
123 // Return null to indicate that third-party authentication is unsupported. | 140 // Return null to indicate that third-party authentication is unsupported. |
124 return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>(); | 141 return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>(); |
125 } | 142 } |
126 | 143 |
127 void ChromotingJniInstance::ConnectToHostOnDisplayThread() { | 144 void ChromotingJniInstance::ConnectToHostOnDisplayThread() { |
128 DCHECK(ChromotingJni::GetInstance()-> | 145 DCHECK(ChromotingJni::GetInstance()-> |
129 display_task_runner()->BelongsToCurrentThread()); | 146 display_task_runner()->BelongsToCurrentThread()); |
130 | 147 |
131 if (!frame_consumer_.get()) { | 148 frame_consumer_ = new FrameConsumerProxy( |
132 frame_consumer_ = new FrameConsumerProxy( | 149 ChromotingJni::GetInstance()->display_task_runner()); |
133 ChromotingJni::GetInstance()->display_task_runner()); | 150 view_.reset(new JniFrameConsumer()); |
134 // TODO(solb) Instantiate some FrameConsumer implementation and attach it. | 151 view_weak_factory_.reset(new base::WeakPtrFactory<JniFrameConsumer>( |
135 } | 152 view_.get())); |
153 frame_consumer_->Attach(view_weak_factory_->GetWeakPtr()); | |
136 | 154 |
137 ChromotingJni::GetInstance()->network_task_runner()->PostTask( | 155 ChromotingJni::GetInstance()->network_task_runner()->PostTask( |
138 FROM_HERE, | 156 FROM_HERE, |
139 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, | 157 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, |
140 this)); | 158 this)); |
141 } | 159 } |
142 | 160 |
143 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { | 161 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { |
144 DCHECK(ChromotingJni::GetInstance()-> | 162 DCHECK(ChromotingJni::GetInstance()-> |
145 network_task_runner()->BelongsToCurrentThread()); | 163 network_task_runner()->BelongsToCurrentThread()); |
(...skipping 19 matching lines...) Expand all Loading... | |
165 | 183 |
166 connection_.reset(new protocol::ConnectionToHost(true)); | 184 connection_.reset(new protocol::ConnectionToHost(true)); |
167 | 185 |
168 client_.reset(new ChromotingClient(*client_config_, | 186 client_.reset(new ChromotingClient(*client_config_, |
169 client_context_.get(), | 187 client_context_.get(), |
170 connection_.get(), | 188 connection_.get(), |
171 this, | 189 this, |
172 frame_consumer_, | 190 frame_consumer_, |
173 scoped_ptr<AudioPlayer>())); | 191 scoped_ptr<AudioPlayer>())); |
174 | 192 |
193 view_->set_frame_producer(client_->GetFrameProducer()); | |
194 | |
175 signaling_config_.reset(new XmppSignalStrategy::XmppServerConfig()); | 195 signaling_config_.reset(new XmppSignalStrategy::XmppServerConfig()); |
176 signaling_config_->host = CHAT_SERVER; | 196 signaling_config_->host = CHAT_SERVER; |
177 signaling_config_->port = CHAT_PORT; | 197 signaling_config_->port = CHAT_PORT; |
178 signaling_config_->use_tls = CHAT_USE_TLS; | 198 signaling_config_->use_tls = CHAT_USE_TLS; |
179 | 199 |
180 signaling_.reset(new XmppSignalStrategy( | 200 signaling_.reset(new XmppSignalStrategy( |
181 ChromotingJni::GetInstance()->url_requester(), | 201 ChromotingJni::GetInstance()->url_requester(), |
182 username_, | 202 username_, |
183 auth_token_, | 203 auth_token_, |
184 CHAT_AUTH_METHOD, | 204 CHAT_AUTH_METHOD, |
(...skipping 21 matching lines...) Expand all Loading... | |
206 pairable, | 226 pairable, |
207 callback)); | 227 callback)); |
208 return; | 228 return; |
209 } | 229 } |
210 | 230 |
211 pin_callback_ = callback; | 231 pin_callback_ = callback; |
212 ChromotingJni::GetInstance()->DisplayAuthenticationPrompt(); | 232 ChromotingJni::GetInstance()->DisplayAuthenticationPrompt(); |
213 } | 233 } |
214 | 234 |
215 } // namespace remoting | 235 } // namespace remoting |
OLD | NEW |