summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authormsarda <msarda@chromium.org>2015-04-28 19:04:41 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-29 02:05:15 +0000
commit3f45fd5444081f44205896e6c6a211fbfaa98ed5 (patch)
treefb64aefe1f2724550a52457d50102cb58270b5d2 /components
parent3d79357fea5857f6acad36653a6a3f7282134067 (diff)
downloadchromium_src-3f45fd5444081f44205896e6c6a211fbfaa98ed5.zip
chromium_src-3f45fd5444081f44205896e6c6a211fbfaa98ed5.tar.gz
chromium_src-3f45fd5444081f44205896e6c6a211fbfaa98ed5.tar.bz2
Unlock Chrome when a phone with Smart Lock service is found.
This CL starts finding BLE phone devices that advertise smart lock services when the screen is locked. It unlocks the Chrome when such a device is found. BUG=478073 Review URL: https://codereview.chromium.org/1102473003 Cr-Commit-Position: refs/heads/master@{#327416}
Diffstat (limited to 'components')
-rw-r--r--components/proximity_auth.gypi2
-rw-r--r--components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc7
-rw-r--r--components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h2
-rw-r--r--components/proximity_auth/ble/proximity_auth_ble_system.cc67
-rw-r--r--components/proximity_auth/ble/proximity_auth_ble_system.h35
5 files changed, 95 insertions, 18 deletions
diff --git a/components/proximity_auth.gypi b/components/proximity_auth.gypi
index e10cc9c..8d8b695 100644
--- a/components/proximity_auth.gypi
+++ b/components/proximity_auth.gypi
@@ -5,6 +5,8 @@
{
'targets': [
{
+ # GN version: //components/proximity_auth and
+ # //components/proximity_auth/ble.
'target_name': 'proximity_auth',
'type': 'static_library',
'include_dirs': [
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 0fdec85..a9aea04 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc
@@ -154,7 +154,7 @@ bool BluetoothLowEnergyConnectionFinder::HasService(
void BluetoothLowEnergyConnectionFinder::OnCreateConnectionError(
BluetoothDevice::ConnectErrorCode error_code) {
- VLOG(1) << "Error creating connection";
+ VLOG(1) << "Error creating connection: " << error_code;
}
void BluetoothLowEnergyConnectionFinder::OnConnectionCreated(
@@ -162,7 +162,10 @@ void BluetoothLowEnergyConnectionFinder::OnConnectionCreated(
VLOG(1) << "Connection created";
connected_ = true;
StopDiscoverySession();
- connection_callback_.Run(connection.Pass());
+ if (!connection_callback_.is_null()) {
+ connection_callback_.Run(connection.Pass());
+ connection_callback_.Reset();
+ }
}
void BluetoothLowEnergyConnectionFinder::CreateConnection(
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 618a502..47c5727 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
@@ -29,7 +29,7 @@ class BluetoothLowEnergyConnectionFinder
BluetoothLowEnergyConnectionFinder(const std::string& remote_service_uuid);
~BluetoothLowEnergyConnectionFinder() override;
- // Finds a connection the remote device, only the first one is functional.
+ // Finds a connection to the remote device. Only the first one is functional.
void Find(const device::BluetoothDevice::GattConnectionCallback&
connection_callback);
void Find(const ConnectionCallback& connection_callback) override;
diff --git a/components/proximity_auth/ble/proximity_auth_ble_system.cc b/components/proximity_auth/ble/proximity_auth_ble_system.cc
index ecdb90d..bf4c2c7 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
diff --git a/components/proximity_auth/ble/proximity_auth_ble_system.h b/components/proximity_auth/ble/proximity_auth_ble_system.h
index 29ba662..607f4ce 100644
--- a/components/proximity_auth/ble/proximity_auth_ble_system.h
+++ b/components/proximity_auth/ble/proximity_auth_ble_system.h
@@ -7,23 +7,50 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
+#include "components/proximity_auth/screenlock_bridge.h"
-#include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h"
+namespace content {
+class BrowserContext;
+}
+
+namespace device {
+class BluetoothGattConnection;
+}
namespace proximity_auth {
+class BluetoothLowEnergyConnectionFinder;
+
// This is the main entry point to start Proximity Auth over Bluetooth Low
// Energy. This is the underlying system for the Smart Lock features. It will
// discover Bluetooth Low Energy phones and unlock the lock screen if the phone
// passes an authorization and authentication protocol.
-class ProximityAuthBleSystem {
+class ProximityAuthBleSystem : public ScreenlockBridge::Observer {
public:
- ProximityAuthBleSystem();
- ~ProximityAuthBleSystem();
+ ProximityAuthBleSystem(ScreenlockBridge* screenlock_bridge,
+ content::BrowserContext* browser_context);
+ ~ProximityAuthBleSystem() override;
+
+ // ScreenlockBridge::Observer:
+ void OnScreenDidLock(
+ ScreenlockBridge::LockHandler::ScreenType screen_type) override;
+ void OnScreenDidUnlock(
+ ScreenlockBridge::LockHandler::ScreenType screen_type) override;
+ void OnFocusedUserChanged(const std::string& user_id) override;
private:
+ // Handler for a new connection found event.
+ void OnConnectionFound(
+ scoped_ptr<device::BluetoothGattConnection> connection);
+
+ ScreenlockBridge* screenlock_bridge_; // Not owned. Must outlive this object.
+ content::BrowserContext*
+ browser_context_; // Not owned. Must outlive this object.
+
scoped_ptr<BluetoothLowEnergyConnectionFinder> connection_finder_;
+ base::WeakPtrFactory<ProximityAuthBleSystem> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(ProximityAuthBleSystem);
};