summaryrefslogtreecommitdiffstats
path: root/components/proximity_auth
diff options
context:
space:
mode:
authorsacomoto <sacomoto@chromium.org>2015-08-04 08:14:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-04 15:15:49 +0000
commitb224c457004e6c3c41c1fdee9099ce6b2e6cef82 (patch)
tree8d19e7f9959d2240046ca169443cc031155339b3 /components/proximity_auth
parent79e604620ff0be4f068341ee286bb518590b0939 (diff)
downloadchromium_src-b224c457004e6c3c41c1fdee9099ce6b2e6cef82.zip
chromium_src-b224c457004e6c3c41c1fdee9099ce6b2e6cef82.tar.gz
chromium_src-b224c457004e6c3c41c1fdee9099ce6b2e6cef82.tar.bz2
Throttling reconnection attempts in ProximityAuthBleSystem.
This CL modifies proximity_auth::BluetoothLowEnergyConnection to only try to reconnect to a given device after a delay given by proximity_auth::BluetoothThrottler. BUG=508919 Review URL: https://codereview.chromium.org/1269793003 Cr-Commit-Position: refs/heads/master@{#341724}
Diffstat (limited to 'components/proximity_auth')
-rw-r--r--components/proximity_auth/ble/bluetooth_low_energy_connection.cc41
-rw-r--r--components/proximity_auth/ble/bluetooth_low_energy_connection.h24
-rw-r--r--components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc9
-rw-r--r--components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h6
-rw-r--r--components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc10
-rw-r--r--components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc86
-rw-r--r--components/proximity_auth/ble/proximity_auth_ble_system.cc8
-rw-r--r--components/proximity_auth/ble/proximity_auth_ble_system.h3
8 files changed, 162 insertions, 25 deletions
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection.cc
index e0eba83..3d7586e 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection.cc
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection.cc
@@ -8,10 +8,12 @@
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
+#include "base/task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_finder.h"
#include "components/proximity_auth/ble/fake_wire_message.h"
+#include "components/proximity_auth/bluetooth_throttler.h"
#include "components/proximity_auth/connection_finder.h"
#include "components/proximity_auth/logging/logging.h"
#include "components/proximity_auth/wire_message.h"
@@ -53,12 +55,15 @@ BluetoothLowEnergyConnection::BluetoothLowEnergyConnection(
const BluetoothUUID remote_service_uuid,
const BluetoothUUID to_peripheral_char_uuid,
const BluetoothUUID from_peripheral_char_uuid,
+ BluetoothThrottler* bluetooth_throttler,
int max_number_of_write_attempts)
: Connection(device),
adapter_(adapter),
remote_service_({remote_service_uuid, ""}),
to_peripheral_char_({to_peripheral_char_uuid, ""}),
from_peripheral_char_({from_peripheral_char_uuid, ""}),
+ bluetooth_throttler_(bluetooth_throttler),
+ task_runner_(base::ThreadTaskRunnerHandle::Get()),
sub_status_(SubStatus::DISCONNECTED),
receiving_bytes_(false),
write_remote_characteristic_pending_(false),
@@ -84,12 +89,36 @@ BluetoothLowEnergyConnection::~BluetoothLowEnergyConnection() {
void BluetoothLowEnergyConnection::Connect() {
DCHECK(sub_status() == SubStatus::DISCONNECTED);
+ SetSubStatus(SubStatus::WAITING_GATT_CONNECTION);
+ base::TimeDelta throttler_delay = bluetooth_throttler_->GetDelay();
+ PA_LOG(INFO) << "Connecting in " << throttler_delay;
+
start_time_ = base::TimeTicks::Now();
+
+ // If necessary, wait to create a new GATT connection.
+ //
+ // Avoid creating a new GATT connection immediately after a given device was
+ // disconnected. This is a workaround for crbug.com/508919.
+ if (!throttler_delay.is_zero()) {
+ task_runner_->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&BluetoothLowEnergyConnection::CreateGattConnection,
+ weak_ptr_factory_.GetWeakPtr()),
+ throttler_delay);
+ return;
+ }
+
+ CreateGattConnection();
+}
+
+void BluetoothLowEnergyConnection::CreateGattConnection() {
+ DCHECK(sub_status() == SubStatus::WAITING_GATT_CONNECTION);
+
BluetoothDevice* remote_device = GetRemoteDevice();
if (remote_device) {
PA_LOG(INFO) << "Creating GATT connection with "
<< remote_device->GetAddress();
- SetSubStatus(SubStatus::WAITING_GATT_CONNECTION);
+
remote_device->CreateGattConnection(
base::Bind(&BluetoothLowEnergyConnection::OnGattConnectionCreated,
weak_ptr_factory_.GetWeakPtr()),
@@ -131,8 +160,9 @@ void BluetoothLowEnergyConnection::SetSubStatus(SubStatus new_sub_status) {
}
}
-void BluetoothLowEnergyConnection::SetDelayForTesting(base::TimeDelta delay) {
- delay_after_gatt_connection_ = delay;
+void BluetoothLowEnergyConnection::SetTaskRunnerForTesting(
+ scoped_refptr<base::TaskRunner> task_runner) {
+ task_runner_ = task_runner;
}
void BluetoothLowEnergyConnection::SendMessageImpl(
@@ -302,6 +332,9 @@ void BluetoothLowEnergyConnection::OnGattConnectionCreated(
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&BluetoothLowEnergyConnection::OnCharacteristicsFinderError,
weak_ptr_factory_.GetWeakPtr())));
+
+ // Informing |bluetooth_trottler_| a new connection was established.
+ bluetooth_throttler_->OnConnection(this);
}
BluetoothLowEnergyCharacteristicsFinder*
@@ -409,7 +442,7 @@ void BluetoothLowEnergyConnection::SendInviteToConnectSignal() {
// This is a workaround for crbug.com/498850. Currently, trying to
// write/read characteristics immediatelly after the GATT connection was
// established fails with GATT_ERROR_FAILED.
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ task_runner_->PostDelayedTask(
FROM_HERE,
base::Bind(&BluetoothLowEnergyConnection::WriteRemoteCharacteristic,
weak_ptr_factory_.GetWeakPtr(), write_request),
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.h b/components/proximity_auth/ble/bluetooth_low_energy_connection.h
index 827ea32..b2019b7 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection.h
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection.h
@@ -23,8 +23,14 @@
#include "device/bluetooth/bluetooth_gatt_notify_session.h"
#include "device/bluetooth/bluetooth_uuid.h"
+namespace base {
+class TaskRunner;
+}
+
namespace proximity_auth {
+class BluetoothThrottler;
+
// Represents a connection with a remote device over Bluetooth low energy. The
// connection is a persistent bidirectional channel for sending and receiving
// wire messages. The remote device is the peripheral mode and the service
@@ -84,6 +90,7 @@ class BluetoothLowEnergyConnection : public Connection,
const device::BluetoothUUID remote_service_uuid,
const device::BluetoothUUID to_peripheral_char_uuid,
const device::BluetoothUUID from_peripheral_char_uuid,
+ BluetoothThrottler* bluetooth_throttler,
int max_number_of_write_attempts);
~BluetoothLowEnergyConnection() override;
@@ -97,8 +104,8 @@ class BluetoothLowEnergyConnection : public Connection,
void SetSubStatus(SubStatus status);
SubStatus sub_status() { return sub_status_; }
- // Sets |delay_after_gatt_connection_| for testing.
- void SetDelayForTesting(base::TimeDelta delay);
+ // Sets |task_runner_| for testing.
+ void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner);
// Virtual for testing.
virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder(
@@ -138,11 +145,14 @@ class BluetoothLowEnergyConnection : public Connection,
int number_of_failed_attempts;
};
- // Called when a GATT connection is created or received by the constructor.
+ // Creates the GATT connection with |remote_device|.
+ void CreateGattConnection();
+
+ // Called when a GATT connection is created.
void OnGattConnectionCreated(
scoped_ptr<device::BluetoothGattConnection> gatt_connection);
- // Callback called when there is an error creating the connection.
+ // Callback called when there is an error creating the GATT connection.
void OnCreateGattConnectionError(
device::BluetoothDevice::ConnectErrorCode error_code);
@@ -248,6 +258,12 @@ class BluetoothLowEnergyConnection : public Connection,
// Characteristic used to receive data from the remote device.
RemoteAttribute from_peripheral_char_;
+ // Throttles repeated connection attempts to the same device. This is a
+ // workaround for crbug.com/508919. Not owned, must outlive this instance.
+ BluetoothThrottler* bluetooth_throttler_;
+
+ scoped_refptr<base::TaskRunner> task_runner_;
+
// The GATT connection with the remote device.
scoped_ptr<device::BluetoothGattConnection> gatt_connection_;
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc
index 85d0474..8b020a9 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc
@@ -30,20 +30,23 @@ namespace {
const int kMinDiscoveryRSSI = -90;
} // namespace
+class BluetoothThrottler;
+
BluetoothLowEnergyConnectionFinder::BluetoothLowEnergyConnectionFinder(
const std::string& remote_service_uuid,
const std::string& to_peripheral_char_uuid,
const std::string& from_peripheral_char_uuid,
const BluetoothLowEnergyDeviceWhitelist* device_whitelist,
+ BluetoothThrottler* bluetooth_throttler,
int max_number_of_tries)
: remote_service_uuid_(device::BluetoothUUID(remote_service_uuid)),
to_peripheral_char_uuid_(device::BluetoothUUID(to_peripheral_char_uuid)),
from_peripheral_char_uuid_(
device::BluetoothUUID(from_peripheral_char_uuid)),
device_whitelist_(device_whitelist),
+ bluetooth_throttler_(bluetooth_throttler),
max_number_of_tries_(max_number_of_tries),
- weak_ptr_factory_(this) {
-}
+ weak_ptr_factory_(this) {}
BluetoothLowEnergyConnectionFinder::~BluetoothLowEnergyConnectionFinder() {
if (discovery_session_) {
@@ -249,7 +252,7 @@ scoped_ptr<Connection> BluetoothLowEnergyConnectionFinder::CreateConnection(
return make_scoped_ptr(new BluetoothLowEnergyConnection(
remote_device, adapter_, remote_service_uuid_, to_peripheral_char_uuid_,
- from_peripheral_char_uuid_, max_number_of_tries_));
+ from_peripheral_char_uuid_, bluetooth_throttler_, max_number_of_tries_));
}
void BluetoothLowEnergyConnectionFinder::OnConnectionStatusChanged(
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
index bc07b3c..5d4cc52 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
@@ -25,6 +25,7 @@
namespace proximity_auth {
class BluetoothLowEnergyDeviceWhitelist;
+class BluetoothThrottler;
// This ConnectionFinder implementation is specialized in finding a Bluetooth
// Low Energy remote device.
@@ -38,6 +39,7 @@ class BluetoothLowEnergyConnectionFinder
const std::string& to_peripheral_char_uuid,
const std::string& from_peripheral_char_uuid,
const BluetoothLowEnergyDeviceWhitelist* device_whitelist,
+ BluetoothThrottler* bluetooth_throttler,
int max_number_of_tries);
~BluetoothLowEnergyConnectionFinder() override;
@@ -112,6 +114,10 @@ class BluetoothLowEnergyConnectionFinder
// cached or advertised. Not owned, must outlive this instance.
const BluetoothLowEnergyDeviceWhitelist* device_whitelist_;
+ // Throttles repeated connection attempts to the same device. This is a
+ // workaround for crbug.com/508919. Not owned, must outlive this instance.
+ BluetoothThrottler* bluetooth_throttler_;
+
// The Bluetooth adapter over which the Bluetooth connection will be made.
scoped_refptr<device::BluetoothAdapter> adapter_;
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc
index 39ee9bc..b41ec03 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder_unittest.cc
@@ -89,8 +89,8 @@ class MockBluetoothLowEnergyConnectionFinder
kToPeripheralCharUUID,
kFromPeripheralCharUUID,
device_whitelist,
- kMaxNumberOfAttempts) {
- }
+ nullptr,
+ kMaxNumberOfAttempts) {}
~MockBluetoothLowEnergyConnectionFinder() override {}
@@ -219,14 +219,14 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// should not crash.
BluetoothLowEnergyConnectionFinder connection_finder(
kServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID,
- device_whitelist_.get(), kMaxNumberOfAttempts);
+ device_whitelist_.get(), nullptr, kMaxNumberOfAttempts);
}
TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
Find_StartsDiscoverySession) {
BluetoothLowEnergyConnectionFinder connection_finder(
kServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID,
- device_whitelist_.get(), kMaxNumberOfAttempts);
+ device_whitelist_.get(), nullptr, kMaxNumberOfAttempts);
EXPECT_CALL(*adapter_, StartDiscoverySessionWithFilterRaw(_, _, _));
EXPECT_CALL(*adapter_, AddObserver(_));
@@ -237,7 +237,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
Find_StopsDiscoverySessionBeforeDestroying) {
BluetoothLowEnergyConnectionFinder connection_finder(
kServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID,
- device_whitelist_.get(), kMaxNumberOfAttempts);
+ device_whitelist_.get(), nullptr, kMaxNumberOfAttempts);
device::BluetoothAdapter::DiscoverySessionCallback discovery_callback;
scoped_ptr<device::MockBluetoothDiscoverySession> discovery_session(
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc
index 971f24a..9dbaa9c 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc
@@ -9,7 +9,9 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
+#include "base/test/test_simple_task_runner.h"
#include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_finder.h"
+#include "components/proximity_auth/bluetooth_throttler.h"
#include "components/proximity_auth/connection_finder.h"
#include "components/proximity_auth/remote_device.h"
#include "components/proximity_auth/wire_message.h"
@@ -57,11 +59,26 @@ const device::BluetoothGattCharacteristic::Properties
const int kMaxNumberOfTries = 3;
+class MockBluetoothThrottler : public BluetoothThrottler {
+ public:
+ MockBluetoothThrottler() {}
+ ~MockBluetoothThrottler() override {}
+
+ MOCK_CONST_METHOD0(GetDelay, base::TimeDelta());
+ MOCK_METHOD1(OnConnection, void(Connection* connection));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockBluetoothThrottler);
+};
+
class MockBluetoothLowEnergyCharacteristicsFinder
: public BluetoothLowEnergyCharacteristicsFinder {
public:
MockBluetoothLowEnergyCharacteristicsFinder() {}
~MockBluetoothLowEnergyCharacteristicsFinder() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyCharacteristicsFinder);
};
class MockBluetoothLowEnergyConnection : public BluetoothLowEnergyConnection {
@@ -72,15 +89,15 @@ class MockBluetoothLowEnergyConnection : public BluetoothLowEnergyConnection {
const device::BluetoothUUID remote_service_uuid,
const device::BluetoothUUID to_peripheral_char_uuid,
const device::BluetoothUUID from_peripheral_char_uuid,
+ BluetoothThrottler* bluetooth_throttler,
int max_number_of_write_attempts)
: BluetoothLowEnergyConnection(remote_device,
adapter,
remote_service_uuid,
to_peripheral_char_uuid,
from_peripheral_char_uuid,
- max_number_of_write_attempts) {
- SetDelayForTesting(base::TimeDelta());
- }
+ bluetooth_throttler,
+ max_number_of_write_attempts) {}
~MockBluetoothLowEnergyConnection() override {}
@@ -97,10 +114,14 @@ class MockBluetoothLowEnergyConnection : public BluetoothLowEnergyConnection {
// Exposing inherited protected methods for testing.
using BluetoothLowEnergyConnection::GattCharacteristicValueChanged;
+ using BluetoothLowEnergyConnection::SetTaskRunnerForTesting;
// Exposing inherited protected fields for testing.
using BluetoothLowEnergyConnection::status;
using BluetoothLowEnergyConnection::sub_status;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyConnection);
};
} // namespace
@@ -120,7 +141,9 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test {
gatt_connection_(new NiceMock<device::MockBluetoothGattConnection>(
kBluetoothAddress)),
gatt_connection_alias_(gatt_connection_.get()),
- notify_session_alias_(NULL) {}
+ notify_session_alias_(NULL),
+ bluetooth_throttler_(new NiceMock<MockBluetoothThrottler>),
+ task_runner_(new base::TestSimpleTaskRunner) {}
void SetUp() override {
device_ = make_scoped_ptr(new NiceMock<device::MockBluetoothDevice>(
@@ -162,12 +185,15 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test {
scoped_ptr<MockBluetoothLowEnergyConnection> connection(
new MockBluetoothLowEnergyConnection(
remote_device_, adapter_, service_uuid_, to_peripheral_char_uuid_,
- from_peripheral_char_uuid_, kMaxNumberOfTries));
+ from_peripheral_char_uuid_, bluetooth_throttler_.get(),
+ kMaxNumberOfTries));
EXPECT_EQ(connection->sub_status(),
BluetoothLowEnergyConnection::SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
+ connection->SetTaskRunnerForTesting(task_runner_);
+
return connection.Pass();
}
@@ -179,6 +205,10 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test {
.WillOnce(DoAll(SaveArg<0>(&create_gatt_connection_success_callback_),
SaveArg<1>(&create_gatt_connection_error_callback_)));
+ // No throttling by default
+ EXPECT_CALL(*bluetooth_throttler_, GetDelay())
+ .WillOnce(Return(base::TimeDelta()));
+
connection->Connect();
EXPECT_EQ(connection->sub_status(),
@@ -238,9 +268,8 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test {
kToPeripheralCharID));
notify_session_alias_ = notify_session.get();
- base::RunLoop run_loop;
notify_session_success_callback_.Run(notify_session.Pass());
- run_loop.RunUntilIdle();
+ task_runner_->RunUntilIdle();
EXPECT_EQ(connection->sub_status(),
BluetoothLowEnergyConnection::SubStatus::WAITING_RESPONSE_SIGNAL);
@@ -331,6 +360,8 @@ class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test {
scoped_ptr<device::MockBluetoothGattCharacteristic> from_peripheral_char_;
std::vector<uint8> last_value_written_on_to_peripheral_char_;
device::MockBluetoothGattNotifySession* notify_session_alias_;
+ scoped_ptr<MockBluetoothThrottler> bluetooth_throttler_;
+ scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
base::MessageLoop message_loop_;
// Callbacks
@@ -358,7 +389,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
CreateAndDestroyWithouthConnectCallDoesntCrash) {
BluetoothLowEnergyConnection connection(
remote_device_, adapter_, service_uuid_, to_peripheral_char_uuid_,
- from_peripheral_char_uuid_, kMaxNumberOfTries);
+ from_peripheral_char_uuid_, bluetooth_throttler_.get(),
+ kMaxNumberOfTries);
}
TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
@@ -646,4 +678,42 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
RunWriteCharacteristicSuccessCallback();
}
+TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
+ Connect_AfterADelayWhenThrottled) {
+ scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
+
+ EXPECT_CALL(*bluetooth_throttler_, GetDelay())
+ .WillOnce(Return(base::TimeDelta(base::TimeDelta::FromSeconds(1))));
+ EXPECT_CALL(*device_, CreateGattConnection(_, _))
+ .WillOnce(DoAll(SaveArg<0>(&create_gatt_connection_success_callback_),
+ SaveArg<1>(&create_gatt_connection_error_callback_)));
+
+ // No GATT connection should be created before the delay.
+ connection->Connect();
+ EXPECT_EQ(connection->sub_status(),
+ BluetoothLowEnergyConnection::SubStatus::WAITING_GATT_CONNECTION);
+ EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
+ EXPECT_TRUE(create_gatt_connection_error_callback_.is_null());
+ EXPECT_TRUE(create_gatt_connection_success_callback_.is_null());
+
+ // A GATT connection should be created after the delay.
+ task_runner_->RunUntilIdle();
+ EXPECT_FALSE(create_gatt_connection_error_callback_.is_null());
+ ASSERT_FALSE(create_gatt_connection_success_callback_.is_null());
+
+ // Preparing |connection| to run |create_gatt_connection_success_callback_|.
+ EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _))
+ .WillOnce(DoAll(
+ SaveArg<0>(&characteristics_finder_success_callback_),
+ SaveArg<1>(&characteristics_finder_error_callback_),
+ Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>)));
+
+ create_gatt_connection_success_callback_.Run(make_scoped_ptr(
+ new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress)));
+
+ CharacteristicsFound(connection.get());
+ NotifySessionStarted(connection.get());
+ ResponseSignalReceived(connection.get());
+}
+
} // namespace proximity_auth
diff --git a/components/proximity_auth/ble/proximity_auth_ble_system.cc b/components/proximity_auth/ble/proximity_auth_ble_system.cc
index 52e7e69..7d12468 100644
--- a/components/proximity_auth/ble/proximity_auth_ble_system.cc
+++ b/components/proximity_auth/ble/proximity_auth_ble_system.cc
@@ -11,10 +11,12 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/thread_task_runner_handle.h"
+#include "base/time/default_tick_clock.h"
#include "components/proximity_auth/ble/bluetooth_low_energy_connection.h"
#include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h"
#include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h"
#include "components/proximity_auth/ble/fake_wire_message.h"
+#include "components/proximity_auth/bluetooth_throttler_impl.h"
#include "components/proximity_auth/connection.h"
#include "components/proximity_auth/cryptauth/base64url.h"
#include "components/proximity_auth/cryptauth/cryptauth_client.h"
@@ -92,6 +94,8 @@ ProximityAuthBleSystem::ProximityAuthBleSystem(
proximity_auth_client_(proximity_auth_client),
cryptauth_client_factory_(cryptauth_client_factory.Pass()),
device_whitelist_(new BluetoothLowEnergyDeviceWhitelist(pref_service)),
+ bluetooth_throttler_(new BluetoothThrottlerImpl(
+ make_scoped_ptr(new base::DefaultTickClock()))),
device_authenticated_(false),
unlock_requested_(false),
is_polling_screen_state_(false),
@@ -106,6 +110,8 @@ ProximityAuthBleSystem::ProximityAuthBleSystem(
ProximityAuthClient* proximity_auth_client)
: screenlock_bridge_(screenlock_bridge.Pass()),
proximity_auth_client_(proximity_auth_client),
+ bluetooth_throttler_(new BluetoothThrottlerImpl(
+ make_scoped_ptr(new base::DefaultTickClock()))),
unlock_requested_(false),
is_polling_screen_state_(false),
unlock_keys_requested_(false),
@@ -208,7 +214,7 @@ void ProximityAuthBleSystem::OnScreenDidLock(
ConnectionFinder* ProximityAuthBleSystem::CreateConnectionFinder() {
return new BluetoothLowEnergyConnectionFinder(
kSmartLockServiceUUID, kToPeripheralCharUUID, kFromPeripheralCharUUID,
- device_whitelist_.get(), kMaxNumberOfTries);
+ device_whitelist_.get(), bluetooth_throttler_.get(), kMaxNumberOfTries);
}
void ProximityAuthBleSystem::OnScreenDidUnlock(
diff --git a/components/proximity_auth/ble/proximity_auth_ble_system.h b/components/proximity_auth/ble/proximity_auth_ble_system.h
index 59617ac..2a82aea 100644
--- a/components/proximity_auth/ble/proximity_auth_ble_system.h
+++ b/components/proximity_auth/ble/proximity_auth_ble_system.h
@@ -27,6 +27,7 @@ namespace proximity_auth {
class BluetoothLowEnergyConnection;
class BluetoothLowEnergyConnectionFinder;
class BluetoothLowEnergyDeviceWhitelist;
+class BluetoothThrottler;
class Connection;
class ConnectionFinder;
class ProximityAuthClient;
@@ -133,6 +134,8 @@ class ProximityAuthBleSystem : public ScreenlockBridge::Observer,
scoped_ptr<BluetoothLowEnergyDeviceWhitelist> device_whitelist_;
+ scoped_ptr<BluetoothThrottler> bluetooth_throttler_;
+
const base::TimeDelta polling_interval_;
// True if the remote device sent public key contained in |unlock_keyes_| or