| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" | 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 static base::LazyInstance<BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI> > | 34 static base::LazyInstance<BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI> > |
| 35 g_factory = LAZY_INSTANCE_INITIALIZER; | 35 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 36 | 36 |
| 37 // Utility method for getting the API's crypto delegate. | 37 // Utility method for getting the API's crypto delegate. |
| 38 EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate( | 38 EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate( |
| 39 content::BrowserContext* context) { | 39 content::BrowserContext* context) { |
| 40 return BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>::Get(context) | 40 return BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>::Get(context) |
| 41 ->crypto_delegate(); | 41 ->crypto_delegate(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler( | |
| 45 content::BrowserContext* context) { | |
| 46 return EasyUnlockService::Get(Profile::FromBrowserContext(context)) | |
| 47 ->GetScreenlockStateHandler(); | |
| 48 } | |
| 49 | |
| 50 EasyUnlockScreenlockStateHandler::State ToScreenlockStateHandlerState( | 44 EasyUnlockScreenlockStateHandler::State ToScreenlockStateHandlerState( |
| 51 easy_unlock_private::State state) { | 45 easy_unlock_private::State state) { |
| 52 switch (state) { | 46 switch (state) { |
| 53 case easy_unlock_private::STATE_NO_BLUETOOTH: | 47 case easy_unlock_private::STATE_NO_BLUETOOTH: |
| 54 return EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH; | 48 return EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH; |
| 55 case easy_unlock_private::STATE_BLUETOOTH_CONNECTING: | 49 case easy_unlock_private::STATE_BLUETOOTH_CONNECTING: |
| 56 return EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; | 50 return EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; |
| 57 case easy_unlock_private::STATE_NO_PHONE: | 51 case easy_unlock_private::STATE_NO_PHONE: |
| 58 return EasyUnlockScreenlockStateHandler::STATE_NO_PHONE; | 52 return EasyUnlockScreenlockStateHandler::STATE_NO_PHONE; |
| 59 case easy_unlock_private::STATE_PHONE_NOT_AUTHENTICATED: | 53 case easy_unlock_private::STATE_PHONE_NOT_AUTHENTICATED: |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 EasyUnlockPrivateUpdateScreenlockStateFunction() {} | 413 EasyUnlockPrivateUpdateScreenlockStateFunction() {} |
| 420 | 414 |
| 421 EasyUnlockPrivateUpdateScreenlockStateFunction:: | 415 EasyUnlockPrivateUpdateScreenlockStateFunction:: |
| 422 ~EasyUnlockPrivateUpdateScreenlockStateFunction() {} | 416 ~EasyUnlockPrivateUpdateScreenlockStateFunction() {} |
| 423 | 417 |
| 424 bool EasyUnlockPrivateUpdateScreenlockStateFunction::RunSync() { | 418 bool EasyUnlockPrivateUpdateScreenlockStateFunction::RunSync() { |
| 425 scoped_ptr<easy_unlock_private::UpdateScreenlockState::Params> params( | 419 scoped_ptr<easy_unlock_private::UpdateScreenlockState::Params> params( |
| 426 easy_unlock_private::UpdateScreenlockState::Params::Create(*args_)); | 420 easy_unlock_private::UpdateScreenlockState::Params::Create(*args_)); |
| 427 EXTENSION_FUNCTION_VALIDATE(params.get()); | 421 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 428 | 422 |
| 429 EasyUnlockScreenlockStateHandler* screenlock_state_handler = | 423 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 430 GetScreenlockStateHandler(browser_context()); | 424 if (EasyUnlockService::Get(profile)->UpdateScreenlockState( |
| 431 if (screenlock_state_handler) { | 425 ToScreenlockStateHandlerState(params->state))) |
| 432 screenlock_state_handler->ChangeState( | |
| 433 ToScreenlockStateHandlerState(params->state)); | |
| 434 return true; | 426 return true; |
| 435 } | |
| 436 | 427 |
| 437 SetError("Not allowed"); | 428 SetError("Not allowed"); |
| 438 return false; | 429 return false; |
| 439 } | 430 } |
| 440 | 431 |
| 441 EasyUnlockPrivateSetPermitAccessFunction:: | 432 EasyUnlockPrivateSetPermitAccessFunction:: |
| 442 EasyUnlockPrivateSetPermitAccessFunction() { | 433 EasyUnlockPrivateSetPermitAccessFunction() { |
| 443 } | 434 } |
| 444 | 435 |
| 445 EasyUnlockPrivateSetPermitAccessFunction:: | 436 EasyUnlockPrivateSetPermitAccessFunction:: |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 } | 547 } |
| 557 | 548 |
| 558 EasyUnlockPrivateTrySignInSecretFunction:: | 549 EasyUnlockPrivateTrySignInSecretFunction:: |
| 559 EasyUnlockPrivateTrySignInSecretFunction() { | 550 EasyUnlockPrivateTrySignInSecretFunction() { |
| 560 } | 551 } |
| 561 | 552 |
| 562 EasyUnlockPrivateTrySignInSecretFunction:: | 553 EasyUnlockPrivateTrySignInSecretFunction:: |
| 563 ~EasyUnlockPrivateTrySignInSecretFunction() { | 554 ~EasyUnlockPrivateTrySignInSecretFunction() { |
| 564 } | 555 } |
| 565 | 556 |
| 566 bool EasyUnlockPrivateTrySignInSecretFunction::RunAsync() { | 557 bool EasyUnlockPrivateTrySignInSecretFunction::RunSync() { |
| 567 SetError("Not implemented"); | 558 scoped_ptr<easy_unlock_private::TrySignInSecret::Params> params( |
| 568 SendResponse(false); | 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); |
| 569 return true; | 564 return true; |
| 570 } | 565 } |
| 571 | 566 |
| 572 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { | 567 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { |
| 573 } | 568 } |
| 574 | 569 |
| 575 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { | 570 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { |
| 576 } | 571 } |
| 577 | 572 |
| 578 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { | 573 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { |
| 579 EasyUnlockService* service = | 574 EasyUnlockService* service = |
| 580 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); | 575 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); |
| 581 std::vector<linked_ptr<easy_unlock_private::UserInfo> > users; | 576 std::vector<linked_ptr<easy_unlock_private::UserInfo> > users; |
| 582 std::string user_id = service->GetUserEmail(); | 577 std::string user_id = service->GetUserEmail(); |
| 583 if (!user_id.empty()) { | 578 if (!user_id.empty()) { |
| 584 users.push_back( | 579 users.push_back( |
| 585 linked_ptr<easy_unlock_private::UserInfo>( | 580 linked_ptr<easy_unlock_private::UserInfo>( |
| 586 new easy_unlock_private::UserInfo())); | 581 new easy_unlock_private::UserInfo())); |
| 587 users[0]->user_id = user_id; | 582 users[0]->user_id = user_id; |
| 588 users[0]->logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR; | 583 users[0]->logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR; |
| 589 users[0]->data_ready = service->GetRemoteDevices() != NULL; | 584 users[0]->data_ready = users[0]->logged_in || |
| 585 service->GetRemoteDevices() != NULL; |
| 590 } | 586 } |
| 591 results_ = easy_unlock_private::GetUserInfo::Results::Create(users); | 587 results_ = easy_unlock_private::GetUserInfo::Results::Create(users); |
| 592 return true; | 588 return true; |
| 593 } | 589 } |
| 594 | 590 |
| 595 } // namespace api | 591 } // namespace api |
| 596 } // namespace extensions | 592 } // namespace extensions |
| OLD | NEW |