summaryrefslogtreecommitdiffstats
path: root/components/proximity_auth
diff options
context:
space:
mode:
authorisherman <isherman@chromium.org>2015-06-30 23:04:37 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-01 06:05:13 +0000
commit3ead4bc4ebb743b3771afb47dbfbd4eb2131ef1b (patch)
tree9a89715e485cf016af038b1d4e45bdd9edc0e70d /components/proximity_auth
parent082bb470775656368f5bec9dd7a1ba4583e2bcb9 (diff)
downloadchromium_src-3ead4bc4ebb743b3771afb47dbfbd4eb2131ef1b.zip
chromium_src-3ead4bc4ebb743b3771afb47dbfbd4eb2131ef1b.tar.gz
chromium_src-3ead4bc4ebb743b3771afb47dbfbd4eb2131ef1b.tar.bz2
[Proximity Auth] Create one ProximityAuthClient per profile, rather than one global one.
BUG=501626 TEST=none R=tengs@chromium.org,mlerman@chromium.org Review URL: https://codereview.chromium.org/1209193003 Cr-Commit-Position: refs/heads/master@{#336983}
Diffstat (limited to 'components/proximity_auth')
-rw-r--r--components/proximity_auth/ble/proximity_auth_ble_system.cc19
-rw-r--r--components/proximity_auth/ble/proximity_auth_ble_system.h17
-rw-r--r--components/proximity_auth/ble/proximity_auth_ble_system_unittest.cc4
-rw-r--r--components/proximity_auth/proximity_auth_client.h22
-rw-r--r--components/proximity_auth/screenlock_bridge.cc13
-rw-r--r--components/proximity_auth/screenlock_bridge.h16
6 files changed, 33 insertions, 58 deletions
diff --git a/components/proximity_auth/ble/proximity_auth_ble_system.cc b/components/proximity_auth/ble/proximity_auth_ble_system.cc
index cfd2074..1a399b4 100644
--- a/components/proximity_auth/ble/proximity_auth_ble_system.cc
+++ b/components/proximity_auth/ble/proximity_auth_ble_system.cc
@@ -16,6 +16,7 @@
#include "components/proximity_auth/cryptauth/cryptauth_client.h"
#include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h"
#include "components/proximity_auth/logging/logging.h"
+#include "components/proximity_auth/proximity_auth_client.h"
#include "components/proximity_auth/remote_device.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_gatt_connection.h"
@@ -70,17 +71,17 @@ void ProximityAuthBleSystem::ScreenlockBridgeAdapter::RemoveObserver(
}
void ProximityAuthBleSystem::ScreenlockBridgeAdapter::Unlock(
- content::BrowserContext* browser_context) {
- screenlock_bridge_->Unlock(browser_context);
+ ProximityAuthClient* client) {
+ screenlock_bridge_->Unlock(client->GetAuthenticatedUsername());
}
ProximityAuthBleSystem::ProximityAuthBleSystem(
ScreenlockBridge* screenlock_bridge,
- content::BrowserContext* browser_context,
+ ProximityAuthClient* proximity_auth_client,
scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory)
: screenlock_bridge_(new ProximityAuthBleSystem::ScreenlockBridgeAdapter(
screenlock_bridge)),
- browser_context_(browser_context),
+ proximity_auth_client_(proximity_auth_client),
cryptauth_client_factory_(cryptauth_client_factory.Pass()),
is_polling_screen_state_(false),
weak_ptr_factory_(this) {
@@ -89,10 +90,10 @@ ProximityAuthBleSystem::ProximityAuthBleSystem(
}
ProximityAuthBleSystem::ProximityAuthBleSystem(
- ScreenlockBridgeAdapter* screenlock_bridge,
- content::BrowserContext* browser_context)
- : screenlock_bridge_(screenlock_bridge),
- browser_context_(browser_context),
+ scoped_ptr<ScreenlockBridgeAdapter> screenlock_bridge,
+ ProximityAuthClient* proximity_auth_client)
+ : screenlock_bridge_(screenlock_bridge.Pass()),
+ proximity_auth_client_(proximity_auth_client),
is_polling_screen_state_(false),
weak_ptr_factory_(this) {
PA_LOG(INFO) << "Starting Proximity Auth over Bluetooth Low Energy.";
@@ -210,7 +211,7 @@ void ProximityAuthBleSystem::OnMessageReceived(const Connection& connection,
// the Proximity Auth Unlock Manager migration to C++ is done.
if (message.payload() == kScreenUnlocked) {
PA_LOG(INFO) << "Device unlocked. Unlock.";
- screenlock_bridge_->Unlock(browser_context_);
+ screenlock_bridge_->Unlock(proximity_auth_client_);
}
}
diff --git a/components/proximity_auth/ble/proximity_auth_ble_system.h b/components/proximity_auth/ble/proximity_auth_ble_system.h
index 1444592..50f8704 100644
--- a/components/proximity_auth/ble/proximity_auth_ble_system.h
+++ b/components/proximity_auth/ble/proximity_auth_ble_system.h
@@ -15,10 +15,6 @@
#include "components/proximity_auth/cryptauth/cryptauth_client.h"
#include "components/proximity_auth/screenlock_bridge.h"
-namespace content {
-class BrowserContext;
-}
-
namespace device {
class BluetoothGattConnection;
}
@@ -29,6 +25,7 @@ class BluetoothLowEnergyConnection;
class BluetoothLowEnergyConnectionFinder;
class Connection;
class ConnectionFinder;
+class ProximityAuthClient;
// 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
@@ -39,7 +36,7 @@ class ProximityAuthBleSystem : public ScreenlockBridge::Observer,
public:
ProximityAuthBleSystem(
ScreenlockBridge* screenlock_bridge,
- content::BrowserContext* browser_context,
+ ProximityAuthClient* proximity_auth_client,
scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory);
~ProximityAuthBleSystem() override;
@@ -65,7 +62,7 @@ class ProximityAuthBleSystem : public ScreenlockBridge::Observer,
virtual void AddObserver(ScreenlockBridge::Observer* observer);
virtual void RemoveObserver(ScreenlockBridge::Observer* observer);
- virtual void Unlock(content::BrowserContext* browser_context);
+ virtual void Unlock(ProximityAuthClient* client);
protected:
ScreenlockBridgeAdapter();
@@ -76,8 +73,8 @@ class ProximityAuthBleSystem : public ScreenlockBridge::Observer,
};
// Used for testing.
- ProximityAuthBleSystem(ScreenlockBridgeAdapter* screenlock_bridge,
- content::BrowserContext* browser_context);
+ ProximityAuthBleSystem(scoped_ptr<ScreenlockBridgeAdapter> screenlock_bridge,
+ ProximityAuthClient* proximity_auth_client);
// Virtual for testing.
virtual ConnectionFinder* CreateConnectionFinder();
@@ -102,8 +99,8 @@ class ProximityAuthBleSystem : public ScreenlockBridge::Observer,
scoped_ptr<ScreenlockBridgeAdapter> screenlock_bridge_;
- content::BrowserContext*
- browser_context_; // Not owned. Must outlive this object.
+ // Not owned. Must outlive this object.
+ ProximityAuthClient* proximity_auth_client_;
// Creates CryptAuth client instances to make API calls.
scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory_;
diff --git a/components/proximity_auth/ble/proximity_auth_ble_system_unittest.cc b/components/proximity_auth/ble/proximity_auth_ble_system_unittest.cc
index 61a5638..b223e4a 100644
--- a/components/proximity_auth/ble/proximity_auth_ble_system_unittest.cc
+++ b/components/proximity_auth/ble/proximity_auth_ble_system_unittest.cc
@@ -38,11 +38,11 @@ class ProximityAuthBleSystemTestable : public ProximityAuthBleSystem {
MOCK_METHOD1(AddObserver, void(ScreenlockBridge::Observer*));
MOCK_METHOD1(RemoveObserver, void(ScreenlockBridge::Observer*));
- MOCK_METHOD1(Unlock, void(content::BrowserContext*));
+ MOCK_METHOD1(Unlock, void(ProximityAuthClient*));
};
ProximityAuthBleSystemTestable(ScreenlockBridgeAdapter* screenlock_bridge)
- : ProximityAuthBleSystem(screenlock_bridge, nullptr) {}
+ : ProximityAuthBleSystem(make_scoped_ptr(screenlock_bridge), nullptr) {}
ConnectionFinder* CreateConnectionFinder() override {
return new NiceMock<MockConnectionFinder>();
diff --git a/components/proximity_auth/proximity_auth_client.h b/components/proximity_auth/proximity_auth_client.h
index b9ad752..7a26778 100644
--- a/components/proximity_auth/proximity_auth_client.h
+++ b/components/proximity_auth/proximity_auth_client.h
@@ -7,31 +7,17 @@
#include <string>
-#include "base/macros.h"
-
-namespace content {
-class BrowserContext;
-} // namespace content
-
namespace proximity_auth {
// An interface that needs to be supplied to the Proximity Auth component by its
-// embedder.
+// embedder. There should be one |ProximityAuthClient| per
+// |content::BrowserContext|.
class ProximityAuthClient {
public:
- // Returns the authenticated username for |browser_context|.
- virtual std::string GetAuthenticatedUsername(
- content::BrowserContext* browser_context) const = 0;
-
- // Locks the screen for |browser_context|.
- virtual void Lock(content::BrowserContext* browser_context) = 0;
-
- protected:
- ProximityAuthClient() {}
virtual ~ProximityAuthClient() {}
- private:
- DISALLOW_COPY_AND_ASSIGN(ProximityAuthClient);
+ // Returns the authenticated username.
+ virtual std::string GetAuthenticatedUsername() const = 0;
};
} // namespace proximity_auth
diff --git a/components/proximity_auth/screenlock_bridge.cc b/components/proximity_auth/screenlock_bridge.cc
index 2af8378..c3dd25f5 100644
--- a/components/proximity_auth/screenlock_bridge.cc
+++ b/components/proximity_auth/screenlock_bridge.cc
@@ -6,7 +6,6 @@
#include "base/logging.h"
#include "base/strings/string16.h"
-#include "components/proximity_auth/proximity_auth_client.h"
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -49,9 +48,7 @@ std::string GetIdForIcon(ScreenlockBridge::UserPodCustomIcon icon) {
} // namespace
-ScreenlockBridge::ScreenlockBridge(ProximityAuthClient* client)
- : client_(client), lock_handler_(nullptr) {
- DCHECK(client_);
+ScreenlockBridge::ScreenlockBridge() : lock_handler_(nullptr) {
}
ScreenlockBridge::~ScreenlockBridge() {
@@ -150,19 +147,19 @@ bool ScreenlockBridge::IsLocked() const {
return lock_handler_ != nullptr;
}
-void ScreenlockBridge::Lock(content::BrowserContext* browser_context) {
+void ScreenlockBridge::Lock() {
#if defined(OS_CHROMEOS)
chromeos::SessionManagerClient* session_manager =
chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
session_manager->RequestLockScreen();
#else
- client_->Lock(browser_context);
+ NOTIMPLEMENTED();
#endif
}
-void ScreenlockBridge::Unlock(content::BrowserContext* browser_context) {
+void ScreenlockBridge::Unlock(const std::string& user_email) {
if (lock_handler_)
- lock_handler_->Unlock(client_->GetAuthenticatedUsername(browser_context));
+ lock_handler_->Unlock(user_email);
}
void ScreenlockBridge::AddObserver(Observer* observer) {
diff --git a/components/proximity_auth/screenlock_bridge.h b/components/proximity_auth/screenlock_bridge.h
index f9a47a4..92cc94f 100644
--- a/components/proximity_auth/screenlock_bridge.h
+++ b/components/proximity_auth/screenlock_bridge.h
@@ -14,14 +14,8 @@
#include "base/strings/string16.h"
#include "base/values.h"
-namespace content {
-class BrowserContext;
-} // namespace content
-
namespace proximity_auth {
-class ProximityAuthClient;
-
// ScreenlockBridge brings together the screenLockPrivate API and underlying
// support. On ChromeOS, it delegates calls to the ScreenLocker. On other
// platforms, it delegates calls to UserManagerUI (and friends).
@@ -29,8 +23,7 @@ class ProximityAuthClient;
// used solely for the lock screen anymore.
class ScreenlockBridge {
public:
- // |client| is not owned and must outlive this object.
- explicit ScreenlockBridge(ProximityAuthClient* client);
+ ScreenlockBridge();
~ScreenlockBridge();
// User pod icons supported by lock screen / signin screen UI.
@@ -165,8 +158,10 @@ class ScreenlockBridge {
void SetFocusedUser(const std::string& user_id);
bool IsLocked() const;
- void Lock(content::BrowserContext* browser_context);
- void Unlock(content::BrowserContext* browser_context);
+ void Lock();
+
+ // Unlocks the screen for the authenticated user with the given |user_email|.
+ void Unlock(const std::string& user_email);
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
@@ -176,7 +171,6 @@ class ScreenlockBridge {
std::string focused_user_id() const { return focused_user_id_; }
private:
- ProximityAuthClient* client_; // Not owned. Must outlive this object.
LockHandler* lock_handler_; // Not owned
// The last focused user's id.
std::string focused_user_id_;