| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64url.h" | 10 #include "base/base64url.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/linked_ptr.h" | |
| 15 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/time/default_tick_clock.h" | 17 #include "base/time/default_tick_clock.h" |
| 19 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 20 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
| 21 #include "base/values.h" | 20 #include "base/values.h" |
| 22 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 23 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
connection_manager.h" | 22 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
connection_manager.h" |
| 24 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
crypto_delegate.h" | 23 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
crypto_delegate.h" |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 ~EasyUnlockPrivateSetRemoteDevicesFunction() { | 665 ~EasyUnlockPrivateSetRemoteDevicesFunction() { |
| 667 } | 666 } |
| 668 | 667 |
| 669 bool EasyUnlockPrivateSetRemoteDevicesFunction::RunSync() { | 668 bool EasyUnlockPrivateSetRemoteDevicesFunction::RunSync() { |
| 670 scoped_ptr<easy_unlock_private::SetRemoteDevices::Params> params( | 669 scoped_ptr<easy_unlock_private::SetRemoteDevices::Params> params( |
| 671 easy_unlock_private::SetRemoteDevices::Params::Create(*args_)); | 670 easy_unlock_private::SetRemoteDevices::Params::Create(*args_)); |
| 672 EXTENSION_FUNCTION_VALIDATE(params.get()); | 671 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 673 | 672 |
| 674 Profile* profile = Profile::FromBrowserContext(browser_context()); | 673 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 675 base::ListValue devices; | 674 base::ListValue devices; |
| 676 for (size_t i = 0; i < params->devices.size(); ++i) { | 675 for (const easy_unlock_private::Device& device : params->devices) |
| 677 devices.Append(params->devices[i]->ToValue().release()); | 676 devices.Append(device.ToValue()); |
| 678 } | 677 |
| 679 // Store the BLE device if we are trying out the BLE experiment. | 678 // Store the BLE device if we are trying out the BLE experiment. |
| 680 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 679 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 681 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { | 680 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { |
| 682 EasyUnlockService::Get(profile)->SetRemoteBleDevices(devices); | 681 EasyUnlockService::Get(profile)->SetRemoteBleDevices(devices); |
| 683 } else { | 682 } else { |
| 684 EasyUnlockService::Get(profile)->SetRemoteDevices(devices); | 683 EasyUnlockService::Get(profile)->SetRemoteDevices(devices); |
| 685 } | 684 } |
| 686 | 685 |
| 687 return true; | 686 return true; |
| 688 } | 687 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 | 885 |
| 887 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { | 886 EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { |
| 888 } | 887 } |
| 889 | 888 |
| 890 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { | 889 EasyUnlockPrivateGetUserInfoFunction::~EasyUnlockPrivateGetUserInfoFunction() { |
| 891 } | 890 } |
| 892 | 891 |
| 893 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { | 892 bool EasyUnlockPrivateGetUserInfoFunction::RunSync() { |
| 894 EasyUnlockService* service = | 893 EasyUnlockService* service = |
| 895 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); | 894 EasyUnlockService::Get(Profile::FromBrowserContext(browser_context())); |
| 896 std::vector<linked_ptr<easy_unlock_private::UserInfo> > users; | 895 std::vector<easy_unlock_private::UserInfo> users; |
| 897 const AccountId& account_id = service->GetAccountId(); | 896 const AccountId& account_id = service->GetAccountId(); |
| 898 if (account_id.is_valid()) { | 897 if (account_id.is_valid()) { |
| 899 users.push_back( | 898 easy_unlock_private::UserInfo user; |
| 900 linked_ptr<easy_unlock_private::UserInfo>( | 899 user.user_id = account_id.GetUserEmail(); |
| 901 new easy_unlock_private::UserInfo())); | 900 user.logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR; |
| 902 users[0]->user_id = account_id.GetUserEmail(); | 901 user.data_ready = user.logged_in || service->GetRemoteDevices() != NULL; |
| 903 users[0]->logged_in = service->GetType() == EasyUnlockService::TYPE_REGULAR; | |
| 904 users[0]->data_ready = users[0]->logged_in || | |
| 905 service->GetRemoteDevices() != NULL; | |
| 906 | 902 |
| 907 EasyUnlockService::UserSettings user_settings = | 903 EasyUnlockService::UserSettings user_settings = |
| 908 EasyUnlockService::GetUserSettings(account_id); | 904 EasyUnlockService::GetUserSettings(account_id); |
| 909 users[0]->require_close_proximity = user_settings.require_close_proximity; | 905 user.require_close_proximity = user_settings.require_close_proximity; |
| 910 | 906 |
| 911 users[0]->device_user_id = proximity_auth::CalculateDeviceUserId( | 907 user.device_user_id = proximity_auth::CalculateDeviceUserId( |
| 912 EasyUnlockService::GetDeviceId(), account_id.GetUserEmail()); | 908 EasyUnlockService::GetDeviceId(), account_id.GetUserEmail()); |
| 913 | 909 |
| 914 users[0]->ble_discovery_enabled = | 910 user.ble_discovery_enabled = |
| 915 base::CommandLine::ForCurrentProcess()->HasSwitch( | 911 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 916 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery); | 912 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery); |
| 913 users.push_back(std::move(user)); |
| 917 } | 914 } |
| 918 results_ = easy_unlock_private::GetUserInfo::Results::Create(users); | 915 results_ = easy_unlock_private::GetUserInfo::Results::Create(users); |
| 919 return true; | 916 return true; |
| 920 } | 917 } |
| 921 | 918 |
| 922 EasyUnlockPrivateGetConnectionInfoFunction:: | 919 EasyUnlockPrivateGetConnectionInfoFunction:: |
| 923 EasyUnlockPrivateGetConnectionInfoFunction() { | 920 EasyUnlockPrivateGetConnectionInfoFunction() { |
| 924 } | 921 } |
| 925 | 922 |
| 926 EasyUnlockPrivateGetConnectionInfoFunction:: | 923 EasyUnlockPrivateGetConnectionInfoFunction:: |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 ->GetDeviceAddress(extension(), params->connection_id); | 1173 ->GetDeviceAddress(extension(), params->connection_id); |
| 1177 results_ = | 1174 results_ = |
| 1178 easy_unlock_private::SetupConnectionGetDeviceAddress::Results::Create( | 1175 easy_unlock_private::SetupConnectionGetDeviceAddress::Results::Create( |
| 1179 device_address); | 1176 device_address); |
| 1180 if (device_address.empty()) | 1177 if (device_address.empty()) |
| 1181 SetError("Invalid connectionId."); | 1178 SetError("Invalid connectionId."); |
| 1182 return true; | 1179 return true; |
| 1183 } | 1180 } |
| 1184 | 1181 |
| 1185 } // namespace extensions | 1182 } // namespace extensions |
| OLD | NEW |