| 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 <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/base64url.h" | 10 #include "base/base64url.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 13 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 14 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 proximity_auth::ProximityAuthClient* client = | 747 proximity_auth::ProximityAuthClient* client = |
| 747 easy_unlock_service->proximity_auth_client(); | 748 easy_unlock_service->proximity_auth_client(); |
| 748 | 749 |
| 749 permit_id_ = "permit://google.com/easyunlock/v1/" + client->GetAccountId(); | 750 permit_id_ = "permit://google.com/easyunlock/v1/" + client->GetAccountId(); |
| 750 secure_message_delegate_ = client->CreateSecureMessageDelegate(); | 751 secure_message_delegate_ = client->CreateSecureMessageDelegate(); |
| 751 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys = GetUnlockKeys(); | 752 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys = GetUnlockKeys(); |
| 752 expected_devices_count_ = unlock_keys.size(); | 753 expected_devices_count_ = unlock_keys.size(); |
| 753 | 754 |
| 754 remote_devices_.reset(new base::ListValue()); | 755 remote_devices_.reset(new base::ListValue()); |
| 755 if (expected_devices_count_ == 0) { | 756 if (expected_devices_count_ == 0) { |
| 756 SetResult(remote_devices_.Pass()); | 757 SetResult(std::move(remote_devices_)); |
| 757 SendResponse(true); | 758 SendResponse(true); |
| 758 return; | 759 return; |
| 759 } | 760 } |
| 760 | 761 |
| 761 // If there is a BLE unlock key, then don't return anything, so the app does | 762 // If there is a BLE unlock key, then don't return anything, so the app does |
| 762 // not try the classic Bluetooth protocol. | 763 // not try the classic Bluetooth protocol. |
| 763 for (const auto& unlock_key : unlock_keys) { | 764 for (const auto& unlock_key : unlock_keys) { |
| 764 if (unlock_key.bluetooth_address().empty()) { | 765 if (unlock_key.bluetooth_address().empty()) { |
| 765 SetResult(remote_devices_.Pass()); | 766 SetResult(std::move(remote_devices_)); |
| 766 SendResponse(true); | 767 SendResponse(true); |
| 767 return; | 768 return; |
| 768 } | 769 } |
| 769 } | 770 } |
| 770 | 771 |
| 771 // Derive the PSKs for the user's unlock keys. | 772 // Derive the PSKs for the user's unlock keys. |
| 772 PA_LOG(INFO) << "Deriving PSKs for " | 773 PA_LOG(INFO) << "Deriving PSKs for " |
| 773 << "chrome.easyUnlockPrivate.getRemoteDevices.\n" | 774 << "chrome.easyUnlockPrivate.getRemoteDevices.\n" |
| 774 << "Expecting " << expected_devices_count_ << " devices."; | 775 << "Expecting " << expected_devices_count_ << " devices."; |
| 775 for (const auto& unlock_key : unlock_keys) { | 776 for (const auto& unlock_key : unlock_keys) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 798 device_dictionary->SetString("name", device.friendly_device_name()); | 799 device_dictionary->SetString("name", device.friendly_device_name()); |
| 799 device_dictionary->SetString("bluetoothAddress", device.bluetooth_address()); | 800 device_dictionary->SetString("bluetoothAddress", device.bluetooth_address()); |
| 800 device_dictionary->SetString("psk", b64_psk); | 801 device_dictionary->SetString("psk", b64_psk); |
| 801 | 802 |
| 802 // Fill in the permit license for the unlock key. | 803 // Fill in the permit license for the unlock key. |
| 803 scoped_ptr<base::DictionaryValue> permit_license(new base::DictionaryValue()); | 804 scoped_ptr<base::DictionaryValue> permit_license(new base::DictionaryValue()); |
| 804 permit_license->SetString("permitId", permit_id_); | 805 permit_license->SetString("permitId", permit_id_); |
| 805 permit_license->SetString("id", b64_public_key); | 806 permit_license->SetString("id", b64_public_key); |
| 806 permit_license->SetString("type", "license"); | 807 permit_license->SetString("type", "license"); |
| 807 permit_license->SetString("data", b64_public_key); | 808 permit_license->SetString("data", b64_public_key); |
| 808 device_dictionary->Set("permitRecord", permit_license.Pass()); | 809 device_dictionary->Set("permitRecord", std::move(permit_license)); |
| 809 | 810 |
| 810 remote_devices_->Append(device_dictionary.Pass()); | 811 remote_devices_->Append(std::move(device_dictionary)); |
| 811 | 812 |
| 812 // If all PSKs are derived, then return from the API call. | 813 // If all PSKs are derived, then return from the API call. |
| 813 PA_LOG(INFO) << "Derived PSK for " << b64_public_key << ": " | 814 PA_LOG(INFO) << "Derived PSK for " << b64_public_key << ": " |
| 814 << remote_devices_->GetSize() << "/" << expected_devices_count_; | 815 << remote_devices_->GetSize() << "/" << expected_devices_count_; |
| 815 if (remote_devices_->GetSize() == expected_devices_count_) { | 816 if (remote_devices_->GetSize() == expected_devices_count_) { |
| 816 SetResult(remote_devices_.Pass()); | 817 SetResult(std::move(remote_devices_)); |
| 817 SendResponse(true); | 818 SendResponse(true); |
| 818 } | 819 } |
| 819 } | 820 } |
| 820 | 821 |
| 821 EasyUnlockPrivateGetSignInChallengeFunction:: | 822 EasyUnlockPrivateGetSignInChallengeFunction:: |
| 822 EasyUnlockPrivateGetSignInChallengeFunction() { | 823 EasyUnlockPrivateGetSignInChallengeFunction() { |
| 823 } | 824 } |
| 824 | 825 |
| 825 EasyUnlockPrivateGetSignInChallengeFunction:: | 826 EasyUnlockPrivateGetSignInChallengeFunction:: |
| 826 ~EasyUnlockPrivateGetSignInChallengeFunction() { | 827 ~EasyUnlockPrivateGetSignInChallengeFunction() { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 &EasyUnlockPrivateGetConnectionInfoFunction::OnConnectionInfo, this)); | 953 &EasyUnlockPrivateGetConnectionInfoFunction::OnConnectionInfo, this)); |
| 953 return false; | 954 return false; |
| 954 } | 955 } |
| 955 | 956 |
| 956 void EasyUnlockPrivateGetConnectionInfoFunction::OnConnectionInfo( | 957 void EasyUnlockPrivateGetConnectionInfoFunction::OnConnectionInfo( |
| 957 const device::BluetoothDevice::ConnectionInfo& connection_info) { | 958 const device::BluetoothDevice::ConnectionInfo& connection_info) { |
| 958 scoped_ptr<base::ListValue> results(new base::ListValue()); | 959 scoped_ptr<base::ListValue> results(new base::ListValue()); |
| 959 results->AppendInteger(connection_info.rssi); | 960 results->AppendInteger(connection_info.rssi); |
| 960 results->AppendInteger(connection_info.transmit_power); | 961 results->AppendInteger(connection_info.transmit_power); |
| 961 results->AppendInteger(connection_info.max_transmit_power); | 962 results->AppendInteger(connection_info.max_transmit_power); |
| 962 SetResultList(results.Pass()); | 963 SetResultList(std::move(results)); |
| 963 SendResponse(true); | 964 SendResponse(true); |
| 964 } | 965 } |
| 965 | 966 |
| 966 EasyUnlockPrivateShowErrorBubbleFunction:: | 967 EasyUnlockPrivateShowErrorBubbleFunction:: |
| 967 EasyUnlockPrivateShowErrorBubbleFunction() { | 968 EasyUnlockPrivateShowErrorBubbleFunction() { |
| 968 } | 969 } |
| 969 | 970 |
| 970 EasyUnlockPrivateShowErrorBubbleFunction:: | 971 EasyUnlockPrivateShowErrorBubbleFunction:: |
| 971 ~EasyUnlockPrivateShowErrorBubbleFunction() { | 972 ~EasyUnlockPrivateShowErrorBubbleFunction() { |
| 972 } | 973 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 SendResponse(false); | 1068 SendResponse(false); |
| 1068 } | 1069 } |
| 1069 | 1070 |
| 1070 void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound( | 1071 void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound( |
| 1071 scoped_ptr<proximity_auth::Connection> connection) { | 1072 scoped_ptr<proximity_auth::Connection> connection) { |
| 1072 // Connection are not persistent by default. | 1073 // Connection are not persistent by default. |
| 1073 std::string device_address = connection->remote_device().bluetooth_address; | 1074 std::string device_address = connection->remote_device().bluetooth_address; |
| 1074 bool persistent = false; | 1075 bool persistent = false; |
| 1075 int connection_id = | 1076 int connection_id = |
| 1076 GetConnectionManager(browser_context()) | 1077 GetConnectionManager(browser_context()) |
| 1077 ->AddConnection(extension(), connection.Pass(), persistent); | 1078 ->AddConnection(extension(), std::move(connection), persistent); |
| 1078 results_ = easy_unlock_private::FindSetupConnection::Results::Create( | 1079 results_ = easy_unlock_private::FindSetupConnection::Results::Create( |
| 1079 connection_id, device_address); | 1080 connection_id, device_address); |
| 1080 SendResponse(true); | 1081 SendResponse(true); |
| 1081 } | 1082 } |
| 1082 | 1083 |
| 1083 bool EasyUnlockPrivateFindSetupConnectionFunction::RunAsync() { | 1084 bool EasyUnlockPrivateFindSetupConnectionFunction::RunAsync() { |
| 1084 scoped_ptr<easy_unlock_private::FindSetupConnection::Params> params = | 1085 scoped_ptr<easy_unlock_private::FindSetupConnection::Params> params = |
| 1085 easy_unlock_private::FindSetupConnection::Params::Create(*args_); | 1086 easy_unlock_private::FindSetupConnection::Params::Create(*args_); |
| 1086 EXTENSION_FUNCTION_VALIDATE(params); | 1087 EXTENSION_FUNCTION_VALIDATE(params); |
| 1087 | 1088 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 ->GetDeviceAddress(extension(), params->connection_id); | 1178 ->GetDeviceAddress(extension(), params->connection_id); |
| 1178 results_ = | 1179 results_ = |
| 1179 easy_unlock_private::SetupConnectionGetDeviceAddress::Results::Create( | 1180 easy_unlock_private::SetupConnectionGetDeviceAddress::Results::Create( |
| 1180 device_address); | 1181 device_address); |
| 1181 if (device_address.empty()) | 1182 if (device_address.empty()) |
| 1182 SetError("Invalid connectionId."); | 1183 SetError("Invalid connectionId."); |
| 1183 return true; | 1184 return true; |
| 1184 } | 1185 } |
| 1185 | 1186 |
| 1186 } // namespace extensions | 1187 } // namespace extensions |
| OLD | NEW |