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/setup/me2me_native_messaging_host.h" | 5 #include "remoting/host/setup/me2me_native_messaging_host.h" |
6 #include <sstream> | |
Sergey Ulanov
2015/08/08 00:57:09
don't need this include.
nit: add an empty line he
| |
6 #include <string> | 7 #include <string> |
7 | 8 |
8 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/strings/stringize_macros.h" | 15 #include "base/strings/stringize_macros.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 DCHECK(!quit_closure.is_null()); | 101 DCHECK(!quit_closure.is_null()); |
101 | 102 |
102 quit_closure_ = quit_closure; | 103 quit_closure_ = quit_closure; |
103 | 104 |
104 channel_->Start(this); | 105 channel_->Start(this); |
105 } | 106 } |
106 | 107 |
107 void Me2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) { | 108 void Me2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) { |
108 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
109 | 110 |
111 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | |
112 | |
110 if (!message->IsType(base::Value::TYPE_DICTIONARY)) { | 113 if (!message->IsType(base::Value::TYPE_DICTIONARY)) { |
111 LOG(ERROR) << "Received a message that's not a dictionary."; | 114 std::string error_message = "Received a message that's not a dictionary."; |
112 channel_->SendMessage(nullptr); | 115 LOG(ERROR) << error_message; |
116 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
113 return; | 117 return; |
114 } | 118 } |
115 | 119 |
116 scoped_ptr<base::DictionaryValue> message_dict( | 120 scoped_ptr<base::DictionaryValue> message_dict( |
117 static_cast<base::DictionaryValue*>(message.release())); | 121 static_cast<base::DictionaryValue*>(message.release())); |
118 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 122 std::string type; |
123 if (!message_dict->GetString("type", &type)) { | |
124 std::string error_message = "'type' not found"; | |
125 LOG(ERROR) << error_message; | |
126 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
127 return; | |
128 } | |
129 | |
130 // Message response types are just the message type with "Response" appended. | |
131 response->SetString("type", type + "Response"); | |
119 | 132 |
120 // If the client supplies an ID, it will expect it in the response. This | 133 // If the client supplies an ID, it will expect it in the response. This |
121 // might be a string or a number, so cope with both. | 134 // might be a string or a number, so cope with both. |
122 const base::Value* id; | 135 const base::Value* id; |
123 if (message_dict->Get("id", &id)) | 136 if (message_dict->Get("id", &id)) |
124 response->Set("id", id->DeepCopy()); | 137 response->Set("id", id->DeepCopy()); |
125 | 138 |
126 std::string type; | |
127 if (!message_dict->GetString("type", &type)) { | |
128 LOG(ERROR) << "'type' not found"; | |
129 channel_->SendMessage(nullptr); | |
130 return; | |
131 } | |
132 | |
133 response->SetString("type", type + "Response"); | |
134 | |
135 if (type == "hello") { | 139 if (type == "hello") { |
136 ProcessHello(message_dict.Pass(), response.Pass()); | 140 ProcessHello(message_dict.Pass(), response.Pass()); |
137 } else if (type == "clearPairedClients") { | 141 } else if (type == "clearPairedClients") { |
138 ProcessClearPairedClients(message_dict.Pass(), response.Pass()); | 142 ProcessClearPairedClients(message_dict.Pass(), response.Pass()); |
139 } else if (type == "deletePairedClient") { | 143 } else if (type == "deletePairedClient") { |
140 ProcessDeletePairedClient(message_dict.Pass(), response.Pass()); | 144 ProcessDeletePairedClient(message_dict.Pass(), response.Pass()); |
141 } else if (type == "getHostName") { | 145 } else if (type == "getHostName") { |
142 ProcessGetHostName(message_dict.Pass(), response.Pass()); | 146 ProcessGetHostName(message_dict.Pass(), response.Pass()); |
143 } else if (type == "getPinHash") { | 147 } else if (type == "getPinHash") { |
144 ProcessGetPinHash(message_dict.Pass(), response.Pass()); | 148 ProcessGetPinHash(message_dict.Pass(), response.Pass()); |
(...skipping 15 matching lines...) Expand all Loading... | |
160 ProcessGetDaemonState(message_dict.Pass(), response.Pass()); | 164 ProcessGetDaemonState(message_dict.Pass(), response.Pass()); |
161 } else if (type == "getHostClientId") { | 165 } else if (type == "getHostClientId") { |
162 ProcessGetHostClientId(message_dict.Pass(), response.Pass()); | 166 ProcessGetHostClientId(message_dict.Pass(), response.Pass()); |
163 } else if (type == "getCredentialsFromAuthCode") { | 167 } else if (type == "getCredentialsFromAuthCode") { |
164 ProcessGetCredentialsFromAuthCode( | 168 ProcessGetCredentialsFromAuthCode( |
165 message_dict.Pass(), response.Pass(), true); | 169 message_dict.Pass(), response.Pass(), true); |
166 } else if (type == "getRefreshTokenFromAuthCode") { | 170 } else if (type == "getRefreshTokenFromAuthCode") { |
167 ProcessGetCredentialsFromAuthCode( | 171 ProcessGetCredentialsFromAuthCode( |
168 message_dict.Pass(), response.Pass(), false); | 172 message_dict.Pass(), response.Pass(), false); |
169 } else { | 173 } else { |
170 LOG(ERROR) << "Unsupported request type: " << type; | 174 std::string error_message = "Unsupported request type: " + type; |
171 OnError(); | 175 LOG(ERROR) << error_message; |
176 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
172 } | 177 } |
173 } | 178 } |
174 | 179 |
175 void Me2MeNativeMessagingHost::OnDisconnect() { | 180 void Me2MeNativeMessagingHost::OnDisconnect() { |
176 if (!quit_closure_.is_null()) | 181 if (!quit_closure_.is_null()) |
177 base::ResetAndReturn(&quit_closure_).Run(); | 182 base::ResetAndReturn(&quit_closure_).Run(); |
178 } | 183 } |
179 | 184 |
180 void Me2MeNativeMessagingHost::ProcessHello( | 185 void Me2MeNativeMessagingHost::ProcessHello( |
181 scoped_ptr<base::DictionaryValue> message, | 186 scoped_ptr<base::DictionaryValue> message, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 222 |
218 if (needs_elevation_) { | 223 if (needs_elevation_) { |
219 if (!DelegateToElevatedHost(message.Pass())) | 224 if (!DelegateToElevatedHost(message.Pass())) |
220 SendBooleanResult(response.Pass(), false); | 225 SendBooleanResult(response.Pass(), false); |
221 return; | 226 return; |
222 } | 227 } |
223 | 228 |
224 std::string client_id; | 229 std::string client_id; |
225 if (!message->GetString(protocol::PairingRegistry::kClientIdKey, | 230 if (!message->GetString(protocol::PairingRegistry::kClientIdKey, |
226 &client_id)) { | 231 &client_id)) { |
227 LOG(ERROR) << "'" << protocol::PairingRegistry::kClientIdKey | 232 std::string error_message = std::string("'") + |
228 << "' string not found."; | 233 protocol::PairingRegistry::kClientIdKey + "' string not found"; |
229 OnError(); | 234 LOG(ERROR) << error_message; |
235 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
230 return; | 236 return; |
231 } | 237 } |
232 | 238 |
233 if (pairing_registry_.get()) { | 239 if (pairing_registry_.get()) { |
234 pairing_registry_->DeletePairing( | 240 pairing_registry_->DeletePairing( |
235 client_id, base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, | 241 client_id, base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, |
236 weak_ptr_, base::Passed(&response))); | 242 weak_ptr_, base::Passed(&response))); |
237 } else { | 243 } else { |
238 SendBooleanResult(response.Pass(), false); | 244 SendBooleanResult(response.Pass(), false); |
239 } | 245 } |
240 } | 246 } |
241 | 247 |
242 void Me2MeNativeMessagingHost::ProcessGetHostName( | 248 void Me2MeNativeMessagingHost::ProcessGetHostName( |
243 scoped_ptr<base::DictionaryValue> message, | 249 scoped_ptr<base::DictionaryValue> message, |
244 scoped_ptr<base::DictionaryValue> response) { | 250 scoped_ptr<base::DictionaryValue> response) { |
245 DCHECK(thread_checker_.CalledOnValidThread()); | 251 DCHECK(thread_checker_.CalledOnValidThread()); |
246 | 252 |
247 response->SetString("hostname", net::GetHostName()); | 253 response->SetString("hostname", net::GetHostName()); |
248 channel_->SendMessage(response.Pass()); | 254 channel_->SendMessage(response.Pass()); |
249 } | 255 } |
250 | 256 |
251 void Me2MeNativeMessagingHost::ProcessGetPinHash( | 257 void Me2MeNativeMessagingHost::ProcessGetPinHash( |
252 scoped_ptr<base::DictionaryValue> message, | 258 scoped_ptr<base::DictionaryValue> message, |
253 scoped_ptr<base::DictionaryValue> response) { | 259 scoped_ptr<base::DictionaryValue> response) { |
254 DCHECK(thread_checker_.CalledOnValidThread()); | 260 DCHECK(thread_checker_.CalledOnValidThread()); |
255 | 261 |
256 std::string host_id; | 262 std::string host_id; |
257 if (!message->GetString("hostId", &host_id)) { | 263 if (!message->GetString("hostId", &host_id)) { |
258 LOG(ERROR) << "'hostId' not found: " << message; | 264 std::string error_message = "'hostId' not found"; |
259 OnError(); | 265 LOG(ERROR) << error_message; |
266 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
260 return; | 267 return; |
261 } | 268 } |
262 std::string pin; | 269 std::string pin; |
263 if (!message->GetString("pin", &pin)) { | 270 if (!message->GetString("pin", &pin)) { |
264 LOG(ERROR) << "'pin' not found: " << message; | 271 std::string error_message = "'pin' not found"; |
265 OnError(); | 272 LOG(ERROR) << error_message; |
273 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
266 return; | 274 return; |
267 } | 275 } |
268 response->SetString("hash", MakeHostPinHash(host_id, pin)); | 276 response->SetString("hash", MakeHostPinHash(host_id, pin)); |
269 channel_->SendMessage(response.Pass()); | 277 channel_->SendMessage(response.Pass()); |
270 } | 278 } |
271 | 279 |
272 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( | 280 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( |
273 scoped_ptr<base::DictionaryValue> message, | 281 scoped_ptr<base::DictionaryValue> message, |
274 scoped_ptr<base::DictionaryValue> response) { | 282 scoped_ptr<base::DictionaryValue> response) { |
275 DCHECK(thread_checker_.CalledOnValidThread()); | 283 DCHECK(thread_checker_.CalledOnValidThread()); |
276 | 284 |
277 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); | 285 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); |
278 response->SetString("privateKey", key_pair->ToString()); | 286 response->SetString("privateKey", key_pair->ToString()); |
279 response->SetString("publicKey", key_pair->GetPublicKey()); | 287 response->SetString("publicKey", key_pair->GetPublicKey()); |
280 channel_->SendMessage(response.Pass()); | 288 channel_->SendMessage(response.Pass()); |
281 } | 289 } |
282 | 290 |
283 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( | 291 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( |
284 scoped_ptr<base::DictionaryValue> message, | 292 scoped_ptr<base::DictionaryValue> message, |
285 scoped_ptr<base::DictionaryValue> response) { | 293 scoped_ptr<base::DictionaryValue> response) { |
286 DCHECK(thread_checker_.CalledOnValidThread()); | 294 DCHECK(thread_checker_.CalledOnValidThread()); |
287 | 295 |
288 if (needs_elevation_) { | 296 if (needs_elevation_) { |
289 if (!DelegateToElevatedHost(message.Pass())) | 297 if (!DelegateToElevatedHost(message.Pass())) { |
290 SendAsyncResult(response.Pass(), DaemonController::RESULT_FAILED); | 298 std::string error_message = "DelegateToElevatedHost failed"; |
299 LOG(ERROR) << error_message; | |
300 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
301 } | |
291 return; | 302 return; |
292 } | 303 } |
293 | 304 |
294 scoped_ptr<base::DictionaryValue> config_dict = | 305 scoped_ptr<base::DictionaryValue> config_dict = |
295 ConfigDictionaryFromMessage(message.Pass()); | 306 ConfigDictionaryFromMessage(message.Pass()); |
296 if (!config_dict) { | 307 if (!config_dict) { |
297 OnError(); | 308 std::string error_message = "No config dictionary in message"; |
309 LOG(ERROR) << error_message; | |
310 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
298 return; | 311 return; |
299 } | 312 } |
300 | 313 |
314 scoped_ptr<base::DictionaryValue> response_copy(response->CreateDeepCopy()); | |
301 daemon_controller_->UpdateConfig( | 315 daemon_controller_->UpdateConfig( |
302 config_dict.Pass(), | 316 config_dict.Pass(), |
303 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, | 317 base::Bind(&Me2MeNativeMessagingHost::SendAsyncSuccess, weak_ptr_, |
304 base::Passed(&response))); | 318 base::Passed(&response)), |
319 base::Bind(&Me2MeNativeMessagingHost::SendAsyncFailure, weak_ptr_, | |
320 base::Passed(&response_copy))); | |
305 } | 321 } |
306 | 322 |
307 void Me2MeNativeMessagingHost::ProcessGetDaemonConfig( | 323 void Me2MeNativeMessagingHost::ProcessGetDaemonConfig( |
308 scoped_ptr<base::DictionaryValue> message, | 324 scoped_ptr<base::DictionaryValue> message, |
309 scoped_ptr<base::DictionaryValue> response) { | 325 scoped_ptr<base::DictionaryValue> response) { |
310 DCHECK(thread_checker_.CalledOnValidThread()); | 326 DCHECK(thread_checker_.CalledOnValidThread()); |
311 | 327 |
312 daemon_controller_->GetConfig( | 328 daemon_controller_->GetConfig( |
313 base::Bind(&Me2MeNativeMessagingHost::SendConfigResponse, weak_ptr_, | 329 base::Bind(&Me2MeNativeMessagingHost::SendConfigResponse, weak_ptr_, |
314 base::Passed(&response))); | 330 base::Passed(&response))); |
(...skipping 23 matching lines...) Expand all Loading... | |
338 base::Bind(&Me2MeNativeMessagingHost::SendUsageStatsConsentResponse, | 354 base::Bind(&Me2MeNativeMessagingHost::SendUsageStatsConsentResponse, |
339 weak_ptr_, base::Passed(&response))); | 355 weak_ptr_, base::Passed(&response))); |
340 } | 356 } |
341 | 357 |
342 void Me2MeNativeMessagingHost::ProcessStartDaemon( | 358 void Me2MeNativeMessagingHost::ProcessStartDaemon( |
343 scoped_ptr<base::DictionaryValue> message, | 359 scoped_ptr<base::DictionaryValue> message, |
344 scoped_ptr<base::DictionaryValue> response) { | 360 scoped_ptr<base::DictionaryValue> response) { |
345 DCHECK(thread_checker_.CalledOnValidThread()); | 361 DCHECK(thread_checker_.CalledOnValidThread()); |
346 | 362 |
347 if (needs_elevation_) { | 363 if (needs_elevation_) { |
348 if (!DelegateToElevatedHost(message.Pass())) | 364 if (!DelegateToElevatedHost(message.Pass())) { |
349 SendAsyncResult(response.Pass(), DaemonController::RESULT_FAILED); | 365 std::string error_message = "DelegateToElevatedHost failed"; |
366 LOG(ERROR) << error_message; | |
367 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
368 } | |
350 return; | 369 return; |
351 } | 370 } |
352 | 371 |
353 bool consent; | 372 bool consent; |
354 if (!message->GetBoolean("consent", &consent)) { | 373 if (!message->GetBoolean("consent", &consent)) { |
355 LOG(ERROR) << "'consent' not found."; | 374 std::string error_message = "'consent' not found"; |
356 OnError(); | 375 LOG(ERROR) << error_message; |
376 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
357 return; | 377 return; |
358 } | 378 } |
359 | 379 |
360 scoped_ptr<base::DictionaryValue> config_dict = | 380 scoped_ptr<base::DictionaryValue> config_dict = |
361 ConfigDictionaryFromMessage(message.Pass()); | 381 ConfigDictionaryFromMessage(message.Pass()); |
362 if (!config_dict) { | 382 if (!config_dict) { |
363 OnError(); | 383 std::string error_message = "No config dictionary in message"; |
384 LOG(ERROR) << error_message; | |
385 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
364 return; | 386 return; |
365 } | 387 } |
366 | 388 |
389 scoped_ptr<base::DictionaryValue> response_copy(response->CreateDeepCopy()); | |
367 daemon_controller_->SetConfigAndStart( | 390 daemon_controller_->SetConfigAndStart( |
368 config_dict.Pass(), consent, | 391 config_dict.Pass(), consent, |
369 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, | 392 base::Bind(&Me2MeNativeMessagingHost::SendAsyncSuccess, weak_ptr_, |
370 base::Passed(&response))); | 393 base::Passed(&response)), |
394 base::Bind(&Me2MeNativeMessagingHost::SendAsyncFailure, weak_ptr_, | |
395 base::Passed(&response_copy))); | |
371 } | 396 } |
372 | 397 |
373 void Me2MeNativeMessagingHost::ProcessStopDaemon( | 398 void Me2MeNativeMessagingHost::ProcessStopDaemon( |
374 scoped_ptr<base::DictionaryValue> message, | 399 scoped_ptr<base::DictionaryValue> message, |
375 scoped_ptr<base::DictionaryValue> response) { | 400 scoped_ptr<base::DictionaryValue> response) { |
376 DCHECK(thread_checker_.CalledOnValidThread()); | 401 DCHECK(thread_checker_.CalledOnValidThread()); |
377 | 402 |
378 if (needs_elevation_) { | 403 if (needs_elevation_) { |
379 if (!DelegateToElevatedHost(message.Pass())) | 404 if (!DelegateToElevatedHost(message.Pass())) { |
380 SendAsyncResult(response.Pass(), DaemonController::RESULT_FAILED); | 405 std::string error_message = "DelegateToElevatedHost failed"; |
406 LOG(ERROR) << error_message; | |
407 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
408 } | |
381 return; | 409 return; |
382 } | 410 } |
383 | 411 |
412 scoped_ptr<base::DictionaryValue> response_copy(response->CreateDeepCopy()); | |
384 daemon_controller_->Stop( | 413 daemon_controller_->Stop( |
385 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, | 414 base::Bind(&Me2MeNativeMessagingHost::SendAsyncSuccess, weak_ptr_, |
386 base::Passed(&response))); | 415 base::Passed(&response)), |
416 base::Bind(&Me2MeNativeMessagingHost::SendAsyncFailure, weak_ptr_, | |
417 base::Passed(&response_copy))); | |
387 } | 418 } |
388 | 419 |
389 void Me2MeNativeMessagingHost::ProcessGetDaemonState( | 420 void Me2MeNativeMessagingHost::ProcessGetDaemonState( |
390 scoped_ptr<base::DictionaryValue> message, | 421 scoped_ptr<base::DictionaryValue> message, |
391 scoped_ptr<base::DictionaryValue> response) { | 422 scoped_ptr<base::DictionaryValue> response) { |
392 DCHECK(thread_checker_.CalledOnValidThread()); | 423 DCHECK(thread_checker_.CalledOnValidThread()); |
393 | 424 |
394 DaemonController::State state = daemon_controller_->GetState(); | 425 DaemonController::State state = daemon_controller_->GetState(); |
395 switch (state) { | 426 switch (state) { |
396 case DaemonController::STATE_NOT_IMPLEMENTED: | 427 case DaemonController::STATE_NOT_IMPLEMENTED: |
(...skipping 29 matching lines...) Expand all Loading... | |
426 } | 457 } |
427 | 458 |
428 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( | 459 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( |
429 scoped_ptr<base::DictionaryValue> message, | 460 scoped_ptr<base::DictionaryValue> message, |
430 scoped_ptr<base::DictionaryValue> response, | 461 scoped_ptr<base::DictionaryValue> response, |
431 bool need_user_email) { | 462 bool need_user_email) { |
432 DCHECK(thread_checker_.CalledOnValidThread()); | 463 DCHECK(thread_checker_.CalledOnValidThread()); |
433 | 464 |
434 std::string auth_code; | 465 std::string auth_code; |
435 if (!message->GetString("authorizationCode", &auth_code)) { | 466 if (!message->GetString("authorizationCode", &auth_code)) { |
436 LOG(ERROR) << "'authorizationCode' string not found."; | 467 std::string error_message = "'authorizationCode' string not found"; |
437 OnError(); | 468 LOG(ERROR) << error_message; |
469 SendAsyncFailure(response.Pass(), error_message, FROM_HERE); | |
438 return; | 470 return; |
439 } | 471 } |
440 | 472 |
441 gaia::OAuthClientInfo oauth_client_info = { | 473 gaia::OAuthClientInfo oauth_client_info = { |
442 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST), | 474 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST), |
443 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST), | 475 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST), |
444 kServiceAccountRedirectUri | 476 kServiceAccountRedirectUri |
445 }; | 477 }; |
446 | 478 |
447 oauth_client_->GetCredentialsFromAuthCode( | 479 oauth_client_->GetCredentialsFromAuthCode( |
(...skipping 28 matching lines...) Expand all Loading... | |
476 scoped_ptr<base::DictionaryValue> response, | 508 scoped_ptr<base::DictionaryValue> response, |
477 const DaemonController::UsageStatsConsent& consent) { | 509 const DaemonController::UsageStatsConsent& consent) { |
478 DCHECK(thread_checker_.CalledOnValidThread()); | 510 DCHECK(thread_checker_.CalledOnValidThread()); |
479 | 511 |
480 response->SetBoolean("supported", consent.supported); | 512 response->SetBoolean("supported", consent.supported); |
481 response->SetBoolean("allowed", consent.allowed); | 513 response->SetBoolean("allowed", consent.allowed); |
482 response->SetBoolean("setByPolicy", consent.set_by_policy); | 514 response->SetBoolean("setByPolicy", consent.set_by_policy); |
483 channel_->SendMessage(response.Pass()); | 515 channel_->SendMessage(response.Pass()); |
484 } | 516 } |
485 | 517 |
486 void Me2MeNativeMessagingHost::SendAsyncResult( | 518 void Me2MeNativeMessagingHost::SendAsyncSuccess( |
487 scoped_ptr<base::DictionaryValue> response, | 519 scoped_ptr<base::DictionaryValue> response) { |
488 DaemonController::AsyncResult result) { | |
489 DCHECK(thread_checker_.CalledOnValidThread()); | 520 DCHECK(thread_checker_.CalledOnValidThread()); |
490 | 521 |
491 switch (result) { | 522 response->SetString("result", "OK"); |
492 case DaemonController::RESULT_OK: | |
493 response->SetString("result", "OK"); | |
494 break; | |
495 case DaemonController::RESULT_FAILED: | |
496 response->SetString("result", "FAILED"); | |
497 break; | |
498 case DaemonController::RESULT_CANCELLED: | |
499 response->SetString("result", "CANCELLED"); | |
Sergey Ulanov
2015/08/08 00:57:09
Do we still send "CANCELLED" response? I think it
Jamie
2015/08/11 21:23:13
I've reverted this change, but FWIW I don't think
| |
500 break; | |
501 case DaemonController::RESULT_FAILED_DIRECTORY: | |
502 response->SetString("result", "FAILED_DIRECTORY"); | |
503 break; | |
504 } | |
505 channel_->SendMessage(response.Pass()); | 523 channel_->SendMessage(response.Pass()); |
506 } | 524 } |
507 | 525 |
526 void Me2MeNativeMessagingHost::SendAsyncFailure( | |
527 scoped_ptr<base::DictionaryValue> response, | |
528 const std::string& error_message, | |
529 const tracked_objects::Location& location) { | |
530 DCHECK(thread_checker_.CalledOnValidThread()); | |
531 | |
532 response->SetString("result", "FAILED"); | |
533 response->SetString("error_message", error_message); | |
534 response->SetString("error_location", location.ToString()); | |
535 channel_->SendMessage(response.Pass()); | |
536 } | |
537 | |
508 void Me2MeNativeMessagingHost::SendBooleanResult( | 538 void Me2MeNativeMessagingHost::SendBooleanResult( |
509 scoped_ptr<base::DictionaryValue> response, bool result) { | 539 scoped_ptr<base::DictionaryValue> response, bool result) { |
510 DCHECK(thread_checker_.CalledOnValidThread()); | 540 DCHECK(thread_checker_.CalledOnValidThread()); |
511 | 541 |
512 response->SetBoolean("result", result); | 542 response->SetBoolean("result", result); |
513 channel_->SendMessage(response.Pass()); | 543 channel_->SendMessage(response.Pass()); |
514 } | 544 } |
515 | 545 |
516 void Me2MeNativeMessagingHost::SendCredentialsResponse( | 546 void Me2MeNativeMessagingHost::SendCredentialsResponse( |
517 scoped_ptr<base::DictionaryValue> response, | 547 scoped_ptr<base::DictionaryValue> response, |
518 const std::string& user_email, | 548 const std::string& user_email, |
519 const std::string& refresh_token) { | 549 const std::string& refresh_token) { |
520 DCHECK(thread_checker_.CalledOnValidThread()); | 550 DCHECK(thread_checker_.CalledOnValidThread()); |
521 | 551 |
522 if (!user_email.empty()) { | 552 if (!user_email.empty()) { |
523 response->SetString("userEmail", user_email); | 553 response->SetString("userEmail", user_email); |
524 } | 554 } |
525 response->SetString("refreshToken", refresh_token); | 555 response->SetString("refreshToken", refresh_token); |
526 channel_->SendMessage(response.Pass()); | 556 channel_->SendMessage(response.Pass()); |
527 } | 557 } |
528 | 558 |
529 void Me2MeNativeMessagingHost::OnError() { | |
530 // Trigger a host shutdown by sending a nullptr message. | |
531 channel_->SendMessage(nullptr); | |
532 } | |
533 | |
534 void Me2MeNativeMessagingHost::Stop() { | 559 void Me2MeNativeMessagingHost::Stop() { |
535 DCHECK(thread_checker_.CalledOnValidThread()); | 560 DCHECK(thread_checker_.CalledOnValidThread()); |
536 | 561 |
537 if (!quit_closure_.is_null()) | 562 if (!quit_closure_.is_null()) |
538 base::ResetAndReturn(&quit_closure_).Run(); | 563 base::ResetAndReturn(&quit_closure_).Run(); |
539 } | 564 } |
540 | 565 |
541 #if defined(OS_WIN) | 566 #if defined(OS_WIN) |
542 Me2MeNativeMessagingHost::ElevatedChannelEventHandler:: | 567 Me2MeNativeMessagingHost::ElevatedChannelEventHandler:: |
543 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host) | 568 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 | 760 |
736 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( | 761 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( |
737 scoped_ptr<base::DictionaryValue> message) { | 762 scoped_ptr<base::DictionaryValue> message) { |
738 NOTREACHED(); | 763 NOTREACHED(); |
739 return false; | 764 return false; |
740 } | 765 } |
741 | 766 |
742 #endif // !defined(OS_WIN) | 767 #endif // !defined(OS_WIN) |
743 | 768 |
744 } // namespace remoting | 769 } // namespace remoting |
OLD | NEW |