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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
bluetooth_util.h" | 11 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
bluetooth_util.h" |
12 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
crypto_delegate.h" | 12 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
crypto_delegate.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 15 #include "chrome/browser/signin/easy_unlock_service.h" |
13 #include "chrome/common/extensions/api/easy_unlock_private.h" | 16 #include "chrome/common/extensions/api/easy_unlock_private.h" |
14 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
15 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
17 | 20 |
18 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
19 #include "chrome/browser/chromeos/chromeos_utils.h" | 22 #include "chrome/browser/chromeos/chromeos_utils.h" |
20 #endif | 23 #endif |
21 | 24 |
22 namespace extensions { | 25 namespace extensions { |
23 namespace api { | 26 namespace api { |
24 | 27 |
25 namespace { | 28 namespace { |
26 | 29 |
27 static base::LazyInstance<BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI> > | 30 static base::LazyInstance<BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI> > |
28 g_factory = LAZY_INSTANCE_INITIALIZER; | 31 g_factory = LAZY_INSTANCE_INITIALIZER; |
29 | 32 |
30 // Utility method for getting the API's crypto delegate. | 33 // Utility method for getting the API's crypto delegate. |
31 EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate( | 34 EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate( |
32 content::BrowserContext* context) { | 35 content::BrowserContext* context) { |
33 return BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>::Get(context) | 36 return BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>::Get(context) |
34 ->crypto_delegate(); | 37 ->crypto_delegate(); |
35 } | 38 } |
36 | 39 |
| 40 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler( |
| 41 content::BrowserContext* context) { |
| 42 return EasyUnlockService::Get(Profile::FromBrowserContext(context)) |
| 43 ->GetScreenlockStateHandler(); |
| 44 } |
| 45 |
| 46 EasyUnlockScreenlockStateHandler::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_AUTHENTICATED: |
| 64 return EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED; |
| 65 default: |
| 66 return EasyUnlockScreenlockStateHandler::STATE_INACTIVE; |
| 67 } |
| 68 } |
| 69 |
37 } // namespace | 70 } // namespace |
38 | 71 |
39 // static | 72 // static |
40 BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>* | 73 BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>* |
41 EasyUnlockPrivateAPI::GetFactoryInstance() { | 74 EasyUnlockPrivateAPI::GetFactoryInstance() { |
42 return g_factory.Pointer(); | 75 return g_factory.Pointer(); |
43 } | 76 } |
44 | 77 |
45 EasyUnlockPrivateAPI::EasyUnlockPrivateAPI(content::BrowserContext* context) | 78 EasyUnlockPrivateAPI::EasyUnlockPrivateAPI(content::BrowserContext* context) |
46 : crypto_delegate_(EasyUnlockPrivateCryptoDelegate::Create()) { | 79 : crypto_delegate_(EasyUnlockPrivateCryptoDelegate::Create()) { |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekCompleted( | 394 void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekCompleted( |
362 const easy_unlock::SeekDeviceResult& seek_result) { | 395 const easy_unlock::SeekDeviceResult& seek_result) { |
363 if (seek_result.success) { | 396 if (seek_result.success) { |
364 SendResponse(true); | 397 SendResponse(true); |
365 } else { | 398 } else { |
366 SetError(seek_result.error_message); | 399 SetError(seek_result.error_message); |
367 SendResponse(false); | 400 SendResponse(false); |
368 } | 401 } |
369 } | 402 } |
370 | 403 |
| 404 EasyUnlockPrivateUpdateScreenlockStateFunction:: |
| 405 EasyUnlockPrivateUpdateScreenlockStateFunction() {} |
| 406 |
| 407 EasyUnlockPrivateUpdateScreenlockStateFunction:: |
| 408 ~EasyUnlockPrivateUpdateScreenlockStateFunction() {} |
| 409 |
| 410 bool EasyUnlockPrivateUpdateScreenlockStateFunction::RunSync() { |
| 411 scoped_ptr<easy_unlock_private::UpdateScreenlockState::Params> params( |
| 412 easy_unlock_private::UpdateScreenlockState::Params::Create(*args_)); |
| 413 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 414 |
| 415 EasyUnlockScreenlockStateHandler* screenlock_state_handler = |
| 416 GetScreenlockStateHandler(browser_context()); |
| 417 if (screenlock_state_handler) { |
| 418 screenlock_state_handler->ChangeState( |
| 419 ToScreenlockStateHandlerState(params->state)); |
| 420 return true; |
| 421 } |
| 422 |
| 423 SetError("Not allowed"); |
| 424 return false; |
| 425 } |
| 426 |
371 } // namespace api | 427 } // namespace api |
372 } // namespace extensions | 428 } // namespace extensions |
OLD | NEW |