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" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 14 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
15 #include "chrome/browser/signin/easy_unlock_service.h" | 15 #include "chrome/browser/signin/easy_unlock_service.h" |
16 #include "chrome/common/extensions/api/easy_unlock_private.h" | 16 #include "chrome/common/extensions/api/easy_unlock_private.h" |
17 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 | 20 |
21 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
22 #include "chrome/browser/chromeos/chromeos_utils.h" | 22 #include "chrome/browser/chromeos/chromeos_utils.h" |
| 23 #include "device/bluetooth/bluetooth_device_chromeos.h" |
23 #endif | 24 #endif |
24 | 25 |
25 namespace extensions { | 26 namespace extensions { |
26 namespace api { | 27 namespace api { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 static base::LazyInstance<BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI> > | 31 static base::LazyInstance<BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI> > |
31 g_factory = LAZY_INSTANCE_INITIALIZER; | 32 g_factory = LAZY_INSTANCE_INITIALIZER; |
32 | 33 |
| 34 const char kApiUnavailable[] = "This API is not implemented on this platform."; |
| 35 |
33 // Utility method for getting the API's crypto delegate. | 36 // Utility method for getting the API's crypto delegate. |
34 EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate( | 37 EasyUnlockPrivateCryptoDelegate* GetCryptoDelegate( |
35 content::BrowserContext* context) { | 38 content::BrowserContext* context) { |
36 return BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>::Get(context) | 39 return BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>::Get(context) |
37 ->crypto_delegate(); | 40 ->crypto_delegate(); |
38 } | 41 } |
39 | 42 |
40 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler( | 43 EasyUnlockScreenlockStateHandler* GetScreenlockStateHandler( |
41 content::BrowserContext* context) { | 44 content::BrowserContext* context) { |
42 return EasyUnlockService::Get(Profile::FromBrowserContext(context)) | 45 return EasyUnlockService::Get(Profile::FromBrowserContext(context)) |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekCompleted( | 397 void EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction::OnSeekCompleted( |
395 const easy_unlock::SeekDeviceResult& seek_result) { | 398 const easy_unlock::SeekDeviceResult& seek_result) { |
396 if (seek_result.success) { | 399 if (seek_result.success) { |
397 SendResponse(true); | 400 SendResponse(true); |
398 } else { | 401 } else { |
399 SetError(seek_result.error_message); | 402 SetError(seek_result.error_message); |
400 SendResponse(false); | 403 SendResponse(false); |
401 } | 404 } |
402 } | 405 } |
403 | 406 |
| 407 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: |
| 408 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() {} |
| 409 |
| 410 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: |
| 411 ~EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() {} |
| 412 |
| 413 void EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: |
| 414 ConnectToService(device::BluetoothDevice* device, |
| 415 const device::BluetoothUUID& uuid) { |
| 416 #if defined(OS_CHROMEOS) |
| 417 chromeos::BluetoothDeviceChromeOS* device_chromeos = |
| 418 static_cast<chromeos::BluetoothDeviceChromeOS*>(device); |
| 419 device_chromeos->ConnectToServiceInsecurely( |
| 420 uuid, |
| 421 base::Bind(&EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: |
| 422 OnConnect, |
| 423 this), |
| 424 base::Bind(&EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction:: |
| 425 OnConnectError, |
| 426 this)); |
| 427 #else |
| 428 OnConnectError(kApiUnavailable); |
| 429 #endif // defined(OS_CHROMEOS) |
| 430 } |
| 431 |
404 EasyUnlockPrivateUpdateScreenlockStateFunction:: | 432 EasyUnlockPrivateUpdateScreenlockStateFunction:: |
405 EasyUnlockPrivateUpdateScreenlockStateFunction() {} | 433 EasyUnlockPrivateUpdateScreenlockStateFunction() {} |
406 | 434 |
407 EasyUnlockPrivateUpdateScreenlockStateFunction:: | 435 EasyUnlockPrivateUpdateScreenlockStateFunction:: |
408 ~EasyUnlockPrivateUpdateScreenlockStateFunction() {} | 436 ~EasyUnlockPrivateUpdateScreenlockStateFunction() {} |
409 | 437 |
410 bool EasyUnlockPrivateUpdateScreenlockStateFunction::RunSync() { | 438 bool EasyUnlockPrivateUpdateScreenlockStateFunction::RunSync() { |
411 scoped_ptr<easy_unlock_private::UpdateScreenlockState::Params> params( | 439 scoped_ptr<easy_unlock_private::UpdateScreenlockState::Params> params( |
412 easy_unlock_private::UpdateScreenlockState::Params::Create(*args_)); | 440 easy_unlock_private::UpdateScreenlockState::Params::Create(*args_)); |
413 EXTENSION_FUNCTION_VALIDATE(params.get()); | 441 EXTENSION_FUNCTION_VALIDATE(params.get()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() { | 545 bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() { |
518 Profile* profile = Profile::FromBrowserContext(browser_context()); | 546 Profile* profile = Profile::FromBrowserContext(browser_context()); |
519 const base::ListValue* devices = | 547 const base::ListValue* devices = |
520 EasyUnlockService::Get(profile)->GetRemoteDevices(); | 548 EasyUnlockService::Get(profile)->GetRemoteDevices(); |
521 SetResult(devices ? devices->DeepCopy() : new base::ListValue()); | 549 SetResult(devices ? devices->DeepCopy() : new base::ListValue()); |
522 return true; | 550 return true; |
523 } | 551 } |
524 | 552 |
525 } // namespace api | 553 } // namespace api |
526 } // namespace extensions | 554 } // namespace extensions |
OLD | NEW |