Commit 0151fd7c authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

Smart Lock: Remove Unused EasyUnlockAppManager.

The remaining call sites just (re)loaded/disabled the app but did not
use any of the app for functionality.

R=hansberry@chromium.org

Bug: 899324
Test: none
Change-Id: Idf93dea3d8dd6fbff5e842c283055ab67bc2b779
Reviewed-on: https://chromium-review.googlesource.com/c/1312301
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604717}
parent 87bded8e
......@@ -1003,8 +1003,6 @@ source_set("chromeos") {
"login/demo_mode/demo_setup_controller.h",
"login/easy_unlock/chrome_proximity_auth_client.cc",
"login/easy_unlock/chrome_proximity_auth_client.h",
"login/easy_unlock/easy_unlock_app_manager.cc",
"login/easy_unlock/easy_unlock_app_manager.h",
"login/easy_unlock/easy_unlock_auth_attempt.cc",
"login/easy_unlock/easy_unlock_auth_attempt.h",
"login/easy_unlock/easy_unlock_challenge_wrapper.cc",
......
// 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/chromeos/login/easy_unlock/easy_unlock_app_manager.h"
#include <utility>
#include "base/command_line.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/sys_info.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/apps/platform_apps/api/easy_unlock_private.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/switches.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/one_shot_event.h"
namespace chromeos {
namespace {
class EasyUnlockAppManagerImpl : public EasyUnlockAppManager {
public:
EasyUnlockAppManagerImpl(extensions::ExtensionSystem* extension_system,
int manifest_id,
const base::FilePath& app_path);
~EasyUnlockAppManagerImpl() override;
// EasyUnlockAppManager overrides.
void EnsureReady(const base::Closure& ready_callback) override;
void LoadApp() override;
void DisableAppIfLoaded() override;
private:
extensions::ExtensionSystem* extension_system_;
// The Easy Unlock app id.
std::string app_id_;
int manifest_id_;
// The path from which Easy Unlock app should be loaded.
base::FilePath app_path_;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockAppManagerImpl);
};
EasyUnlockAppManagerImpl::EasyUnlockAppManagerImpl(
extensions::ExtensionSystem* extension_system,
int manifest_id,
const base::FilePath& app_path)
: extension_system_(extension_system),
app_id_(extension_misc::kEasyUnlockAppId),
manifest_id_(manifest_id),
app_path_(app_path) {}
EasyUnlockAppManagerImpl::~EasyUnlockAppManagerImpl() {}
void EasyUnlockAppManagerImpl::EnsureReady(
const base::Closure& ready_callback) {
extension_system_->ready().Post(FROM_HERE, ready_callback);
}
void EasyUnlockAppManagerImpl::LoadApp() {
extensions::ExtensionService* extension_service =
extension_system_->extension_service();
if (!extension_service)
return;
// TODO(xiyuan): Remove this when the app is bundled with chrome.
if (!base::SysInfo::IsRunningOnChromeOS() &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
proximity_auth::switches::kForceLoadEasyUnlockAppInTests)) {
return;
}
if (app_path_.empty())
return;
extensions::ComponentLoader* loader = extension_service->component_loader();
if (!loader->Exists(app_id_))
app_id_ = loader->Add(manifest_id_, app_path_);
extension_service->EnableExtension(app_id_);
}
void EasyUnlockAppManagerImpl::DisableAppIfLoaded() {
extensions::ExtensionService* extension_service =
extension_system_->extension_service();
if (!extension_service)
return;
if (!extension_service->component_loader()->Exists(app_id_))
return;
extension_service->DisableExtension(
app_id_, extensions::disable_reason::DISABLE_RELOAD);
}
} // namespace
EasyUnlockAppManager::~EasyUnlockAppManager() {}
// static
std::unique_ptr<EasyUnlockAppManager> EasyUnlockAppManager::Create(
extensions::ExtensionSystem* extension_system,
int manifest_id,
const base::FilePath& app_path) {
return std::unique_ptr<EasyUnlockAppManager>(
new EasyUnlockAppManagerImpl(extension_system, manifest_id, app_path));
}
} // namespace 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 CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_APP_MANAGER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_APP_MANAGER_H_
#include <memory>
#include <string>
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h"
namespace extensions {
class ExtensionSystem;
}
namespace chromeos {
// Used to manage Easy Unlock app's lifetime and to dispatch events to the app.
// It's main purpose is to abstract extension system from the rest of easy
// unlock code.
class EasyUnlockAppManager {
public:
virtual ~EasyUnlockAppManager();
// Creates EasyUnlockAppManager object that should be used in production.
static std::unique_ptr<EasyUnlockAppManager> Create(
extensions::ExtensionSystem* extension_system,
int manifest_id,
const base::FilePath& app_path);
// Wait for the extension system to get ready and invokes |ready_callback|
// when that happens.
// Note that the callback may be triggered after |this| is deleted.
virtual void EnsureReady(const base::Closure& ready_callback) = 0;
// Loads Easy Unlock app.
virtual void LoadApp() = 0;
// Disables Easy Unlock app.
virtual void DisableAppIfLoaded() = 0;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_EASY_UNLOCK_EASY_UNLOCK_APP_MANAGER_H_
// 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/chromeos/login/easy_unlock/easy_unlock_app_manager.h"
#include <stddef.h>
#include <memory>
#include <string>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "build/build_config.h"
#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/common/apps/platform_apps/api/easy_unlock_private.h"
#include "chrome/common/extensions/api/screenlock_private.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/components/proximity_auth/switches.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/process_manager_factory.h"
#include "extensions/common/api/app_runtime.h"
#include "extensions/common/extension.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace {
// Sets |*value| to true, also verifying that the value was not previously set.
// Used in tests for verifying that a callback was called.
void VerifyFalseAndSetToTrue(bool* value) {
EXPECT_FALSE(*value);
*value = true;
}
// A ProcessManager that doesn't create background host pages.
class TestProcessManager : public extensions::ProcessManager {
public:
explicit TestProcessManager(content::BrowserContext* context)
: extensions::ProcessManager(
context,
context,
extensions::ExtensionRegistry::Get(context)) {}
~TestProcessManager() override {}
// ProcessManager overrides:
bool CreateBackgroundHost(const extensions::Extension* extension,
const GURL& url) override {
return false;
}
private:
DISALLOW_COPY_AND_ASSIGN(TestProcessManager);
};
std::unique_ptr<KeyedService> CreateTestProcessManager(
content::BrowserContext* context) {
return std::make_unique<TestProcessManager>(context);
}
// Observes extension registry for unload and load events (in that order) of an
// extension with the provided extension id.
// Used to determine if an extension was reloaded.
class ExtensionReloadTracker : public extensions::ExtensionRegistryObserver {
public:
ExtensionReloadTracker(Profile* profile, const std::string& extension_id)
: profile_(profile),
extension_id_(extension_id),
unloaded_(false),
loaded_(false) {
extensions::ExtensionRegistry::Get(profile)->AddObserver(this);
}
~ExtensionReloadTracker() override {
extensions::ExtensionRegistry::Get(profile_)->RemoveObserver(this);
}
// extension::ExtensionRegistryObserver implementation:
void OnExtensionLoaded(content::BrowserContext* browser_context,
const extensions::Extension* extension) override {
ASSERT_FALSE(loaded_);
ASSERT_EQ(extension_id_, extension->id());
loaded_ = true;
}
void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) override {
ASSERT_FALSE(unloaded_);
ASSERT_EQ(extension_id_, extension->id());
unloaded_ = true;
}
// Whether the extensino was unloaded and loaded during |this| lifetime.
bool HasReloaded() const { return loaded_ && unloaded_; }
private:
Profile* profile_;
std::string extension_id_;
bool unloaded_;
bool loaded_;
DISALLOW_COPY_AND_ASSIGN(ExtensionReloadTracker);
};
class EasyUnlockAppManagerTest : public testing::Test {
public:
EasyUnlockAppManagerTest() : command_line_(base::CommandLine::NO_PROGRAM) {}
~EasyUnlockAppManagerTest() override {}
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
proximity_auth::switches::kForceLoadEasyUnlockAppInTests);
extensions::ExtensionSystem* extension_system = SetUpExtensionSystem();
app_manager_ = EasyUnlockAppManager::Create(
extension_system, IDR_EASY_UNLOCK_MANIFEST, GetAppPath());
}
protected:
void SetExtensionSystemReady() {
extensions::TestExtensionSystem* test_extension_system =
static_cast<extensions::TestExtensionSystem*>(
extensions::ExtensionSystem::Get(&profile_));
test_extension_system->SetReady();
base::RunLoop().RunUntilIdle();
}
base::FilePath GetAppPath() {
return extensions::ExtensionPrefs::Get(&profile_)
->install_directory()
.AppendASCII("easy_unlock");
}
private:
// Initializes test extension system.
extensions::ExtensionSystem* SetUpExtensionSystem() {
extensions::TestExtensionSystem* test_extension_system =
static_cast<extensions::TestExtensionSystem*>(
extensions::ExtensionSystem::Get(&profile_));
extension_service_ = test_extension_system->CreateExtensionService(
&command_line_, base::FilePath() /* install_directory */,
false /* autoupdate_enabled */);
extensions::ProcessManagerFactory::GetInstance()->SetTestingFactory(
&profile_, base::BindRepeating(&CreateTestProcessManager));
extension_service_->component_loader()->set_ignore_whitelist_for_testing(
true);
return test_extension_system;
}
protected:
std::unique_ptr<EasyUnlockAppManager> app_manager_;
// Needed by extension system.
content::TestBrowserThreadBundle thread_bundle_;
// Cros settings are needed when creating user manager.
ScopedCrosSettingsTestHelper cros_settings_test_helper_;
// Needed for creating ExtensionService.
ScopedTestUserManager test_user_manager_;
TestingProfile profile_;
extensions::ExtensionService* extension_service_;
base::CommandLine command_line_;
private:
DISALLOW_COPY_AND_ASSIGN(EasyUnlockAppManagerTest);
};
TEST_F(EasyUnlockAppManagerTest, LoadAppWhenNotLoaded) {
SetExtensionSystemReady();
// Sanity check for the test: the easy unlock app should not be loaded at
// this point.
ASSERT_FALSE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, true));
app_manager_->LoadApp();
ASSERT_TRUE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, false));
EXPECT_TRUE(
extension_service_->IsExtensionEnabled(extension_misc::kEasyUnlockAppId));
}
TEST_F(EasyUnlockAppManagerTest, LoadAppWhenAlreadyLoaded) {
SetExtensionSystemReady();
extension_service_->component_loader()->Add(IDR_EASY_UNLOCK_MANIFEST,
GetAppPath());
app_manager_->LoadApp();
ASSERT_TRUE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, false));
}
TEST_F(EasyUnlockAppManagerTest, LoadAppPreviouslyDisabled) {
SetExtensionSystemReady();
extension_service_->component_loader()->Add(IDR_EASY_UNLOCK_MANIFEST,
GetAppPath());
extension_service_->DisableExtension(
extension_misc::kEasyUnlockAppId,
extensions::disable_reason::DISABLE_RELOAD);
ASSERT_TRUE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, true));
ASSERT_FALSE(
extension_service_->IsExtensionEnabled(extension_misc::kEasyUnlockAppId));
app_manager_->LoadApp();
ASSERT_TRUE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, false));
}
TEST_F(EasyUnlockAppManagerTest, DisableApp) {
SetExtensionSystemReady();
extension_service_->component_loader()->Add(IDR_EASY_UNLOCK_MANIFEST,
GetAppPath());
EXPECT_TRUE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, false));
app_manager_->DisableAppIfLoaded();
EXPECT_TRUE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, true));
EXPECT_FALSE(
extension_service_->IsExtensionEnabled(extension_misc::kEasyUnlockAppId));
}
TEST_F(EasyUnlockAppManagerTest, DisableAppWhenNotLoaded) {
SetExtensionSystemReady();
EXPECT_FALSE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, true));
app_manager_->DisableAppIfLoaded();
EXPECT_FALSE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, true));
extension_service_->component_loader()->Add(IDR_EASY_UNLOCK_MANIFEST,
GetAppPath());
EXPECT_TRUE(extension_service_->GetExtensionById(
extension_misc::kEasyUnlockAppId, false));
}
TEST_F(EasyUnlockAppManagerTest, EnsureReady) {
bool ready = false;
app_manager_->EnsureReady(base::Bind(&VerifyFalseAndSetToTrue, &ready));
base::RunLoop().RunUntilIdle();
ASSERT_FALSE(ready);
SetExtensionSystemReady();
ASSERT_TRUE(ready);
}
TEST_F(EasyUnlockAppManagerTest, EnsureReadyAfterExtesionSystemReady) {
SetExtensionSystemReady();
bool ready = false;
app_manager_->EnsureReady(base::Bind(&VerifyFalseAndSetToTrue, &ready));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(ready);
}
} // namespace
} // namespace chromeos
......@@ -22,7 +22,6 @@
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/easy_unlock/chrome_proximity_auth_client.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_app_manager.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_factory.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.h"
......@@ -257,12 +256,10 @@ void EasyUnlockService::ResetLocalStateForUser(const AccountId& account_id) {
EasyUnlockTpmKeyManager::ResetLocalStateForUser(account_id);
}
void EasyUnlockService::Initialize(
std::unique_ptr<EasyUnlockAppManager> app_manager) {
app_manager_ = std::move(app_manager);
app_manager_->EnsureReady(
base::Bind(&EasyUnlockService::InitializeOnAppManagerReady,
weak_ptr_factory_.GetWeakPtr()));
void EasyUnlockService::Initialize() {
InitializeInternal();
bluetooth_detector_->Initialize();
}
proximity_auth::ProximityAuthPrefManager*
......@@ -512,7 +509,6 @@ void EasyUnlockService::Shutdown() {
void EasyUnlockService::UpdateAppState() {
if (IsAllowed()) {
EnsureTpmKeyPresentIfNeeded();
app_manager_->LoadApp();
if (proximity_auth_system_)
proximity_auth_system_->Start();
......@@ -524,13 +520,11 @@ void EasyUnlockService::UpdateAppState() {
// If the service is not allowed due to bluetooth not being detected just
// after system suspend is done, give bluetooth more time to be detected
// before disabling the app (and resetting screenlock state).
// before resetting screenlock state.
bluetooth_waking_up = power_monitor_.get() && power_monitor_->waking_up() &&
!bluetooth_detector_->IsPresent();
if (!bluetooth_waking_up) {
app_manager_->DisableAppIfLoaded();
if (proximity_auth_system_)
proximity_auth_system_->Stop();
......@@ -539,10 +533,6 @@ void EasyUnlockService::UpdateAppState() {
}
}
void EasyUnlockService::DisableAppWithoutResettingScreenlockState() {
app_manager_->DisableAppIfLoaded();
}
void EasyUnlockService::ResetScreenlockState() {
screenlock_state_handler_.reset();
auth_attempt_.reset();
......@@ -558,14 +548,6 @@ void EasyUnlockService::SetScreenlockHardlockedState(
auth_attempt_.reset();
}
void EasyUnlockService::InitializeOnAppManagerReady() {
CHECK(app_manager_.get());
InitializeInternal();
bluetooth_detector_->Initialize();
}
void EasyUnlockService::OnBluetoothAdapterPresentChanged() {
UpdateAppState();
}
......@@ -704,7 +686,6 @@ void EasyUnlockService::OnCryptohomeKeysFetchedForChecking(
}
void EasyUnlockService::PrepareForSuspend() {
app_manager_->DisableAppIfLoaded();
if (screenlock_state_handler_ && screenlock_state_handler_->IsActive())
UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING);
if (proximity_auth_system_)
......
......@@ -51,7 +51,6 @@ namespace secure_channel {
class SecureChannelClient;
} // namespace secure_channel
class EasyUnlockAppManager;
class EasyUnlockServiceObserver;
class EasyUnlockService : public KeyedService {
......@@ -110,7 +109,7 @@ class EasyUnlockService : public KeyedService {
virtual void RecordPasswordLoginEvent(const AccountId& account_id) const = 0;
// Sets the service up and schedules service initialization.
void Initialize(std::unique_ptr<EasyUnlockAppManager> app_manager);
void Initialize();
// Whether easy unlock is allowed to be used. If the controlling preference
// is set (from policy), this returns the preference value. Otherwise, it is
......@@ -206,13 +205,6 @@ class EasyUnlockService : public KeyedService {
// Checks whether Easy unlock should be running and updates app state.
void UpdateAppState();
// Disables easy unlock app without affecting lock screen state.
// Used primarily by signin service when user logged in state changes to
// logged in but before screen gets unlocked. At this point service shutdown
// is imminent and the app can be safely unloaded, but, for esthetic reasons,
// the lock screen UI should remain unchanged until the screen unlocks.
void DisableAppWithoutResettingScreenlockState();
// Resets the screenlock state set by this service.
void ResetScreenlockState();
......@@ -245,9 +237,6 @@ class EasyUnlockService : public KeyedService {
// A class to detect whether a bluetooth adapter is present.
class BluetoothDetector;
// Initializes the service after EasyUnlockAppManager is ready.
void InitializeOnAppManagerReady();
// Gets |screenlock_state_handler_|. Returns NULL if Easy Unlock is not
// allowed. Otherwise, if |screenlock_state_handler_| is not set, an instance
// is created. Do not cache the returned value, as it may go away if Easy
......@@ -274,8 +263,6 @@ class EasyUnlockService : public KeyedService {
ChromeProximityAuthClient proximity_auth_client_;
std::unique_ptr<EasyUnlockAppManager> app_manager_;
// Created lazily in |GetScreenlockStateHandler|.
std::unique_ptr<EasyUnlockScreenlockStateHandler> screenlock_state_handler_;
......@@ -289,9 +276,6 @@ class EasyUnlockService : public KeyedService {
// Handles connecting, authenticating, and updating the UI on the lock/sign-in
// screen. After a |RemoteDeviceRef| instance is provided, this object will
// handle the rest.
// TODO(tengs): This object is intended as a replacement of the background
// page of the easy_unlock Chrome app. We are in the process of removing the
// app in favor of |proximity_auth_system_|.
std::unique_ptr<proximity_auth::ProximityAuthSystem> proximity_auth_system_;
// Monitors suspend and wake state of ChromeOS.
......
......@@ -9,7 +9,6 @@
#include "build/build_config.h"
#include "chrome/browser/chromeos/cryptauth/chrome_cryptauth_service_factory.h"
#include "chrome/browser/chromeos/device_sync/device_sync_client_factory.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_app_manager.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_signin_chromeos.h"
......@@ -124,9 +123,7 @@ KeyedService* EasyUnlockServiceFactory::BuildServiceInstanceFor(
? GetEasyUnlockAppPath()
: app_path_for_testing_;
service->Initialize(EasyUnlockAppManager::Create(
extensions::ExtensionSystem::Get(context), manifest_id, app_path));
service->Initialize();
return service;
}
......
......@@ -16,7 +16,6 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_app_manager.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_challenge_wrapper.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_metrics.h"
......@@ -29,6 +28,7 @@
#include "chromeos/components/proximity_auth/proximity_auth_local_state_pref_manager.h"
#include "chromeos/components/proximity_auth/switches.h"
#include "chromeos/login/auth/user_context.h"
#include "chromeos/login/login_state.h"
#include "chromeos/tpm/tpm_token_loader.h"
#include "components/cryptauth/remote_device.h"
#include "components/cryptauth/remote_device_cache.h"
......@@ -307,7 +307,6 @@ void EasyUnlockServiceSignin::InitializeInternal() {
pref_manager_.reset(new proximity_auth::ProximityAuthLocalStatePrefManager(
g_browser_process->local_state()));
LoginState::Get()->AddObserver(this);
proximity_auth::ScreenlockBridge* screenlock_bridge =
proximity_auth::ScreenlockBridge::Get();
screenlock_bridge->AddObserver(this);
......@@ -322,7 +321,6 @@ void EasyUnlockServiceSignin::ShutdownInternal() {
weak_ptr_factory_.InvalidateWeakPtrs();
proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this);
LoginState::Get()->RemoveObserver(this);
user_data_.clear();
}
......@@ -382,8 +380,6 @@ void EasyUnlockServiceSignin::OnScreenDidUnlock(
proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN)
return;
DisableAppWithoutResettingScreenlockState();
Shutdown();
}
......@@ -429,12 +425,6 @@ void EasyUnlockServiceSignin::OnFocusedUserChanged(
TPMTokenLoader::Get()->EnsureStarted();
}
void EasyUnlockServiceSignin::LoggedInStateChanged() {
if (!LoginState::Get()->IsUserLoggedIn())
return;
DisableAppWithoutResettingScreenlockState();
}
void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() {
// TODO(xiyuan): Revisit this when adding tests.
if (!base::SysInfo::IsRunningOnChromeOS())
......
......@@ -16,7 +16,6 @@
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_types.h"
#include "chromeos/components/proximity_auth/screenlock_bridge.h"
#include "chromeos/login/login_state.h"
namespace cryptauth {
class RemoteDeviceCache;
......@@ -37,8 +36,7 @@ class EasyUnlockChallengeWrapper;
// EasyUnlockService instance that should be used for signin profile.
class EasyUnlockServiceSignin
: public EasyUnlockService,
public proximity_auth::ScreenlockBridge::Observer,
public LoginState::Observer {
public proximity_auth::ScreenlockBridge::Observer {
public:
EasyUnlockServiceSignin(
Profile* profile,
......@@ -117,9 +115,6 @@ class EasyUnlockServiceSignin
override;
void OnFocusedUserChanged(const AccountId& account_id) override;
// LoginState::Observer implementation:
void LoggedInStateChanged() override;
// Loads the device data associated with the user's Easy unlock keys from
// crypthome.
void LoadCurrentUserDataIfNeeded();
......
......@@ -17,7 +17,6 @@
#include "base/no_destructor.h"
#include "base/run_loop.h"
#include "base/values.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_app_manager.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_notification_controller.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_factory.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h"
......@@ -71,99 +70,6 @@ class MockEasyUnlockNotificationController
DISALLOW_COPY_AND_ASSIGN(MockEasyUnlockNotificationController);
};
// App manager to be used in EasyUnlockService tests.
// This effectivelly abstracts the extension system from the tests.
class TestAppManager : public EasyUnlockAppManager {
public:
TestAppManager()
: state_(STATE_NOT_LOADED),
ready_(false) {}
~TestAppManager() override {}
// The easy unlock app state.
enum State { STATE_NOT_LOADED, STATE_LOADED, STATE_DISABLED };
State state() const { return state_; }
// Marks the manager as ready and runs |ready_callback_| if there is one set.
void SetReady() {
ready_ = true;
if (!ready_callback_.is_null()) {
ready_callback_.Run();
ready_callback_ = base::Closure();
}
}
void EnsureReady(const base::Closure& ready_callback) override {
ASSERT_TRUE(ready_callback_.is_null());
if (ready_) {
ready_callback.Run();
return;
}
ready_callback_ = ready_callback;
}
void LoadApp() override { state_ = STATE_LOADED; }
void DisableAppIfLoaded() override {
if (state_ == STATE_LOADED)
state_ = STATE_DISABLED;
}
private:
// The current app state.
State state_;
// Whether the manager is ready. Set using |SetReady|.
bool ready_;
// If |EnsureReady| was called before |SetReady|, cached callback that will be
// called when manager becomes ready.
base::Closure ready_callback_;
DISALLOW_COPY_AND_ASSIGN(TestAppManager);
};
// Helper factory that tracks AppManagers passed to EasyUnlockServices per
// browser context owning a EasyUnlockService. Used to allow tests access to the
// TestAppManagers passed to the created services.
class TestAppManagerFactory {
public:
TestAppManagerFactory() {}
~TestAppManagerFactory() {}
// Creates a TestAppManager for the provided browser context. If a
// TestAppManager was already created for the context, returns NULL.
std::unique_ptr<TestAppManager> Create(content::BrowserContext* context) {
if (Find(context))
return std::unique_ptr<TestAppManager>();
std::unique_ptr<TestAppManager> app_manager(new TestAppManager());
mapping_[context] = app_manager.get();
return app_manager;
}
// Finds a TestAppManager created for |context|. Returns NULL if no
// TestAppManagers have been created for the context.
TestAppManager* Find(content::BrowserContext* context) {
std::map<content::BrowserContext*, TestAppManager*>::iterator it =
mapping_.find(context);
if (it == mapping_.end())
return NULL;
return it->second;
}
private:
// Mapping from browser contexts to test AppManagers. The AppManagers are not
// owned by this.
std::map<content::BrowserContext*, TestAppManager*> mapping_;
DISALLOW_COPY_AND_ASSIGN(TestAppManagerFactory);
};
// Global TestAppManager factory. It should be created and destroyed in
// EasyUnlockServiceTest::SetUp and EasyUnlockServiceTest::TearDown,
// respectively.
TestAppManagerFactory* app_manager_factory = nullptr;
device_sync::FakeDeviceSyncClient* GetDefaultDeviceSyncClient() {
static base::NoDestructor<device_sync::FakeDeviceSyncClient> fake_client;
return fake_client.get();
......@@ -177,26 +83,15 @@ GetDefaultMultiDeviceSetupClient() {
}
// EasyUnlockService factory function injected into testing profiles.
// It creates an EasyUnlockService with test AppManager.
std::unique_ptr<KeyedService> CreateEasyUnlockServiceForTest(
content::BrowserContext* context) {
EXPECT_TRUE(app_manager_factory);
if (!app_manager_factory)
return nullptr;
std::unique_ptr<EasyUnlockAppManager> app_manager =
app_manager_factory->Create(context);
EXPECT_TRUE(app_manager.get());
if (!app_manager.get())
return nullptr;
std::unique_ptr<EasyUnlockServiceRegular> service(
new EasyUnlockServiceRegular(
Profile::FromBrowserContext(context),
nullptr /* secure_channel_client */,
std::make_unique<MockEasyUnlockNotificationController>(),
GetDefaultDeviceSyncClient(), GetDefaultMultiDeviceSetupClient()));
service->Initialize(std::move(app_manager));
service->Initialize();
return std::move(service);
}
......@@ -212,8 +107,6 @@ class EasyUnlockServiceTest : public testing::Test {
~EasyUnlockServiceTest() override {}
void SetUp() override {
app_manager_factory = new TestAppManagerFactory();
mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>();
device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_);
EXPECT_CALL(*mock_adapter_, IsPresent())
......@@ -240,9 +133,6 @@ class EasyUnlockServiceTest : public testing::Test {
void TearDown() override {
TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
delete app_manager_factory;
app_manager_factory = nullptr;
}
void SetEasyUnlockAllowedPolicy(bool allowed) {
......@@ -262,24 +152,6 @@ class EasyUnlockServiceTest : public testing::Test {
return power_manager_client_;
}
// Checks whether AppManager passed to EasyUnlockservice for |profile| has
// Easy Unlock app loaded.
bool EasyUnlockAppInState(Profile* profile, TestAppManager::State state) {
EXPECT_TRUE(app_manager_factory);
if (!app_manager_factory)
return false;
TestAppManager* app_manager = app_manager_factory->Find(profile);
EXPECT_TRUE(app_manager);
return app_manager && app_manager->state() == state;
}
void SetAppManagerReady(content::BrowserContext* context) {
ASSERT_TRUE(app_manager_factory);
TestAppManager* app_manager = app_manager_factory->Find(context);
ASSERT_TRUE(app_manager);
app_manager->SetReady();
}
// Sets up a test profile using the provided |email|. Will generate a unique
// gaia id and output to |gaia_id|. Returns the created TestingProfile.
std::unique_ptr<TestingProfile> SetUpProfile(const std::string& email,
......@@ -339,70 +211,17 @@ class EasyUnlockServiceTest : public testing::Test {
TEST_F(EasyUnlockServiceTest, NoBluetoothNoService) {
set_is_bluetooth_adapter_present(false);
// This should start easy unlock service initialization.
SetAppManagerReady(profile_.get());
EasyUnlockService* service = EasyUnlockService::Get(profile_.get());
ASSERT_TRUE(service);
EXPECT_FALSE(service->IsAllowed());
EXPECT_TRUE(
EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_NOT_LOADED));
}
// TODO(https://crbug.com/893878): Fix disabled test.
TEST_F(EasyUnlockServiceTest, DISABLED_DisabledOnSuspend) {
// This should start easy unlock service initialization.
SetAppManagerReady(profile_.get());
EasyUnlockService* service = EasyUnlockService::Get(profile_.get());
ASSERT_TRUE(service);
EXPECT_TRUE(service->IsAllowed());
EXPECT_TRUE(
EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_LOADED));
power_manager_client()->SendSuspendImminent(
power_manager::SuspendImminent_Reason_OTHER);
EXPECT_TRUE(
EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_DISABLED));
power_manager_client()->SendSuspendDone();
EXPECT_TRUE(
EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_LOADED));
}
// TODO(https://crbug.com/893878): Fix disabled test.
TEST_F(EasyUnlockServiceTest, DISABLED_NotAllowedForSecondaryProfile) {
SetAppManagerReady(profile_.get());
EasyUnlockService* primary_service = EasyUnlockService::Get(profile_.get());
ASSERT_TRUE(primary_service);
// A sanity check for the test to confirm that the primary profile service
// is allowed under these conditions..
ASSERT_TRUE(primary_service->IsAllowed());
SetUpSecondaryProfile();
SetAppManagerReady(secondary_profile_.get());
EasyUnlockService* secondary_service =
EasyUnlockService::Get(secondary_profile_.get());
ASSERT_TRUE(secondary_service);
EXPECT_FALSE(secondary_service->IsAllowed());
EXPECT_TRUE(EasyUnlockAppInState(secondary_profile_.get(),
TestAppManager::STATE_NOT_LOADED));
}
TEST_F(EasyUnlockServiceTest, NotAllowedForEphemeralAccounts) {
ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral())
.WillByDefault(Return(true));
SetAppManagerReady(profile_.get());
EXPECT_FALSE(EasyUnlockService::Get(profile_.get())->IsAllowed());
EXPECT_TRUE(
EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_NOT_LOADED));
}
TEST_F(EasyUnlockServiceTest, GetAccountId) {
......
......@@ -3818,7 +3818,6 @@ test("unit_tests") {
if (is_chromeos) {
sources += [
"../browser/apps/platform_apps/api/easy_unlock_private/easy_unlock_private_api_chromeos_unittest.cc",
"../browser/chromeos/login/easy_unlock/easy_unlock_app_manager_unittest.cc",
"../browser/chromeos/login/easy_unlock/easy_unlock_auth_attempt_unittest.cc",
"../browser/chromeos/login/easy_unlock/easy_unlock_notification_controller_chromeos_unittest.cc",
"../browser/chromeos/login/easy_unlock/easy_unlock_screenlock_state_handler_unittest.cc",
......
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