| Index: components/proximity_auth/ble/proximity_auth_ble_system.cc
|
| diff --git a/components/proximity_auth/ble/proximity_auth_ble_system.cc b/components/proximity_auth/ble/proximity_auth_ble_system.cc
|
| index ecdb90d05ef6655348ee361d1934c2e2360326cb..bf4c2c743c4fbadf473877284815b68d3d1afc3b 100644
|
| --- a/components/proximity_auth/ble/proximity_auth_ble_system.cc
|
| +++ b/components/proximity_auth/ble/proximity_auth_ble_system.cc
|
| @@ -6,31 +6,76 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/logging.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| +#include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h"
|
| #include "components/proximity_auth/connection.h"
|
| #include "device/bluetooth/bluetooth_device.h"
|
| -
|
| -#include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h"
|
| +#include "device/bluetooth/bluetooth_gatt_connection.h"
|
|
|
| namespace proximity_auth {
|
|
|
| +namespace {
|
| +
|
| +// The UUID of the Bluetooth Low Energy service.
|
| const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11";
|
|
|
| -void ConnectionCallback(
|
| - scoped_ptr<device::BluetoothGattConnection> connection) {
|
| - VLOG(1) << "Connection established";
|
| -}
|
| +} // namespace
|
|
|
| -ProximityAuthBleSystem::ProximityAuthBleSystem() {
|
| +ProximityAuthBleSystem::ProximityAuthBleSystem(
|
| + ScreenlockBridge* screenlock_bridge,
|
| + content::BrowserContext* browser_context)
|
| + : screenlock_bridge_(screenlock_bridge),
|
| + browser_context_(browser_context),
|
| + weak_ptr_factory_(this) {
|
| + DCHECK(screenlock_bridge_);
|
| + DCHECK(browser_context_);
|
| VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy.";
|
| - connection_finder_ = scoped_ptr<BluetoothLowEnergyConnectionFinder>(
|
| - new BluetoothLowEnergyConnectionFinder(kSmartLockServiceUUID));
|
| - connection_finder_->Find(base::Bind(&ConnectionCallback));
|
| + screenlock_bridge_->AddObserver(this);
|
| }
|
|
|
| ProximityAuthBleSystem::~ProximityAuthBleSystem() {
|
| VLOG(1) << "Stopping Proximity over Bluetooth Low Energy.";
|
| + screenlock_bridge_->RemoveObserver(this);
|
| +}
|
| +
|
| +void ProximityAuthBleSystem::OnScreenDidLock(
|
| + ScreenlockBridge::LockHandler::ScreenType screen_type) {
|
| + VLOG(1) << "OnScreenDidLock: " << screen_type;
|
| + switch (screen_type) {
|
| + case ScreenlockBridge::LockHandler::SIGNIN_SCREEN:
|
| + connection_finder_.reset();
|
| + break;
|
| + case ScreenlockBridge::LockHandler::LOCK_SCREEN:
|
| + DCHECK(!connection_finder_);
|
| + connection_finder_.reset(
|
| + new BluetoothLowEnergyConnectionFinder(kSmartLockServiceUUID));
|
| + connection_finder_->Find(
|
| + base::Bind(&ProximityAuthBleSystem::OnConnectionFound,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| + break;
|
| + case ScreenlockBridge::LockHandler::OTHER_SCREEN:
|
| + connection_finder_.reset();
|
| + break;
|
| + }
|
| +};
|
| +
|
| +void ProximityAuthBleSystem::OnScreenDidUnlock(
|
| + ScreenlockBridge::LockHandler::ScreenType screen_type) {
|
| + VLOG(1) << "OnScreenDidUnlock: " << screen_type;
|
| connection_finder_.reset();
|
| +};
|
| +
|
| +void ProximityAuthBleSystem::OnFocusedUserChanged(const std::string& user_id) {
|
| + VLOG(1) << "OnFocusedUserChanged: " << user_id;
|
| +};
|
| +
|
| +void ProximityAuthBleSystem::OnConnectionFound(
|
| + scoped_ptr<device::BluetoothGattConnection> connection) {
|
| + // Unlock the screen when a connection is found.
|
| + //
|
| + // Note that this magically unlocks Chrome (no user interaction is needed).
|
| + // This user experience for this operation will be greately improved once
|
| + // the Proximity Auth Unlock Manager migration to C++ is done.
|
| + screenlock_bridge_->Unlock(browser_context_);
|
| }
|
|
|
| } // namespace proximity_auth
|
|
|