Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api.cc

Issue 2805113002: [CrOS Tether] Make BluetoothThrottler a singleton which can be easily shared between EasyUnlock and… (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 error_message = *params->result.error_message; 1042 error_message = *params->result.error_message;
1043 1043
1044 Profile* profile = Profile::FromBrowserContext(browser_context()); 1044 Profile* profile = Profile::FromBrowserContext(browser_context());
1045 EasyUnlockService::Get(profile) 1045 EasyUnlockService::Get(profile)
1046 ->SetAutoPairingResult(params->result.success, error_message); 1046 ->SetAutoPairingResult(params->result.success, error_message);
1047 1047
1048 return RespondNow(NoArguments()); 1048 return RespondNow(NoArguments());
1049 } 1049 }
1050 1050
1051 EasyUnlockPrivateFindSetupConnectionFunction:: 1051 EasyUnlockPrivateFindSetupConnectionFunction::
1052 EasyUnlockPrivateFindSetupConnectionFunction() 1052 EasyUnlockPrivateFindSetupConnectionFunction() {}
1053 : bluetooth_throttler_(new cryptauth::BluetoothThrottlerImpl(
1054 base::MakeUnique<base::DefaultTickClock>())) {}
1055 1053
1056 EasyUnlockPrivateFindSetupConnectionFunction:: 1054 EasyUnlockPrivateFindSetupConnectionFunction::
1057 ~EasyUnlockPrivateFindSetupConnectionFunction() { 1055 ~EasyUnlockPrivateFindSetupConnectionFunction() {
1058 // |connection_finder_| has a raw pointer to |bluetooth_throttler_|, so it
1059 // should be destroyed first.
1060 connection_finder_.reset(); 1056 connection_finder_.reset();
1061 bluetooth_throttler_.reset();
1062 } 1057 }
1063 1058
1064 void EasyUnlockPrivateFindSetupConnectionFunction:: 1059 void EasyUnlockPrivateFindSetupConnectionFunction::
1065 OnConnectionFinderTimedOut() { 1060 OnConnectionFinderTimedOut() {
1066 SetError("No connection found."); 1061 SetError("No connection found.");
1067 connection_finder_.reset(); 1062 connection_finder_.reset();
1068 SendResponse(false); 1063 SendResponse(false);
1069 } 1064 }
1070 1065
1071 void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound( 1066 void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound(
(...skipping 13 matching lines...) Expand all
1085 std::unique_ptr<easy_unlock_private::FindSetupConnection::Params> params = 1080 std::unique_ptr<easy_unlock_private::FindSetupConnection::Params> params =
1086 easy_unlock_private::FindSetupConnection::Params::Create(*args_); 1081 easy_unlock_private::FindSetupConnection::Params::Create(*args_);
1087 EXTENSION_FUNCTION_VALIDATE(params); 1082 EXTENSION_FUNCTION_VALIDATE(params);
1088 1083
1089 // Creates a BLE connection finder to look for any device advertising 1084 // Creates a BLE connection finder to look for any device advertising
1090 // |params->setup_service_uuid|. 1085 // |params->setup_service_uuid|.
1091 connection_finder_.reset( 1086 connection_finder_.reset(
1092 new proximity_auth::BluetoothLowEnergyConnectionFinder( 1087 new proximity_auth::BluetoothLowEnergyConnectionFinder(
1093 cryptauth::RemoteDevice(), params->setup_service_uuid, 1088 cryptauth::RemoteDevice(), params->setup_service_uuid,
1094 proximity_auth::BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE, 1089 proximity_auth::BluetoothLowEnergyConnectionFinder::FIND_ANY_DEVICE,
1095 nullptr, bluetooth_throttler_.get(), 3)); 1090 nullptr, cryptauth::BluetoothThrottlerImpl::GetInstance(), 3));
1096 1091
1097 connection_finder_->Find(base::Bind( 1092 connection_finder_->Find(base::Bind(
1098 &EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound, this)); 1093 &EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound, this));
1099 1094
1100 timer_.reset(new base::OneShotTimer()); 1095 timer_.reset(new base::OneShotTimer());
1101 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(params->time_out), 1096 timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(params->time_out),
1102 base::Bind(&EasyUnlockPrivateFindSetupConnectionFunction:: 1097 base::Bind(&EasyUnlockPrivateFindSetupConnectionFunction::
1103 OnConnectionFinderTimedOut, 1098 OnConnectionFinderTimedOut,
1104 this)); 1099 this));
1105 1100
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 GetConnectionManager(browser_context()) 1176 GetConnectionManager(browser_context())
1182 ->GetDeviceAddress(extension(), params->connection_id); 1177 ->GetDeviceAddress(extension(), params->connection_id);
1183 if (device_address.empty()) 1178 if (device_address.empty())
1184 return RespondNow(Error("Invalid connectionId.")); 1179 return RespondNow(Error("Invalid connectionId."));
1185 return RespondNow(ArgumentList( 1180 return RespondNow(ArgumentList(
1186 easy_unlock_private::SetupConnectionGetDeviceAddress::Results::Create( 1181 easy_unlock_private::SetupConnectionGetDeviceAddress::Results::Create(
1187 device_address))); 1182 device_address)));
1188 } 1183 }
1189 1184
1190 } // namespace extensions 1185 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698