easy_unlock_private_api.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.h" 6 7#include <vector> 8 9#include "base/bind.h" 10#include "base/lazy_instance.h" 11#include "base/memory/linked_ptr.h" 12#include "base/strings/utf_string_conversions.h" 13#include "base/values.h" 14#include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_crypto_delegate.h" 15#include "chrome/browser/profiles/profile.h" 16#include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" 17#include "chrome/browser/signin/easy_unlock_service.h" 18#include "chrome/common/extensions/api/easy_unlock_private.h" 19#include "chrome/grit/generated_resources.h" 20#include "components/proximity_auth/bluetooth_util.h" 21#include "content/public/browser/browser_thread.h" 22#include "extensions/browser/browser_context_keyed_api_factory.h" 23#include "ui/base/l10n/l10n_util.h" 24 25#if defined(OS_CHROMEOS) 26#include "chrome/browser/chromeos/chromeos_utils.h" 27#include "components/user_manager/user.h" 28#include "components/user_manager/user_manager.h" 29#endif 30 31namespace extensions { 32namespace api { 33 34namespace { 35 36static base::LazyInstance<BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI> > 37 g_factory = LAZY_INSTANCE_INITIALIZER; 38 39// Utility method for getting the API's crypto delegate. 40EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate( 41 content::BrowserContext* context) { 42 return BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>::Get(context) 43 ->crypto_delegate(); 44} 45 46EasyUnlockScreenlockStateHandler::State ToScreenlockStateHandlerState( 47 easy_unlock_private::State state) { 48 switch (state) { 49 case easy_unlock_private::STATE_NO_BLUETOOTH: 50 return EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH; 51 case easy_unlock_private::STATE_BLUETOOTH_CONNECTING: 52 return EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; 53 case easy_unlock_private::STATE_NO_PHONE: 54 return EasyUnlockScreenlockStateHandler::STATE_NO_PHONE; 55 case easy_unlock_private::STATE_PHONE_NOT_AUTHENTICATED: 56 return EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED; 57 case easy_unlock_private::STATE_PHONE_LOCKED: 58 return EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED; 59 case easy_unlock_private::STATE_PHONE_UNLOCKABLE: 60 return EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE; 61 case easy_unlock_private::STATE_PHONE_NOT_NEARBY: 62 return EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY; 63 case easy_unlock_private::STATE_PHONE_UNSUPPORTED: 64 return EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; 65 case easy_unlock_private::STATE_AUTHENTICATED: 66 return EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED; 67 default: 68 return EasyUnlockScreenlockStateHandler::STATE_INACTIVE; 69 } 70} 71 72} // namespace 73 74// static 75BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>* 76 EasyUnlockPrivateAPI::GetFactoryInstance() { 77 return g_factory.Pointer(); 78} 79 80EasyUnlockPrivateAPI::EasyUnlockPrivateAPI(content::BrowserContext* context) 81 : crypto_delegate_(EasyUnlockPrivateCryptoDelegate::Create()) { 82} 83 84EasyUnlockPrivateAPI::~EasyUnlockPrivateAPI() {} 85 86EasyUnlockPrivateGetStringsFunction::EasyUnlockPrivateGetStringsFunction() { 87} 88EasyUnlockPrivateGetStringsFunction::~EasyUnlockPrivateGetStringsFunction() { 89} 90 91bool EasyUnlockPrivateGetStringsFunction::RunSync() { 92 scoped_ptr<base::DictionaryValue> strings(new base::DictionaryValue); 93 94#if defined(OS_CHROMEOS) 95 const base::string16 device_type = chromeos::GetChromeDeviceType(); 96#else 97 // TODO(isherman): Set an appropriate device name for non-ChromeOS devices. 98 const base::string16 device_type = base::ASCIIToUTF16("Chromeschnozzle"); 99#endif // defined(OS_CHROMEOS) 100 101#if defined(OS_CHROMEOS) 102 const user_manager::UserManager* manager = user_manager::UserManager::Get(); 103 const user_manager::User* user = manager ? manager->GetActiveUser() : NULL; 104 const std::string user_email_utf8 = 105 user ? user->display_email() : std::string(); 106 const base::string16 user_email = base::UTF8ToUTF16(user_email_utf8); 107#else 108 // TODO(isherman): Set an appropriate user display email for non-ChromeOS 109 // platforms. 110 const base::string16 user_email = base::UTF8ToUTF16("superman@example.com"); 111#endif // defined(OS_CHROMEOS) 112 113 // Common strings. 114 strings->SetString( 115 "learnMoreLinkTitle", 116 l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_LEARN_MORE_LINK_TITLE)); 117 118 // Setup notification strings. 119 strings->SetString( 120 "setupNotificationTitle", 121 l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SETUP_NOTIFICATION_TITLE, 122 device_type)); 123 strings->SetString( 124 "setupNotificationMessage", 125 l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SETUP_NOTIFICATION_MESSAGE, 126 device_type)); 127 strings->SetString( 128 "setupNotificationButtonTitle", 129 l10n_util::GetStringUTF16( 130 IDS_EASY_UNLOCK_SETUP_NOTIFICATION_BUTTON_TITLE)); 131 132 // Success notification strings. 133 strings->SetString( 134 "successNotificationTitle", 135 l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_SUCCESS_NOTIFICATION_TITLE)); 136 strings->SetString( 137 "successNotificationMessage", 138 l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SUCCESS_NOTIFICATION_MESSAGE, 139 device_type)); 140 141 // Chromebook added to Easy Unlock notification strings. 142 strings->SetString( 143 "chromebookAddedNotificationTitle", 144 l10n_util::GetStringUTF16( 145 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_TITLE)); 146 strings->SetString( 147 "chromebookAddedNotificationMessage", 148 l10n_util::GetStringFUTF16( 149 IDS_EASY_UNLOCK_CHROMEBOOK_ADDED_NOTIFICATION_MESSAGE, 150 device_type)); 151 152 // Setup dialog strings. 153 // Step 1: Intro. 154 strings->SetString( 155 "setupIntroHeaderTitle", 156 l10n_util::GetStringFUTF16( 157 IDS_EASY_UNLOCK_SETUP_INTRO_HEADER_TITLE, device_type)); 158 strings->SetString( 159 "setupIntroHeaderText", 160 l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SETUP_INTRO_HEADER_TEXT, 161 device_type, 162 user_email)); 163 strings->SetString( 164 "setupIntroFindPhoneButtonLabel", 165 l10n_util::GetStringUTF16( 166 IDS_EASY_UNLOCK_SETUP_INTRO_FIND_PHONE_BUTTON_LABEL)); 167 strings->SetString( 168 "setupIntroFindingPhoneButtonLabel", 169 l10n_util::GetStringUTF16( 170 IDS_EASY_UNLOCK_SETUP_INTRO_FINDING_PHONE_BUTTON_LABEL)); 171 strings->SetString( 172 "setupIntroRetryFindPhoneButtonLabel", 173 l10n_util::GetStringUTF16( 174 IDS_EASY_UNLOCK_SETUP_INTRO_RETRY_FIND_PHONE_BUTTON_LABEL)); 175 strings->SetString( 176 "setupIntroHowIsThisSecureLinkText", 177 l10n_util::GetStringUTF16( 178 IDS_EASY_UNLOCK_SETUP_INTRO_HOW_IS_THIS_SECURE_LINK_TEXT)); 179 // Step 2: Found a viable phone. 180 strings->SetString( 181 "setupFoundPhoneHeaderTitle", 182 l10n_util::GetStringFUTF16( 183 IDS_EASY_UNLOCK_SETUP_FOUND_PHONE_HEADER_TITLE, device_type)); 184 strings->SetString( 185 "setupFoundPhoneHeaderText", 186 l10n_util::GetStringFUTF16( 187 IDS_EASY_UNLOCK_SETUP_FOUND_PHONE_HEADER_TEXT, device_type)); 188 strings->SetString( 189 "setupFoundPhoneUseThisPhoneButtonLabel", 190 l10n_util::GetStringUTF16( 191 IDS_EASY_UNLOCK_SETUP_FOUND_PHONE_USE_THIS_PHONE_BUTTON_LABEL)); 192 strings->SetString( 193 "setupPairingPhoneFailedButtonLabel", 194 l10n_util::GetStringUTF16( 195 IDS_EASY_UNLOCK_SETUP_PAIRING_PHONE_FAILED_BUTTON_LABEL)); 196 // Step 3: Setup completed successfully. 197 strings->SetString( 198 "setupCompleteHeaderTitle", 199 l10n_util::GetStringUTF16( 200 IDS_EASY_UNLOCK_SETUP_COMPLETE_HEADER_TITLE)); 201 strings->SetString( 202 "setupCompleteHeaderText", 203 l10n_util::GetStringUTF16( 204 IDS_EASY_UNLOCK_SETUP_COMPLETE_HEADER_TEXT)); 205 strings->SetString( 206 "setupCompleteTryItOutButtonLabel", 207 l10n_util::GetStringUTF16( 208 IDS_EASY_UNLOCK_SETUP_COMPLETE_TRY_IT_OUT_BUTTON_LABEL)); 209 strings->SetString( 210 "setupCompleteSettingsLinkText", 211 l10n_util::GetStringUTF16( 212 IDS_EASY_UNLOCK_SETUP_COMPLETE_SETTINGS_LINK_TEXT)); 213 214 // Error strings. 215 strings->SetString( 216 "setupErrorBluetoothUnavailable", 217 l10n_util::GetStringFUTF16( 218 IDS_EASY_UNLOCK_SETUP_ERROR_BLUETOOTH_UNAVAILBLE, device_type)); 219 strings->SetString( 220 "setupErrorOffline", 221 l10n_util::GetStringFUTF16( 222 IDS_EASY_UNLOCK_SETUP_ERROR_OFFLINE, device_type)); 223 strings->SetString( 224 "setupErrorFindingPhone", 225 l10n_util::GetStringUTF16(IDS_EASY_UNLOCK_SETUP_ERROR_FINDING_PHONE)); 226 strings->SetString( 227 "setupErrorBluetoothConnectionFailed", 228 l10n_util::GetStringFUTF16( 229 IDS_EASY_UNLOCK_SETUP_ERROR_BLUETOOTH_CONNECTION_FAILED, 230 device_type)); 231 strings->SetString( 232 "setupErrorConnectionToPhoneTimeout", 233 l10n_util::GetStringFUTF16( 234 IDS_EASY_UNLOCK_SETUP_ERROR_CONNECT_TO_PHONE_TIMEOUT, 235 device_type)); 236 strings->SetString( 237 "setupErrorSyncPhoneState", 238 l10n_util::GetStringUTF16( 239 IDS_EASY_UNLOCK_SETUP_ERROR_SYNC_PHONE_STATE_FAILED)); 240 strings->SetString( 241 "setupErrorConnectingToPhone", 242 l10n_util::GetStringFUTF16( 243 IDS_EASY_UNLOCK_SETUP_ERROR_CONNECTING_TO_PHONE, device_type)); 244 245 // TODO(isherman): Remove this string once the app has been updated. 246 strings->SetString("setupIntroHeaderFootnote", base::string16()); 247 248 SetResult(strings.release()); 249 return true; 250} 251 252EasyUnlockPrivatePerformECDHKeyAgreementFunction:: 253EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} 254 255EasyUnlockPrivatePerformECDHKeyAgreementFunction:: 256~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} 257 258bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { 259 scoped_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params = 260 easy_unlock_private::PerformECDHKeyAgreement::Params::Create(*args_); 261 EXTENSION_FUNCTION_VALIDATE(params); 262 263 GetCryptoDelegate(browser_context())->PerformECDHKeyAgreement( 264 *params, 265 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, 266 this)); 267 return true; 268} 269 270void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( 271 const std::string& secret_key) { 272 // TODO(tbarzic): Improve error handling. 273 if (!secret_key.empty()) { 274 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( 275 secret_key); 276 } 277 SendResponse(true); 278} 279 280EasyUnlockPrivateGenerateEcP256KeyPairFunction:: 281EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} 282 283EasyUnlockPrivateGenerateEcP256KeyPairFunction:: 284~EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} 285 286bool EasyUnlockPrivateGenerateEcP256KeyPairFunction::RunAsync() { 287 GetCryptoDelegate(browser_context())->GenerateEcP256KeyPair( 288 base::Bind(&EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData, 289 this)); 290 return true; 291} 292 293void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData( 294 const std::string& private_key, 295 const std::string& public_key) { 296 // TODO(tbarzic): Improve error handling. 297 if (!public_key.empty() && !private_key.empty()) { 298 results_ = easy_unlock_private::GenerateEcP256KeyPair::Results::Create( 299 public_key, private_key); 300 } 301 SendResponse(true); 302} 303 304EasyUnlockPrivateCreateSecureMessageFunction:: 305EasyUnlockPrivateCreateSecureMessageFunction() {} 306 307EasyUnlockPrivateCreateSecureMessageFunction:: 308~EasyUnlockPrivateCreateSecureMessageFunction() {} 309 310bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { 311 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params = 312 easy_unlock_private::CreateSecureMessage::Params::Create(*args_); 313 EXTENSION_FUNCTION_VALIDATE(params); 314 315 GetCryptoDelegate(browser_context())->CreateSecureMessage( 316 *params, 317 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, 318 this)); 319 return true; 320} 321 322void EasyUnlockPrivateCreateSecureMessageFunction::OnData( 323 const std::string& message) { 324 // TODO(tbarzic): Improve error handling. 325 if (!message.empty()) { 326 results_ = easy_unlock_private::CreateSecureMessage::Results::Create( 327 message); 328 } 329 SendResponse(true); 330} 331 332EasyUnlockPrivateUnwrapSecureMessageFunction:: 333EasyUnlockPrivateUnwrapSecureMessageFunction() {} 334 335EasyUnlockPrivateUnwrapSecureMessageFunction:: 336~EasyUnlockPrivateUnwrapSecureMessageFunction() {} 337 338bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { 339 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = 340 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); 341 EXTENSION_FUNCTION_VALIDATE(params); 342 343 GetCryptoDelegate(browser_context())->UnwrapSecureMessage( 344 *params, 345 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, 346 this)); 347 return true; 348} 349 350void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( 351 const std::string& data) { 352 // TODO(tbarzic): Improve error handling. 353 if (!data.empty()) 354 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create(data); 355 SendResponse(true); 356} 357 358EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction:: 359 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {} 360 361EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction:: 362 ~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() {} 363 364bool EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::RunAsync() { 365 scoped_ptr<easy_unlock_private::SeekBluetoothDeviceByAddress::Params> params( 366 easy_unlock_private::SeekBluetoothDeviceByAddress::Params::Create( 367 *args_)); 368 EXTENSION_FUNCTION_VALIDATE(params.get()); 369 370 proximity_auth::bluetooth_util::SeekDeviceByAddress( 371 params->device_address, 372 base::Bind( 373 &EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekSuccess, 374 this), 375 base::Bind( 376 &EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekFailure, 377 this), 378 content::BrowserThread::GetBlockingPool()); 379 return true; 380} 381 382void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekSuccess() { 383 SendResponse(true); 384} 385 386void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekFailure( 387 const std::string& error_message) { 388 SetError(error_message); 389 SendResponse(false); 390} 391 392EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: 393 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() {} 394 395EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: 396 ~EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() {} 397 398void EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: 399 ConnectToService(device::BluetoothDevice* device, 400 const device::BluetoothUUID& uuid) { 401 proximity_auth::bluetooth_util::ConnectToServiceInsecurely( 402 device, 403 uuid, 404 base::Bind(&EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: 405 OnConnect, 406 this), 407 base::Bind(&EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: 408 OnConnectError, 409 this)); 410} 411 412EasyUnlockPrivateUpdateScreenlockStateFunction:: 413 EasyUnlockPrivateUpdateScreenlockStateFunction() {} 414 415EasyUnlockPrivateUpdateScreenlockStateFunction:: 416 ~EasyUnlockPrivateUpdateScreenlockStateFunction() {} 417 418bool EasyUnlockPrivateUpdateScreenlockStateFunction::RunSync() { 419 scoped_ptr<easy_unlock_private::UpdateScreenlockState::Params> params( 420 easy_unlock_private::UpdateScreenlockState::Params::Create(*args_)); 421 EXTENSION_FUNCTION_VALIDATE(params.get()); 422 423 Profile* profile = Profile::FromBrowserContext(browser_context()); 424 if (EasyUnlockService::Get(profile)->UpdateScreenlockState( 425 ToScreenlockStateHandlerState(params->state))) 426 return true; 427 428 SetError("Not allowed"); 429 return false; 430} 431 432EasyUnlockPrivateSetPermitAccessFunction:: 433 EasyUnlockPrivateSetPermitAccessFunction() { 434} 435 436EasyUnlockPrivateSetPermitAccessFunction:: 437 ~EasyUnlockPrivateSetPermitAccessFunction() { 438} 439 440bool EasyUnlockPrivateSetPermitAccessFunction::RunSync() { 441 scoped_ptr<easy_unlock_private::SetPermitAccess::Params> params( 442 easy_unlock_private::SetPermitAccess::Params::Create(*args_)); 443 EXTENSION_FUNCTION_VALIDATE(params.get()); 444 445 Profile* profile = Profile::FromBrowserContext(browser_context()); 446 EasyUnlockService::Get(profile) 447 ->SetPermitAccess(*params->permit_access.ToValue()); 448 449 return true; 450} 451 452EasyUnlockPrivateGetPermitAccessFunction:: 453 EasyUnlockPrivateGetPermitAccessFunction() { 454} 455 456EasyUnlockPrivateGetPermitAccessFunction:: 457 ~EasyUnlockPrivateGetPermitAccessFunction() { 458} 459 460bool EasyUnlockPrivateGetPermitAccessFunction::RunSync() { 461 Profile* profile = Profile::FromBrowserContext(browser_context()); 462 const base::DictionaryValue* permit_value = 463 EasyUnlockService::Get(profile)->GetPermitAccess(); 464 if (permit_value) { 465 scoped_ptr<easy_unlock_private::PermitRecord> permit = 466 easy_unlock_private::PermitRecord::FromValue(*permit_value); 467 results_ = easy_unlock_private::GetPermitAccess::Results::Create(*permit); 468 } 469 470 return true; 471} 472 473EasyUnlockPrivateClearPermitAccessFunction:: 474 EasyUnlockPrivateClearPermitAccessFunction() { 475} 476 477EasyUnlockPrivateClearPermitAccessFunction:: 478 ~EasyUnlockPrivateClearPermitAccessFunction() { 479} 480 481bool EasyUnlockPrivateClearPermitAccessFunction::RunSync() { 482 Profile* profile = Profile::FromBrowserContext(browser_context()); 483 EasyUnlockService::Get(profile)->ClearPermitAccess(); 484 return true; 485} 486 487EasyUnlockPrivateSetRemoteDevicesFunction:: 488 EasyUnlockPrivateSetRemoteDevicesFunction() { 489} 490 491EasyUnlockPrivateSetRemoteDevicesFunction:: 492 ~EasyUnlockPrivateSetRemoteDevicesFunction() { 493} 494 495bool EasyUnlockPrivateSetRemoteDevicesFunction::RunSync() { 496 scoped_ptr<easy_unlock_private::SetRemoteDevices::Params> params( 497 easy_unlock_private::SetRemoteDevices::Params::Create(*args_)); 498 EXTENSION_FUNCTION_VALIDATE(params.get()); 499 500 Profile* profile = Profile::FromBrowserContext(browser_context()); 501 if (params->devices.empty()) { 502 EasyUnlockService::Get(profile)->ClearRemoteDevices(); 503 } else { 504 base::ListValue devices; 505 for (size_t i = 0; i < params->devices.size(); ++i) { 506 devices.Append(params->devices[i]->ToValue().release()); 507 } 508 EasyUnlockService::Get(profile)->SetRemoteDevices(devices); 509 } 510 511 return true; 512} 513 514EasyUnlockPrivateGetRemoteDevicesFunction:: 515 EasyUnlockPrivateGetRemoteDevicesFunction() { 516} 517 518EasyUnlockPrivateGetRemoteDevicesFunction:: 519 ~EasyUnlockPrivateGetRemoteDevicesFunction() { 520} 521 522bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() { 523 Profile* profile = Profile::FromBrowserContext(browser_context()); 524 const base::ListValue* devices = 525 EasyUnlockService::Get(profile)->GetRemoteDevices(); 526 SetResult(devices ? devices->DeepCopy() : new base::ListValue()); 527 return true; 528} 529 530EasyUnlockPrivateGetSignInChallengeFunction:: 531 EasyUnlockPrivateGetSignInChallengeFunction() { 532} 533 534EasyUnlockPrivateGetSignInChallengeFunction:: 535 ~EasyUnlockPrivateGetSignInChallengeFunction() { 536} 537 538bool EasyUnlockPrivateGetSignInChallengeFunction::RunSync() { 539 Profile* profile = Profile::FromBrowserContext(browser_context()); 540 const std::string challenge = 541 EasyUnlockService::Get(profile)->GetChallenge(); 542 if (!challenge.empty()) { 543 results_ = 544 easy_unlock_private::GetSignInChallenge::Results::Create(challenge); 545 } 546 return true; 547} 548 549EasyUnlockPrivateTrySignInSecretFunction:: 550 EasyUnlockPrivateTrySignInSecretFunction() { 551} 552 553EasyUnlockPrivateTrySignInSecretFunction:: 554 ~EasyUnlockPrivateTrySignInSecretFunction() { 555} 556 557bool EasyUnlockPrivateTrySignInSecretFunction::RunSync() { 558 scoped_ptr<easy_unlock_private::TrySignInSecret::Params> params( 559 easy_unlock_private::TrySignInSecret::Params::Create(*args_)); 560 EXTENSION_FUNCTION_VALIDATE(params.get()); 561 562 Profile* profile = Profile::FromBrowserContext(browser_context()); 563 EasyUnlockService::Get(profile)->FinalizeSignin(params->sign_in_secret); 564 return true; 565} 566 567EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { 568} 569 570EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { 571} 572 573bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { 574 EasyUnlockService* service = 575 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); 576 std::vector<linked_ptr<easy_unlock_private::UserInfo> > users; 577 std::string user_id = service->GetUserEmail(); 578 if (!user_id.empty()) { 579 users.push_back( 580 linked_ptr<easy_unlock_private::UserInfo>( 581 new easy_unlock_private::UserInfo())); 582 users[0]->user_id = user_id; 583 users[0]->logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR; 584 users[0]->data_ready = users[0]->logged_in || 585 service->GetRemoteDevices() != NULL; 586 } 587 results_ = easy_unlock_private::GetUserInfo::Results::Create(users); 588 return true; 589} 590 591} // namespace api 592} // namespace extensions 593