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/host/it2me/it2me_native_messaging_host.h" | 5 #include "remoting/host/it2me/it2me_native_messaging_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 const base::DictionaryValue& message, | 125 const base::DictionaryValue& message, |
126 scoped_ptr<base::DictionaryValue> response) const { | 126 scoped_ptr<base::DictionaryValue> response) const { |
127 DCHECK(task_runner()->BelongsToCurrentThread()); | 127 DCHECK(task_runner()->BelongsToCurrentThread()); |
128 | 128 |
129 response->SetString("version", STRINGIZE(VERSION)); | 129 response->SetString("version", STRINGIZE(VERSION)); |
130 | 130 |
131 // This list will be populated when new features are added. | 131 // This list will be populated when new features are added. |
132 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); | 132 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); |
133 response->Set("supportedFeatures", supported_features_list.release()); | 133 response->Set("supportedFeatures", supported_features_list.release()); |
134 | 134 |
135 channel_->SendMessage(response.PassAs<base::Value>()); | 135 channel_->SendMessage(response.Pass()); |
136 } | 136 } |
137 | 137 |
138 void It2MeNativeMessagingHost::ProcessConnect( | 138 void It2MeNativeMessagingHost::ProcessConnect( |
139 const base::DictionaryValue& message, | 139 const base::DictionaryValue& message, |
140 scoped_ptr<base::DictionaryValue> response) { | 140 scoped_ptr<base::DictionaryValue> response) { |
141 DCHECK(task_runner()->BelongsToCurrentThread()); | 141 DCHECK(task_runner()->BelongsToCurrentThread()); |
142 | 142 |
143 if (it2me_host_.get()) { | 143 if (it2me_host_.get()) { |
144 SendErrorAndExit(response.Pass(), | 144 SendErrorAndExit(response.Pass(), |
145 "Connect can be called only when disconnected."); | 145 "Connect can be called only when disconnected."); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 #endif // !defined(NDEBUG) | 199 #endif // !defined(NDEBUG) |
200 | 200 |
201 // Create the It2Me host and start connecting. | 201 // Create the It2Me host and start connecting. |
202 it2me_host_ = factory_->CreateIt2MeHost(host_context_.get(), | 202 it2me_host_ = factory_->CreateIt2MeHost(host_context_.get(), |
203 host_context_->ui_task_runner(), | 203 host_context_->ui_task_runner(), |
204 weak_ptr_, | 204 weak_ptr_, |
205 xmpp_config, | 205 xmpp_config, |
206 directory_bot_jid_); | 206 directory_bot_jid_); |
207 it2me_host_->Connect(); | 207 it2me_host_->Connect(); |
208 | 208 |
209 channel_->SendMessage(response.PassAs<base::Value>()); | 209 channel_->SendMessage(response.Pass()); |
210 } | 210 } |
211 | 211 |
212 void It2MeNativeMessagingHost::ProcessDisconnect( | 212 void It2MeNativeMessagingHost::ProcessDisconnect( |
213 const base::DictionaryValue& message, | 213 const base::DictionaryValue& message, |
214 scoped_ptr<base::DictionaryValue> response) { | 214 scoped_ptr<base::DictionaryValue> response) { |
215 DCHECK(task_runner()->BelongsToCurrentThread()); | 215 DCHECK(task_runner()->BelongsToCurrentThread()); |
216 | 216 |
217 if (it2me_host_.get()) { | 217 if (it2me_host_.get()) { |
218 it2me_host_->Disconnect(); | 218 it2me_host_->Disconnect(); |
219 it2me_host_ = NULL; | 219 it2me_host_ = NULL; |
220 } | 220 } |
221 channel_->SendMessage(response.PassAs<base::Value>()); | 221 channel_->SendMessage(response.Pass()); |
222 } | 222 } |
223 | 223 |
224 void It2MeNativeMessagingHost::SendErrorAndExit( | 224 void It2MeNativeMessagingHost::SendErrorAndExit( |
225 scoped_ptr<base::DictionaryValue> response, | 225 scoped_ptr<base::DictionaryValue> response, |
226 const std::string& description) const { | 226 const std::string& description) const { |
227 DCHECK(task_runner()->BelongsToCurrentThread()); | 227 DCHECK(task_runner()->BelongsToCurrentThread()); |
228 | 228 |
229 LOG(ERROR) << description; | 229 LOG(ERROR) << description; |
230 | 230 |
231 response->SetString("type", "error"); | 231 response->SetString("type", "error"); |
232 response->SetString("description", description); | 232 response->SetString("description", description); |
233 channel_->SendMessage(response.PassAs<base::Value>()); | 233 channel_->SendMessage(response.Pass()); |
234 | 234 |
235 // Trigger a host shutdown by sending a NULL message. | 235 // Trigger a host shutdown by sending a NULL message. |
236 channel_->SendMessage(scoped_ptr<base::Value>()); | 236 channel_->SendMessage(nullptr); |
237 } | 237 } |
238 | 238 |
239 void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) { | 239 void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) { |
240 DCHECK(task_runner()->BelongsToCurrentThread()); | 240 DCHECK(task_runner()->BelongsToCurrentThread()); |
241 | 241 |
242 state_ = state; | 242 state_ = state; |
243 | 243 |
244 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); | 244 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); |
245 | 245 |
246 message->SetString("type", "hostStateChanged"); | 246 message->SetString("type", "hostStateChanged"); |
(...skipping 12 matching lines...) Expand all Loading... |
259 break; | 259 break; |
260 | 260 |
261 case kDisconnected: | 261 case kDisconnected: |
262 client_username_.clear(); | 262 client_username_.clear(); |
263 break; | 263 break; |
264 | 264 |
265 default: | 265 default: |
266 ; | 266 ; |
267 } | 267 } |
268 | 268 |
269 channel_->SendMessage(message.PassAs<base::Value>()); | 269 channel_->SendMessage(message.Pass()); |
270 } | 270 } |
271 | 271 |
272 void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) { | 272 void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) { |
273 DCHECK(task_runner()->BelongsToCurrentThread()); | 273 DCHECK(task_runner()->BelongsToCurrentThread()); |
274 | 274 |
275 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); | 275 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); |
276 | 276 |
277 message->SetString("type", "natPolicyChanged"); | 277 message->SetString("type", "natPolicyChanged"); |
278 message->SetBoolean("natTraversalEnabled", nat_traversal_enabled); | 278 message->SetBoolean("natTraversalEnabled", nat_traversal_enabled); |
279 channel_->SendMessage(message.PassAs<base::Value>()); | 279 channel_->SendMessage(message.Pass()); |
280 } | 280 } |
281 | 281 |
282 // Stores the Access Code for the web-app to query. | 282 // Stores the Access Code for the web-app to query. |
283 void It2MeNativeMessagingHost::OnStoreAccessCode( | 283 void It2MeNativeMessagingHost::OnStoreAccessCode( |
284 const std::string& access_code, | 284 const std::string& access_code, |
285 base::TimeDelta access_code_lifetime) { | 285 base::TimeDelta access_code_lifetime) { |
286 DCHECK(task_runner()->BelongsToCurrentThread()); | 286 DCHECK(task_runner()->BelongsToCurrentThread()); |
287 | 287 |
288 access_code_ = access_code; | 288 access_code_ = access_code; |
289 access_code_lifetime_ = access_code_lifetime; | 289 access_code_lifetime_ = access_code_lifetime; |
(...skipping 13 matching lines...) Expand all Loading... |
303 } | 303 } |
304 | 304 |
305 /* static */ | 305 /* static */ |
306 std::string It2MeNativeMessagingHost::HostStateToString( | 306 std::string It2MeNativeMessagingHost::HostStateToString( |
307 It2MeHostState host_state) { | 307 It2MeHostState host_state) { |
308 return ValueToName(kIt2MeHostStates, host_state); | 308 return ValueToName(kIt2MeHostStates, host_state); |
309 } | 309 } |
310 | 310 |
311 } // namespace remoting | 311 } // namespace remoting |
312 | 312 |
OLD | NEW |