Commit f80a0910 authored by msarda's avatar msarda Committed by Commit bot

Move ScreenlockBridge to components/proximity_auth.

This CL moves ScreenlockBridge to components/proximity_auth.

It also moves the usage of profile out of ScreenLockBridge as this
dependency is forbidden in //components.

TBR=rogerta,antrim,rdevlin.cronin,tengs

BUG=479670

Review URL: https://codereview.chromium.org/1096293003

Cr-Commit-Position: refs/heads/master@{#327049}
parent 89cdcdeb
......@@ -8,10 +8,10 @@
#include "chrome/browser/chromeos/login/help_app_launcher.h"
#include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/login/auth/user_context.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui.h"
......@@ -199,10 +199,10 @@ void AppLaunchSigninScreen::HandleGetUsers() {
for (user_manager::UserList::const_iterator it = users.begin();
it != users.end();
++it) {
ScreenlockBridge::LockHandler::AuthType initial_auth_type =
proximity_auth::ScreenlockBridge::LockHandler::AuthType initial_auth_type =
UserSelectionScreen::ShouldForceOnlineSignIn(*it)
? ScreenlockBridge::LockHandler::ONLINE_SIGN_IN
: ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
? proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN
: proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
base::DictionaryValue* user_dict = new base::DictionaryValue();
UserSelectionScreen::FillUserDictionary(
*it,
......
......@@ -8,10 +8,10 @@
#include <string>
#include "base/memory/ref_counted.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chromeos/login/auth/auth_status_consumer.h"
#include "chromeos/login/auth/authenticator.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
......
......@@ -13,7 +13,7 @@
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/easy_unlock_service_regular.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "components/proximity_auth/screenlock_bridge.h"
namespace chromeos {
......
......@@ -7,12 +7,13 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_reauth.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/login/auth/auth_status_consumer.h"
#include "chromeos/login/auth/user_context.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
......@@ -74,8 +75,9 @@ class ReauthHandler : public content::NotificationObserver,
screen_locker->SetLoginStatusConsumer(this);
// Show tooltip explaining reauth.
ScreenlockBridge::UserPodCustomIconOptions icon_options;
icon_options.SetIcon(ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE);
proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options;
icon_options.SetIcon(
proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE);
icon_options.SetTooltip(
l10n_util::GetStringUTF16(
IDS_SMART_LOCK_SCREENLOCK_TOOLTIP_HARDLOCK_REAUTH_USER),
......@@ -83,7 +85,7 @@ class ReauthHandler : public content::NotificationObserver,
const user_manager::UserList& lock_users = screen_locker->users();
DCHECK(lock_users.size() == 1);
ScreenlockBridge::Get()->lock_handler()->ShowUserPodCustomIcon(
GetScreenlockBridgeInstance()->lock_handler()->ShowUserPodCustomIcon(
lock_users[0]->email(), icon_options);
}
......
......@@ -18,9 +18,10 @@
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/user_manager/user_id.h"
#include "components/user_manager/user_manager.h"
#include "components/user_manager/user_type.h"
......@@ -118,14 +119,14 @@ UserSelectionScreen::UserSelectionScreen(const std::string& display_type)
}
UserSelectionScreen::~UserSelectionScreen() {
ScreenlockBridge::Get()->SetLockHandler(nullptr);
GetScreenlockBridgeInstance()->SetLockHandler(nullptr);
ui::UserActivityDetector* activity_detector = ui::UserActivityDetector::Get();
if (activity_detector->HasObserver(this))
activity_detector->RemoveObserver(this);
}
void UserSelectionScreen::InitEasyUnlock() {
ScreenlockBridge::Get()->SetLockHandler(this);
GetScreenlockBridgeInstance()->SetLockHandler(this);
}
void UserSelectionScreen::SetLoginDisplayDelegate(
......@@ -445,15 +446,15 @@ void UserSelectionScreen::SetAuthType(const std::string& user_id,
view_->SetAuthType(user_id, auth_type, initial_value);
}
ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType(
const std::string& username) const {
proximity_auth::ScreenlockBridge::LockHandler::AuthType
UserSelectionScreen::GetAuthType(const std::string& username) const {
if (user_auth_type_map_.find(username) == user_auth_type_map_.end())
return OFFLINE_PASSWORD;
return user_auth_type_map_.find(username)->second;
}
ScreenlockBridge::LockHandler::ScreenType UserSelectionScreen::GetScreenType()
const {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType
UserSelectionScreen::GetScreenType() const {
if (display_type_ == OobeUI::kLockDisplay)
return LOCK_SCREEN;
......@@ -469,7 +470,8 @@ void UserSelectionScreen::ShowBannerMessage(const base::string16& message) {
void UserSelectionScreen::ShowUserPodCustomIcon(
const std::string& user_id,
const ScreenlockBridge::UserPodCustomIconOptions& icon_options) {
const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions&
icon_options) {
scoped_ptr<base::DictionaryValue> icon = icon_options.ToDictionaryValue();
if (!icon || icon->empty())
return;
......
......@@ -15,7 +15,7 @@
#include "chrome/browser/chromeos/login/signin/token_handle_util.h"
#include "chrome/browser/chromeos/login/ui/login_display.h"
#include "chrome/browser/chromeos/login/ui/models/user_board_model.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_id.h"
#include "ui/base/user_activity/user_activity_observer.h"
......@@ -28,9 +28,10 @@ class LoginDisplayWebUIHandler;
class UserBoardView;
// This class represents User Selection screen: user pod-based login screen.
class UserSelectionScreen : public ui::UserActivityObserver,
public ScreenlockBridge::LockHandler,
public UserBoardModel {
class UserSelectionScreen
: public ui::UserActivityObserver,
public proximity_auth::ScreenlockBridge::LockHandler,
public UserBoardModel {
public:
explicit UserSelectionScreen(const std::string& display_type);
~UserSelectionScreen() override;
......@@ -61,11 +62,12 @@ class UserSelectionScreen : public ui::UserActivityObserver,
void InitEasyUnlock();
// ScreenlockBridge::LockHandler implementation:
// proximity_auth::ScreenlockBridge::LockHandler implementation:
void ShowBannerMessage(const base::string16& message) override;
void ShowUserPodCustomIcon(
const std::string& user_email,
const ScreenlockBridge::UserPodCustomIconOptions& icon) override;
const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& icon)
override;
void HideUserPodCustomIcon(const std::string& user_email) override;
void EnableInput() override;
......@@ -135,7 +137,7 @@ class UserSelectionScreen : public ui::UserActivityObserver,
// Map of usernames to their current authentication type. If a user is not
// contained in the map, it is using the default authentication type.
std::map<std::string, ScreenlockBridge::LockHandler::AuthType>
std::map<std::string, proximity_auth::ScreenlockBridge::LockHandler::AuthType>
user_auth_type_map_;
// Timer for measuring idle state duration before password clear.
......
......@@ -10,7 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "components/proximity_auth/screenlock_bridge.h"
namespace chromeos {
......@@ -35,9 +35,10 @@ class UserBoardView {
virtual void ShowUserPodCustomIcon(const std::string& user_id,
const base::DictionaryValue& icon) = 0;
virtual void HideUserPodCustomIcon(const std::string& user_id) = 0;
virtual void SetAuthType(const std::string& user_id,
ScreenlockBridge::LockHandler::AuthType auth_type,
const base::string16& initial_value) = 0;
virtual void SetAuthType(
const std::string& user_id,
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type,
const base::string16& initial_value) = 0;
};
} // namespace chromeos
......
......@@ -17,12 +17,12 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/proximity_auth/proximity_auth_error_bubble.h"
#include "chrome/common/extensions/api/easy_unlock_private.h"
#include "chrome/grit/generated_resources.h"
#include "components/proximity_auth/bluetooth_util.h"
#include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/proximity_auth/switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
......
......@@ -8,6 +8,7 @@
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chrome/common/extensions/api/screenlock_private.h"
#include "chrome/common/extensions/extension_constants.h"
#include "extensions/browser/app_window/app_window_registry.h"
......@@ -20,23 +21,23 @@ namespace extensions {
namespace {
screenlock::AuthType FromLockHandlerAuthType(
ScreenlockBridge::LockHandler::AuthType auth_type) {
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type) {
switch (auth_type) {
case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD:
case proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD:
return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
case ScreenlockBridge::LockHandler::NUMERIC_PIN:
case proximity_auth::ScreenlockBridge::LockHandler::NUMERIC_PIN:
return screenlock::AUTH_TYPE_NUMERICPIN;
case ScreenlockBridge::LockHandler::USER_CLICK:
case proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK:
return screenlock::AUTH_TYPE_USERCLICK;
case ScreenlockBridge::LockHandler::ONLINE_SIGN_IN:
case proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN:
// Apps should treat forced online sign in same as system password.
return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
case ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK:
case proximity_auth::ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK:
// This type is used for public sessions, which do not support screen
// locking.
NOTREACHED();
return screenlock::AUTH_TYPE_NONE;
case ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD:
case proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD:
return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
}
NOTREACHED();
......@@ -50,7 +51,8 @@ ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {}
ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {}
bool ScreenlockPrivateGetLockedFunction::RunAsync() {
SetResult(new base::FundamentalValue(ScreenlockBridge::Get()->IsLocked()));
SetResult(
new base::FundamentalValue(GetScreenlockBridgeInstance()->IsLocked()));
SendResponse(error_.empty());
return true;
}
......@@ -75,9 +77,9 @@ bool ScreenlockPrivateSetLockedFunction::RunAsync() {
if (service)
service->SetTrialRun();
}
ScreenlockBridge::Get()->Lock(GetProfile());
GetScreenlockBridgeInstance()->Lock(GetProfile());
} else {
ScreenlockBridge::Get()->Unlock(GetProfile());
GetScreenlockBridgeInstance()->Unlock(GetProfile());
}
SendResponse(error_.empty());
return true;
......@@ -104,19 +106,19 @@ bool ScreenlockPrivateAcceptAuthAttemptFunction::RunSync() {
ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter(
content::BrowserContext* context)
: browser_context_(context) {
ScreenlockBridge::Get()->AddObserver(this);
GetScreenlockBridgeInstance()->AddObserver(this);
}
ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {}
void ScreenlockPrivateEventRouter::OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
DispatchEvent(screenlock::OnChanged::kEventName,
new base::FundamentalValue(true));
}
void ScreenlockPrivateEventRouter::OnScreenDidUnlock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
DispatchEvent(screenlock::OnChanged::kEventName,
new base::FundamentalValue(false));
}
......@@ -146,11 +148,11 @@ ScreenlockPrivateEventRouter::GetFactoryInstance() {
}
void ScreenlockPrivateEventRouter::Shutdown() {
ScreenlockBridge::Get()->RemoveObserver(this);
GetScreenlockBridgeInstance()->RemoveObserver(this);
}
bool ScreenlockPrivateEventRouter::OnAuthAttempted(
ScreenlockBridge::LockHandler::AuthType auth_type,
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type,
const std::string& value) {
extensions::EventRouter* router =
extensions::EventRouter::Get(browser_context_);
......
......@@ -8,7 +8,7 @@
#include <string>
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
namespace extensions {
......@@ -50,14 +50,16 @@ class ScreenlockPrivateAcceptAuthAttemptFunction
DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateAcceptAuthAttemptFunction);
};
class ScreenlockPrivateEventRouter : public extensions::BrowserContextKeyedAPI,
public ScreenlockBridge::Observer {
class ScreenlockPrivateEventRouter
: public extensions::BrowserContextKeyedAPI,
public proximity_auth::ScreenlockBridge::Observer {
public:
explicit ScreenlockPrivateEventRouter(content::BrowserContext* context);
~ScreenlockPrivateEventRouter() override;
bool OnAuthAttempted(ScreenlockBridge::LockHandler::AuthType auth_type,
const std::string& value);
bool OnAuthAttempted(
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type,
const std::string& value);
// BrowserContextKeyedAPI
static extensions::BrowserContextKeyedAPIFactory<
......@@ -65,11 +67,12 @@ class ScreenlockPrivateEventRouter : public extensions::BrowserContextKeyedAPI,
GetFactoryInstance();
void Shutdown() override;
// ScreenlockBridge::Observer
void OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
// proximity_auth::ScreenlockBridge::Observer
void OnScreenDidLock(proximity_auth::ScreenlockBridge::LockHandler::ScreenType
screen_type) override;
void OnScreenDidUnlock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type)
override;
void OnFocusedUserChanged(const std::string& user_id) override;
private:
......
......@@ -10,6 +10,7 @@
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/signin/core/common/profile_management_switches.h"
......@@ -75,9 +76,8 @@ class ScreenlockPrivateApiTest : public ExtensionApiTest,
const content::NotificationDetails& details) override {
const std::string& content = *content::Details<std::string>(details).ptr();
if (content == kAttemptClickAuthMessage) {
ScreenlockBridge::Get()->lock_handler()->SetAuthType(
kTestUser,
ScreenlockBridge::LockHandler::USER_CLICK,
GetScreenlockBridgeInstance()->lock_handler()->SetAuthType(
kTestUser, proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK,
base::string16());
EasyUnlockService::Get(profile())->AttemptAuth(kTestUser);
}
......
......@@ -7,7 +7,8 @@
#include "base/bind.h"
#include "base/logging.h"
#include "chrome/browser/signin/easy_unlock_app_manager.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "crypto/encryptor.h"
#include "crypto/symmetric_key.h"
......@@ -50,25 +51,25 @@ void DefaultAuthAttemptFinalizedHandler(
const std::string& user_id,
const std::string& key_secret,
const std::string& key_label) {
if (!ScreenlockBridge::Get()->IsLocked())
if (!GetScreenlockBridgeInstance()->IsLocked())
return;
switch (auth_attempt_type) {
case EasyUnlockAuthAttempt::TYPE_UNLOCK:
if (success) {
ScreenlockBridge::Get()->lock_handler()->Unlock(user_id);
GetScreenlockBridgeInstance()->lock_handler()->Unlock(user_id);
} else {
ScreenlockBridge::Get()->lock_handler()->EnableInput();
GetScreenlockBridgeInstance()->lock_handler()->EnableInput();
}
return;
case EasyUnlockAuthAttempt::TYPE_SIGNIN:
if (success) {
ScreenlockBridge::Get()->lock_handler()->AttemptEasySignin(
GetScreenlockBridgeInstance()->lock_handler()->AttemptEasySignin(
user_id, key_secret, key_label);
} else {
// Attempting signin with an empty secret is equivalent to canceling the
// attempt.
ScreenlockBridge::Get()->lock_handler()->AttemptEasySignin(
GetScreenlockBridgeInstance()->lock_handler()->AttemptEasySignin(
user_id, std::string(), std::string());
}
return;
......@@ -99,13 +100,13 @@ EasyUnlockAuthAttempt::~EasyUnlockAuthAttempt() {
bool EasyUnlockAuthAttempt::Start() {
DCHECK_EQ(STATE_IDLE, state_);
if (!ScreenlockBridge::Get()->IsLocked())
if (!GetScreenlockBridgeInstance()->IsLocked())
return false;
ScreenlockBridge::LockHandler::AuthType auth_type =
ScreenlockBridge::Get()->lock_handler()->GetAuthType(user_id_);
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type =
GetScreenlockBridgeInstance()->lock_handler()->GetAuthType(user_id_);
if (auth_type != ScreenlockBridge::LockHandler::USER_CLICK) {
if (auth_type != proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) {
Cancel(user_id_);
return false;
}
......@@ -125,7 +126,7 @@ void EasyUnlockAuthAttempt::FinalizeUnlock(const std::string& user_id,
if (state_ != STATE_RUNNING || user_id != user_id_)
return;
if (!ScreenlockBridge::Get()->IsLocked())
if (!GetScreenlockBridgeInstance()->IsLocked())
return;
if (type_ != TYPE_UNLOCK) {
......@@ -144,7 +145,7 @@ void EasyUnlockAuthAttempt::FinalizeSignin(const std::string& user_id,
if (state_ != STATE_RUNNING || user_id != user_id_)
return;
if (!ScreenlockBridge::Get()->IsLocked())
if (!GetScreenlockBridgeInstance()->IsLocked())
return;
if (type_ != TYPE_SIGNIN) {
......
......@@ -14,7 +14,7 @@
namespace {
ScreenlockBridge::UserPodCustomIcon GetIconForState(
proximity_auth::ScreenlockBridge::UserPodCustomIcon GetIconForState(
EasyUnlockScreenlockStateHandler::State state) {
switch (state) {
case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH:
......@@ -24,20 +24,21 @@ ScreenlockBridge::UserPodCustomIcon GetIconForState(
case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE:
case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED:
case EasyUnlockScreenlockStateHandler::STATE_RSSI_TOO_LOW:
return ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED;
return proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED;
case EasyUnlockScreenlockStateHandler::STATE_TX_POWER_TOO_HIGH:
case EasyUnlockScreenlockStateHandler::
STATE_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH:
// TODO(isherman): This icon is currently identical to the regular locked
// icon. Once the reduced proximity range flag is removed, consider
// deleting the redundant icon.
return ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED_WITH_PROXIMITY_HINT;
return proximity_auth::ScreenlockBridge::
USER_POD_CUSTOM_ICON_LOCKED_WITH_PROXIMITY_HINT;
case EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING:
return ScreenlockBridge::USER_POD_CUSTOM_ICON_SPINNER;
return proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_SPINNER;
case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED:
return ScreenlockBridge::USER_POD_CUSTOM_ICON_UNLOCKED;
return proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_UNLOCKED;
default:
return ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE;
return proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE;
}
}
......@@ -93,11 +94,10 @@ bool IsLockedState(EasyUnlockScreenlockStateHandler::State state) {
} // namespace
EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler(
const std::string& user_email,
HardlockState initial_hardlock_state,
ScreenlockBridge* screenlock_bridge)
proximity_auth::ScreenlockBridge* screenlock_bridge)
: state_(STATE_INACTIVE),
user_email_(user_email),
screenlock_bridge_(screenlock_bridge),
......@@ -140,7 +140,7 @@ void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) {
// Do nothing when auth type is online.
if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) ==
ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) {
proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN) {
return;
}
......@@ -155,14 +155,15 @@ void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) {
UpdateScreenlockAuthType();
ScreenlockBridge::UserPodCustomIcon icon = GetIconForState(state_);
proximity_auth::ScreenlockBridge::UserPodCustomIcon icon =
GetIconForState(state_);
if (icon == ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) {
if (icon == proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) {
screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_);
return;
}
ScreenlockBridge::UserPodCustomIconOptions icon_options;
proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options;
icon_options.SetIcon(icon);
// Don't hardlock on trial run.
......@@ -222,13 +223,13 @@ void EasyUnlockScreenlockStateHandler::RecordClickOnLockIcon() {
}
void EasyUnlockScreenlockStateHandler::OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
did_see_locked_phone_ = IsLockedState(state_);
RefreshScreenlockState();
}
void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
if (hardlock_state_ == LOGIN_FAILED)
hardlock_state_ = NO_HARDLOCK;
hardlock_ui_shown_ = false;
......@@ -259,15 +260,18 @@ void EasyUnlockScreenlockStateHandler::ShowHardlockUI() {
return;
// Do not override online signin.
const ScreenlockBridge::LockHandler::AuthType existing_auth_type =
screenlock_bridge_->lock_handler()->GetAuthType(user_email_);
if (existing_auth_type == ScreenlockBridge::LockHandler::ONLINE_SIGN_IN)
const proximity_auth::ScreenlockBridge::LockHandler::AuthType
existing_auth_type =
screenlock_bridge_->lock_handler()->GetAuthType(user_email_);
if (existing_auth_type ==
proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN)
return;
if (existing_auth_type != ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) {
if (existing_auth_type !=
proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) {
screenlock_bridge_->lock_handler()->SetAuthType(
user_email_,
ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
base::string16());
}
......@@ -280,15 +284,17 @@ void EasyUnlockScreenlockStateHandler::ShowHardlockUI() {
if (hardlock_ui_shown_)
return;
ScreenlockBridge::UserPodCustomIconOptions icon_options;
proximity_auth::ScreenlockBridge::UserPodCustomIconOptions icon_options;
if (hardlock_state_ == LOGIN_FAILED) {
icon_options.SetIcon(ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED);
icon_options.SetIcon(
proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED);
} else if (hardlock_state_ == PAIRING_CHANGED ||
hardlock_state_ == PAIRING_ADDED) {
icon_options.SetIcon(
ScreenlockBridge::USER_POD_CUSTOM_ICON_LOCKED_TO_BE_ACTIVATED);
icon_options.SetIcon(proximity_auth::ScreenlockBridge::
USER_POD_CUSTOM_ICON_LOCKED_TO_BE_ACTIVATED);
} else {
icon_options.SetIcon(ScreenlockBridge::USER_POD_CUSTOM_ICON_HARDLOCKED);
icon_options.SetIcon(
proximity_auth::ScreenlockBridge::USER_POD_CUSTOM_ICON_HARDLOCKED);
}
base::string16 device_name = GetDeviceName();
......@@ -317,7 +323,7 @@ void EasyUnlockScreenlockStateHandler::ShowHardlockUI() {
}
void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions(
ScreenlockBridge::UserPodCustomIconOptions* icon_options) {
proximity_auth::ScreenlockBridge::UserPodCustomIconOptions* icon_options) {
size_t resource_id = 0;
base::string16 device_name;
if (is_trial_run_ && state_ == STATE_AUTHENTICATED) {
......@@ -360,23 +366,26 @@ void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() {
return;
// Do not override online signin.
const ScreenlockBridge::LockHandler::AuthType existing_auth_type =
screenlock_bridge_->lock_handler()->GetAuthType(user_email_);
DCHECK_NE(ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, existing_auth_type);
const proximity_auth::ScreenlockBridge::LockHandler::AuthType
existing_auth_type =
screenlock_bridge_->lock_handler()->GetAuthType(user_email_);
DCHECK_NE(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN,
existing_auth_type);
if (state_ == STATE_AUTHENTICATED) {
if (existing_auth_type != ScreenlockBridge::LockHandler::USER_CLICK) {
if (existing_auth_type !=
proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK) {
screenlock_bridge_->lock_handler()->SetAuthType(
user_email_,
ScreenlockBridge::LockHandler::USER_CLICK,
proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK,
l10n_util::GetStringUTF16(
IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE));
}
} else if (existing_auth_type !=
ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) {
proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) {
screenlock_bridge_->lock_handler()->SetAuthType(
user_email_,
ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
base::string16());
}
}
......@@ -8,13 +8,14 @@
#include <string>
#include "base/strings/string16.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "components/proximity_auth/screenlock_bridge.h"
class PrefService;
// Profile specific class responsible for updating screenlock UI for the user
// associated with the profile when their Easy Unlock state changes.
class EasyUnlockScreenlockStateHandler : public ScreenlockBridge::Observer {
class EasyUnlockScreenlockStateHandler
: public proximity_auth::ScreenlockBridge::Observer {
public:
// Available Easy Unlock states.
enum State {
......@@ -71,9 +72,10 @@ class EasyUnlockScreenlockStateHandler : public ScreenlockBridge::Observer {
// |initial_hardlock_state|: The initial hardlock state.
// |screenlock_bridge|: The screenlock bridge used to update the screen lock
// state.
EasyUnlockScreenlockStateHandler(const std::string& user_email,
HardlockState initial_hardlock_state,
ScreenlockBridge* screenlock_bridge);
EasyUnlockScreenlockStateHandler(
const std::string& user_email,
HardlockState initial_hardlock_state,
proximity_auth::ScreenlockBridge* screenlock_bridge);
~EasyUnlockScreenlockStateHandler() override;
// Returns true if handler is not in INACTIVE state.
......@@ -104,11 +106,12 @@ class EasyUnlockScreenlockStateHandler : public ScreenlockBridge::Observer {
State state() const { return state_; }
private:
// ScreenlockBridge::Observer:
void OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
// proximity_auth::ScreenlockBridge::Observer:
void OnScreenDidLock(proximity_auth::ScreenlockBridge::LockHandler::ScreenType
screen_type) override;
void OnScreenDidUnlock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type)
override;
void OnFocusedUserChanged(const std::string& user_id) override;
// Forces refresh of the Easy Unlock screenlock UI.
......@@ -118,7 +121,7 @@ class EasyUnlockScreenlockStateHandler : public ScreenlockBridge::Observer {
// Updates icon's tooltip options.
void UpdateTooltipOptions(
ScreenlockBridge::UserPodCustomIconOptions* icon_options);
proximity_auth::ScreenlockBridge::UserPodCustomIconOptions* icon_options);
// Gets the name to be used for the device. The name depends on the device
// type (example values: Chromebook and Chromebox).
......@@ -129,7 +132,7 @@ class EasyUnlockScreenlockStateHandler : public ScreenlockBridge::Observer {
State state_;
std::string user_email_;
ScreenlockBridge* screenlock_bridge_;
proximity_auth::ScreenlockBridge* screenlock_bridge_;
// State of hardlock.
HardlockState hardlock_state_;
......
......@@ -22,12 +22,13 @@
#include "chrome/browser/signin/easy_unlock_app_manager.h"
#include "chrome/browser/signin/easy_unlock_service_factory.h"
#include "chrome/browser/signin/easy_unlock_service_observer.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/proximity_auth/ble/proximity_auth_ble_system.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/proximity_auth/switches.h"
#include "components/user_manager/user.h"
#include "device/bluetooth/bluetooth_adapter.h"
......@@ -446,9 +447,7 @@ EasyUnlockScreenlockStateHandler*
return NULL;
if (!screenlock_state_handler_) {
screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler(
GetUserEmail(),
GetHardlockState(),
ScreenlockBridge::Get()));
GetUserEmail(), GetHardlockState(), GetScreenlockBridgeInstance()));
}
return screenlock_state_handler_.get();
}
......
......@@ -14,7 +14,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/api/easy_unlock_private.h"
......@@ -24,6 +24,7 @@
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h"
#include "components/proximity_auth/cryptauth/cryptauth_client_impl.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/proximity_auth/switches.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
......@@ -92,7 +93,12 @@ EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const {
}
std::string EasyUnlockServiceRegular::GetUserEmail() const {
return ScreenlockBridge::GetAuthenticatedUserEmail(profile());
const SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfileIfExists(profile());
// |profile| has to be a signed-in profile with SigninManager already
// created. Otherwise, just crash to collect stack.
DCHECK(signin_manager);
return signin_manager->GetAuthenticatedUsername();
}
void EasyUnlockServiceRegular::LaunchSetup() {
......@@ -298,7 +304,7 @@ void EasyUnlockServiceRegular::SetAutoPairingResult(
}
void EasyUnlockServiceRegular::InitializeInternal() {
ScreenlockBridge::Get()->AddObserver(this);
GetScreenlockBridgeInstance()->AddObserver(this);
registrar_.Init(profile()->GetPrefs());
registrar_.Add(
prefs::kEasyUnlockAllowed,
......@@ -317,7 +323,7 @@ void EasyUnlockServiceRegular::ShutdownInternal() {
turn_off_flow_status_ = EasyUnlockService::IDLE;
registrar_.RemoveAll();
ScreenlockBridge::Get()->RemoveObserver(this);
GetScreenlockBridgeInstance()->RemoveObserver(this);
}
bool EasyUnlockServiceRegular::IsAllowedInternal() const {
......@@ -354,16 +360,16 @@ void EasyUnlockServiceRegular::OnSuspendDone() {
}
void EasyUnlockServiceRegular::OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
will_unlock_using_easy_unlock_ = false;
lock_screen_last_shown_timestamp_ = base::TimeTicks::Now();
}
void EasyUnlockServiceRegular::OnScreenDidUnlock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
// Notifications of signin screen unlock events can also reach this code path;
// disregard them.
if (screen_type != ScreenlockBridge::LockHandler::LOCK_SCREEN)
if (screen_type != proximity_auth::ScreenlockBridge::LockHandler::LOCK_SCREEN)
return;
// Only record metrics for users who have enabled the feature.
......
......@@ -13,7 +13,7 @@
#include "base/prefs/pref_change_registrar.h"
#include "base/time/time.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "components/proximity_auth/screenlock_bridge.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/easy_unlock/short_lived_user_context.h"
......@@ -38,8 +38,9 @@ class Profile;
// EasyUnlockService instance that should be used for regular, non-signin
// profiles.
class EasyUnlockServiceRegular : public EasyUnlockService,
public ScreenlockBridge::Observer {
class EasyUnlockServiceRegular
: public EasyUnlockService,
public proximity_auth::ScreenlockBridge::Observer {
public:
explicit EasyUnlockServiceRegular(Profile* profile);
~EasyUnlockServiceRegular() override;
......@@ -70,11 +71,12 @@ class EasyUnlockServiceRegular : public EasyUnlockService,
void OnWillFinalizeUnlock(bool success) override;
void OnSuspendDone() override;
// ScreenlockBridge::Observer implementation:
void OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
// proximity_auth::ScreenlockBridge::Observer implementation:
void OnScreenDidLock(proximity_auth::ScreenlockBridge::LockHandler::ScreenType
screen_type) override;
void OnScreenDidUnlock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type)
override;
void OnFocusedUserChanged(const std::string& user_id) override;
......
......@@ -16,6 +16,7 @@
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/signin/easy_unlock_app_manager.h"
#include "chrome/browser/signin/easy_unlock_metrics.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chromeos/login/auth/user_context.h"
#include "chromeos/tpm/tpm_token_loader.h"
......@@ -222,7 +223,8 @@ void EasyUnlockServiceSignin::InitializeInternal() {
service_active_ = true;
chromeos::LoginState::Get()->AddObserver(this);
ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get();
proximity_auth::ScreenlockBridge* screenlock_bridge =
GetScreenlockBridgeInstance();
screenlock_bridge->AddObserver(this);
if (!screenlock_bridge->focused_user_id().empty())
OnFocusedUserChanged(screenlock_bridge->focused_user_id());
......@@ -234,7 +236,7 @@ void EasyUnlockServiceSignin::ShutdownInternal() {
service_active_ = false;
weak_ptr_factory_.InvalidateWeakPtrs();
ScreenlockBridge::Get()->RemoveObserver(this);
GetScreenlockBridgeInstance()->RemoveObserver(this);
chromeos::LoginState::Get()->RemoveObserver(this);
STLDeleteContainerPairSecondPointers(user_data_.begin(), user_data_.end());
user_data_.clear();
......@@ -257,10 +259,11 @@ void EasyUnlockServiceSignin::OnSuspendDone() {
}
void EasyUnlockServiceSignin::OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
// In production code, the screen type should always be the signin screen; but
// in tests, the screen type might be different.
if (screen_type != ScreenlockBridge::LockHandler::SIGNIN_SCREEN)
if (screen_type !=
proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN)
return;
// Update initial UI is when the account picker on login screen is ready.
......@@ -269,10 +272,11 @@ void EasyUnlockServiceSignin::OnScreenDidLock(
}
void EasyUnlockServiceSignin::OnScreenDidUnlock(
ScreenlockBridge::LockHandler::ScreenType screen_type) {
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
// In production code, the screen type should always be the signin screen; but
// in tests, the screen type might be different.
if (screen_type != ScreenlockBridge::LockHandler::SIGNIN_SCREEN)
if (screen_type !=
proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN)
return;
DisableAppWithoutResettingScreenlockState();
......
......@@ -15,13 +15,14 @@
#include "base/values.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chromeos/login/login_state.h"
#include "components/proximity_auth/screenlock_bridge.h"
// EasyUnlockService instance that should be used for signin profile.
class EasyUnlockServiceSignin : public EasyUnlockService,
public ScreenlockBridge::Observer,
public chromeos::LoginState::Observer {
class EasyUnlockServiceSignin
: public EasyUnlockService,
public proximity_auth::ScreenlockBridge::Observer,
public chromeos::LoginState::Observer {
public:
explicit EasyUnlockServiceSignin(Profile* profile);
~EasyUnlockServiceSignin() override;
......@@ -85,11 +86,12 @@ class EasyUnlockServiceSignin : public EasyUnlockService,
void OnWillFinalizeUnlock(bool success) override;
void OnSuspendDone() override;
// ScreenlockBridge::Observer implementation:
void OnScreenDidLock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
// proximity_auth::ScreenlockBridge::Observer implementation:
void OnScreenDidLock(proximity_auth::ScreenlockBridge::LockHandler::ScreenType
screen_type) override;
void OnScreenDidUnlock(
ScreenlockBridge::LockHandler::ScreenType screen_type) override;
proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type)
override;
void OnFocusedUserChanged(const std::string& user_id) override;
// chromeos::LoginState::Observer implementation:
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/proximity_auth/proximity_auth_client.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/signin/core/browser/signin_manager_base.h"
namespace {
// A Chrome-specific implementation of the ProximityAuthClient.
class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient {
public:
ChromeProximityAuthClient() {}
~ChromeProximityAuthClient() override {}
// proximity_auth::ProximityAuthClient implementation:
std::string GetAuthenticatedUsername(
content::BrowserContext* browser_context) const override;
void Lock(content::BrowserContext* browser_context) override;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeProximityAuthClient);
};
std::string ChromeProximityAuthClient::GetAuthenticatedUsername(
content::BrowserContext* browser_context) const {
Profile* profile = Profile::FromBrowserContext(browser_context);
const SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfileIfExists(profile);
// |profile| has to be a signed-in profile with SigninManager already
// created. Otherwise, just crash to collect stack.
DCHECK(signin_manager);
return signin_manager->GetAuthenticatedUsername();
}
void ChromeProximityAuthClient::Lock(content::BrowserContext* browser_context) {
profiles::LockProfile(Profile::FromBrowserContext(browser_context));
}
// A facade class that is the glue required to initialize and manage the
// lifecycle of various objects of the Proximity Auth component.
class ProximityAuthFacade {
public:
proximity_auth::ScreenlockBridge* GetScreenlockBridge() {
return &screenlock_bridge_;
}
private:
friend struct base::DefaultLazyInstanceTraits<ProximityAuthFacade>;
friend struct base::DefaultDeleter<ProximityAuthFacade>;
ProximityAuthFacade() : screenlock_bridge_(&proximity_auth_client_) {}
~ProximityAuthFacade() {}
ChromeProximityAuthClient proximity_auth_client_;
proximity_auth::ScreenlockBridge screenlock_bridge_;
DISALLOW_COPY_AND_ASSIGN(ProximityAuthFacade);
};
base::LazyInstance<ProximityAuthFacade> g_proximity_auth_facade_instance =
LAZY_INSTANCE_INITIALIZER;
} // namespace
proximity_auth::ScreenlockBridge* GetScreenlockBridgeInstance() {
return g_proximity_auth_facade_instance.Pointer()->GetScreenlockBridge();
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SIGNIN_PROXIMITY_AUTH_FACADE_H_
#define CHROME_BROWSER_SIGNIN_PROXIMITY_AUTH_FACADE_H_
namespace proximity_auth {
class ScreenlockBridge;
}
// Returns the global proximity_auth::ScreenlockBridge instance.
proximity_auth::ScreenlockBridge* GetScreenlockBridgeInstance();
#endif // CHROME_BROWSER_SIGNIN_PROXIMITY_AUTH_FACADE_H_
......@@ -51,6 +51,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
......@@ -294,8 +295,8 @@ SigninScreenHandler::~SigninScreenHandler() {
max_mode_delegate_->RemoveObserver(this);
max_mode_delegate_.reset(NULL);
}
ScreenlockBridge::Get()->SetLockHandler(NULL);
ScreenlockBridge::Get()->SetFocusedUser("");
GetScreenlockBridgeInstance()->SetLockHandler(NULL);
GetScreenlockBridgeInstance()->SetFocusedUser("");
}
// static
......@@ -1256,7 +1257,7 @@ void SigninScreenHandler::HandleUpdateOfflineLogin(bool offline_login_active) {
void SigninScreenHandler::HandleFocusPod(const std::string& user_id) {
SetUserInputMethod(user_id, ime_state_.get());
WallpaperManager::Get()->SetUserWallpaperDelayed(user_id);
ScreenlockBridge::Get()->SetFocusedUser(user_id);
GetScreenlockBridgeInstance()->SetFocusedUser(user_id);
if (delegate_)
delegate_->CheckUserStatus(user_id);
if (!test_focus_pod_callback_.is_null())
......
......@@ -20,12 +20,12 @@
#include "chrome/browser/chromeos/login/signin_specifics.h"
#include "chrome/browser/chromeos/login/ui/login_display.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/browser/ui/webui/chromeos/touch_view_controller_delegate.h"
#include "chromeos/network/portal_detector/network_portal_detector.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
......
......@@ -8,9 +8,9 @@
#include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
#include "chrome/browser/chromeos/login/users/multi_profile_user_controller_delegate.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "components/user_manager/user.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -68,8 +68,8 @@ class SigninPrepareUserListTest
FakeChromeUserManager* fake_user_manager_;
ScopedUserManagerEnabler user_manager_enabler_;
scoped_ptr<TestingProfileManager> profile_manager_;
std::map<std::string,
ScreenlockBridge::LockHandler::AuthType> user_auth_type_map;
std::map<std::string, proximity_auth::ScreenlockBridge::LockHandler::AuthType>
user_auth_type_map;
scoped_ptr<MultiProfileUserController> controller_;
DISALLOW_COPY_AND_ASSIGN(SigninPrepareUserListTest);
......
......@@ -225,10 +225,8 @@ void SupervisedUserCreationScreenHandler::Show() {
bool is_owner = ((*it)->email() == owner);
base::DictionaryValue* user_dict = new base::DictionaryValue();
UserSelectionScreen::FillUserDictionary(
*it,
is_owner,
false, /* is_signin_to_add */
ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
*it, is_owner, false, /* is_signin_to_add */
proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
NULL, /* public_session_recommended_locales */
user_dict);
users_list->Append(user_dict);
......
......@@ -87,7 +87,7 @@ void UserBoardScreenHandler::HideUserPodCustomIcon(const std::string& user_id) {
void UserBoardScreenHandler::SetAuthType(
const std::string& user_id,
ScreenlockBridge::LockHandler::AuthType auth_type,
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type,
const base::string16& initial_value) {
CallJS("login.AccountPickerScreen.setAuthType", user_id,
static_cast<int>(auth_type), base::StringValue(initial_value));
......
......@@ -47,9 +47,10 @@ class UserBoardScreenHandler : public BaseScreenHandler, public UserBoardView {
void ShowUserPodCustomIcon(const std::string& user_id,
const base::DictionaryValue& icon) override;
void HideUserPodCustomIcon(const std::string& user_id) override;
void SetAuthType(const std::string& user_id,
ScreenlockBridge::LockHandler::AuthType auth_type,
const base::string16& initial_value) override;
void SetAuthType(
const std::string& user_id,
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type,
const base::string16& initial_value) override;
void Bind(UserBoardModel& model) override;
void Unbind() override;
......
......@@ -22,6 +22,7 @@
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/local_auth.h"
#include "chrome/browser/signin/proximity_auth_facade.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
......@@ -297,7 +298,7 @@ UserManagerScreenHandler::UserManagerScreenHandler()
}
UserManagerScreenHandler::~UserManagerScreenHandler() {
ScreenlockBridge::Get()->SetLockHandler(NULL);
GetScreenlockBridgeInstance()->SetLockHandler(NULL);
}
void UserManagerScreenHandler::ShowBannerMessage(
......@@ -309,7 +310,8 @@ void UserManagerScreenHandler::ShowBannerMessage(
void UserManagerScreenHandler::ShowUserPodCustomIcon(
const std::string& user_email,
const ScreenlockBridge::UserPodCustomIconOptions& icon_options) {
const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions&
icon_options) {
scoped_ptr<base::DictionaryValue> icon = icon_options.ToDictionaryValue();
if (!icon || icon->empty())
return;
......@@ -332,10 +334,10 @@ void UserManagerScreenHandler::EnableInput() {
void UserManagerScreenHandler::SetAuthType(
const std::string& user_email,
ScreenlockBridge::LockHandler::AuthType auth_type,
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type,
const base::string16& auth_value) {
if (GetAuthType(user_email) ==
ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD)
proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD)
return;
user_auth_type_map_[user_email] = auth_type;
......@@ -346,17 +348,17 @@ void UserManagerScreenHandler::SetAuthType(
base::StringValue(auth_value));
}
ScreenlockBridge::LockHandler::AuthType UserManagerScreenHandler::GetAuthType(
const std::string& user_email) const {
proximity_auth::ScreenlockBridge::LockHandler::AuthType
UserManagerScreenHandler::GetAuthType(const std::string& user_email) const {
UserAuthTypeMap::const_iterator it = user_auth_type_map_.find(user_email);
if (it == user_auth_type_map_.end())
return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
return proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
return it->second;
}
ScreenlockBridge::LockHandler::ScreenType
proximity_auth::ScreenlockBridge::LockHandler::ScreenType
UserManagerScreenHandler::GetScreenType() const {
return ScreenlockBridge::LockHandler::LOCK_SCREEN;
return proximity_auth::ScreenlockBridge::LockHandler::LOCK_SCREEN;
}
void UserManagerScreenHandler::Unlock(const std::string& user_email) {
......@@ -388,7 +390,7 @@ void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) {
desktop_type_ = chrome::GetHostDesktopTypeForNativeView(
web_ui()->GetWebContents()->GetNativeView());
ScreenlockBridge::Get()->SetLockHandler(this);
GetScreenlockBridgeInstance()->SetLockHandler(this);
}
void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) {
......@@ -546,9 +548,10 @@ void UserManagerScreenHandler::HandleHardlockUserPod(
const base::ListValue* args) {
std::string email;
CHECK(args->GetString(0, &email));
SetAuthType(email,
ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
base::string16());
SetAuthType(
email,
proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
base::string16());
HideUserPodCustomIcon(email);
}
......
......@@ -14,8 +14,8 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/host_desktop.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_ui_message_handler.h"
......@@ -29,10 +29,11 @@ class FilePath;
class ListValue;
}
class UserManagerScreenHandler : public content::WebUIMessageHandler,
public ScreenlockBridge::LockHandler,
public GaiaAuthConsumer,
public content::NotificationObserver {
class UserManagerScreenHandler
: public content::WebUIMessageHandler,
public proximity_auth::ScreenlockBridge::LockHandler,
public GaiaAuthConsumer,
public content::NotificationObserver {
public:
UserManagerScreenHandler();
~UserManagerScreenHandler() override;
......@@ -47,16 +48,18 @@ class UserManagerScreenHandler : public content::WebUIMessageHandler,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ScreenlockBridge::LockHandler implementation.
// proximity_auth::ScreenlockBridge::LockHandler implementation.
void ShowBannerMessage(const base::string16& message) override;
void ShowUserPodCustomIcon(
const std::string& user_email,
const ScreenlockBridge::UserPodCustomIconOptions& icon_options) override;
const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions&
icon_options) override;
void HideUserPodCustomIcon(const std::string& user_email) override;
void EnableInput() override;
void SetAuthType(const std::string& user_email,
ScreenlockBridge::LockHandler::AuthType auth_type,
const base::string16& auth_value) override;
void SetAuthType(
const std::string& user_email,
proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type,
const base::string16& auth_value) override;
AuthType GetAuthType(const std::string& user_email) const override;
ScreenType GetScreenType() const override;
void Unlock(const std::string& user_email) override;
......@@ -115,7 +118,8 @@ class UserManagerScreenHandler : public content::WebUIMessageHandler,
// URL hash, used to key post-profile actions if present.
std::string url_hash_;
typedef std::map<std::string, ScreenlockBridge::LockHandler::AuthType>
typedef std::map<std::string,
proximity_auth::ScreenlockBridge::LockHandler::AuthType>
UserAuthTypeMap;
UserAuthTypeMap user_auth_type_map_;
......
......@@ -1422,6 +1422,8 @@
'browser/signin/easy_unlock_service_regular.h',
'browser/signin/easy_unlock_service_signin_chromeos.cc',
'browser/signin/easy_unlock_service_signin_chromeos.h',
'browser/signin/proximity_auth_facade.cc',
'browser/signin/proximity_auth_facade.h',
'browser/speech/extension_api/tts_engine_extension_api.cc',
'browser/speech/extension_api/tts_engine_extension_api.h',
'browser/speech/extension_api/tts_engine_extension_observer.cc',
......@@ -2596,8 +2598,6 @@
'browser/signin/profile_identity_provider.h',
'browser/signin/profile_oauth2_token_service_factory.cc',
'browser/signin/profile_oauth2_token_service_factory.h',
'browser/signin/screenlock_bridge.cc',
'browser/signin/screenlock_bridge.h',
'browser/signin/signin_cookie_changed_subscription.cc',
'browser/signin/signin_cookie_changed_subscription.h',
'browser/signin/signin_error_controller_factory.cc',
......
......@@ -37,11 +37,14 @@
"proximity_auth/connection.h",
"proximity_auth/connection_finder.h",
"proximity_auth/connection_observer.h",
"proximity_auth/proximity_auth_client.h",
"proximity_auth/proximity_auth_system.cc",
"proximity_auth/proximity_auth_system.h",
"proximity_auth/remote_device.h",
"proximity_auth/remote_status_update.cc",
"proximity_auth/remote_status_update.h",
"proximity_auth/screenlock_bridge.cc",
"proximity_auth/screenlock_bridge.h",
"proximity_auth/secure_context.h",
"proximity_auth/switches.cc",
"proximity_auth/switches.h",
......
......@@ -23,11 +23,14 @@ source_set("proximity_auth") {
"connection.h",
"connection_finder.h",
"connection_observer.h",
"proximity_auth_client.h",
"proximity_auth_system.cc",
"proximity_auth_system.h",
"remote_device.h",
"remote_status_update.cc",
"remote_status_update.h",
"screenlock_bridge.cc",
"screenlock_bridge.h",
"secure_context.h",
"switches.cc",
"switches.h",
......
......@@ -2,3 +2,9 @@ include_rules = [
"+device/bluetooth",
"+net",
]
specific_include_rules = {
"screenlock_bridge\.*": [
"+chromeos",
],
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PROXIMITY_AUTH_CLIENT_H_
#define COMPONENTS_PROXIMITY_AUTH_CLIENT_H_
#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.
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);
};
} // namespace proximity_auth
#endif // COMPONENTS_PROXIMITY_AUTH_CLIENT_H_
......@@ -2,24 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/signin/screenlock_bridge.h"
#include "components/proximity_auth/screenlock_bridge.h"
#include "base/logging.h"
#include "base/strings/string16.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/proximity_auth/proximity_auth_client.h"
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#endif
namespace proximity_auth {
namespace {
base::LazyInstance<ScreenlockBridge> g_screenlock_bridge_bridge_instance =
LAZY_INSTANCE_INITIALIZER;
// Ids for the icons that are supported by lock screen and signin screen
// account picker as user pod custom icons.
// The id's should be kept in sync with values used by user_pod_row.js.
......@@ -53,9 +49,12 @@ std::string GetIdForIcon(ScreenlockBridge::UserPodCustomIcon icon) {
} // namespace
// static
ScreenlockBridge* ScreenlockBridge::Get() {
return g_screenlock_bridge_bridge_instance.Pointer();
ScreenlockBridge::ScreenlockBridge(ProximityAuthClient* client)
: client_(client), lock_handler_(nullptr) {
DCHECK(client_);
}
ScreenlockBridge::~ScreenlockBridge() {
}
ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions()
......@@ -64,7 +63,8 @@ ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions()
is_trial_run_(false) {
}
ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {}
ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {
}
scoped_ptr<base::DictionaryValue>
ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const {
......@@ -116,24 +116,8 @@ void ScreenlockBridge::UserPodCustomIconOptions::SetTrialRun() {
is_trial_run_ = true;
}
// static
std::string ScreenlockBridge::GetAuthenticatedUserEmail(
const Profile* profile) {
// |profile| has to be a signed-in profile with SigninManager already
// created. Otherwise, just crash to collect stack.
const SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfileIfExists(profile);
return signin_manager->GetAuthenticatedUsername();
}
ScreenlockBridge::ScreenlockBridge() : lock_handler_(NULL) {
}
ScreenlockBridge::~ScreenlockBridge() {
}
void ScreenlockBridge::SetLockHandler(LockHandler* lock_handler) {
DCHECK(lock_handler_ == NULL || lock_handler == NULL);
DCHECK(lock_handler_ == nullptr || lock_handler == nullptr);
// Don't notify observers if there is no change -- i.e. if the screen was
// already unlocked, and is remaining unlocked.
......@@ -163,22 +147,22 @@ void ScreenlockBridge::SetFocusedUser(const std::string& user_id) {
}
bool ScreenlockBridge::IsLocked() const {
return lock_handler_ != NULL;
return lock_handler_ != nullptr;
}
void ScreenlockBridge::Lock(Profile* profile) {
void ScreenlockBridge::Lock(content::BrowserContext* browser_context) {
#if defined(OS_CHROMEOS)
chromeos::SessionManagerClient* session_manager =
chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
session_manager->RequestLockScreen();
#else
profiles::LockProfile(profile);
client_->Lock(browser_context);
#endif
}
void ScreenlockBridge::Unlock(Profile* profile) {
void ScreenlockBridge::Unlock(content::BrowserContext* browser_context) {
if (lock_handler_)
lock_handler_->Unlock(GetAuthenticatedUserEmail(profile));
lock_handler_->Unlock(client_->GetAuthenticatedUsername(browser_context));
}
void ScreenlockBridge::AddObserver(Observer* observer) {
......@@ -188,3 +172,5 @@ void ScreenlockBridge::AddObserver(Observer* observer) {
void ScreenlockBridge::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
} // namespace proximity_auth
......@@ -2,21 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
#define CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
#ifndef COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_
#define COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_
#include <string>
#include "base/basictypes.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "base/values.h"
namespace content {
class BrowserContext;
} // namespace content
class Profile;
namespace proximity_auth {
class ProximityAuthClient;
// ScreenlockBridge brings together the screenLockPrivate API and underlying
// support. On ChromeOS, it delegates calls to the ScreenLocker. On other
......@@ -25,6 +29,10 @@ class Profile;
// used solely for the lock screen anymore.
class ScreenlockBridge {
public:
// |client| is not owned and must outlive this object.
explicit ScreenlockBridge(ProximityAuthClient* client);
~ScreenlockBridge();
// User pod icons supported by lock screen / signin screen UI.
enum UserPodCustomIcon {
USER_POD_CUSTOM_ICON_NONE,
......@@ -99,11 +107,7 @@ class ScreenlockBridge {
FORCE_OFFLINE_PASSWORD = 5
};
enum ScreenType {
SIGNIN_SCREEN = 0,
LOCK_SCREEN = 1,
OTHER_SCREEN = 2
};
enum ScreenType { SIGNIN_SCREEN = 0, LOCK_SCREEN = 1, OTHER_SCREEN = 2 };
// Displays |message| in a banner on the lock screen.
virtual void ShowBannerMessage(const base::string16& message) = 0;
......@@ -130,7 +134,7 @@ class ScreenlockBridge {
// Returns the type of the screen -- a signin or a lock screen.
virtual ScreenType GetScreenType() const = 0;
// Unlock from easy unlock app for a user.
// Unlocks from easy unlock app for a user.
virtual void Unlock(const std::string& user_email) = 0;
// Attempts to login the user using an easy unlock key.
......@@ -157,15 +161,12 @@ class ScreenlockBridge {
virtual ~Observer() {}
};
static ScreenlockBridge* Get();
static std::string GetAuthenticatedUserEmail(const Profile* profile);
void SetLockHandler(LockHandler* lock_handler);
void SetFocusedUser(const std::string& user_id);
bool IsLocked() const;
void Lock(Profile* profile);
void Unlock(Profile* profile);
void Lock(content::BrowserContext* browser_context);
void Unlock(content::BrowserContext* browser_context);
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
......@@ -175,13 +176,8 @@ class ScreenlockBridge {
std::string focused_user_id() const { return focused_user_id_; }
private:
friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>;
friend struct base::DefaultDeleter<ScreenlockBridge>;
ScreenlockBridge();
~ScreenlockBridge();
LockHandler* lock_handler_; // Not owned
ProximityAuthClient* client_; // Not owned. Must outlive this object.
LockHandler* lock_handler_; // Not owned
// The last focused user's id.
std::string focused_user_id_;
ObserverList<Observer, true> observers_;
......@@ -189,4 +185,6 @@ class ScreenlockBridge {
DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
};
#endif // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
} // namespace proximity_auth
#endif // COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment