Commit cfbaa984 authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

extensions/EasyUnlockPrivateApi: Remove so much dead code.

These methods are now unused after removing the Bluetooth Classic
implementation of EasyUnlock.

R=khorimoto@chromium.org

Bug: none
Test: none
Change-Id: I5a2a30c7dbd83bc51441f7525030ea94526df32b
Reviewed-on: https://chromium-review.googlesource.com/1000728Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549263}
parent 3e446577
......@@ -41,9 +41,6 @@ class EasyUnlockAppManagerImpl : public EasyUnlockAppManager {
void LoadApp() override;
void DisableAppIfLoaded() override;
void ReloadApp() override;
bool SendUserUpdatedEvent(const std::string& user_id,
bool is_logged_in,
bool data_ready) override;
bool SendAuthAttemptEvent() override;
private:
......@@ -138,41 +135,6 @@ void EasyUnlockAppManagerImpl::ReloadApp() {
extension_service->ReloadExtension(app_id_);
}
bool EasyUnlockAppManagerImpl::SendUserUpdatedEvent(const std::string& user_id,
bool is_logged_in,
bool data_ready) {
ExtensionService* extension_service = extension_system_->extension_service();
if (!extension_service)
return false;
extensions::EventRouter* event_router =
extensions::EventRouter::Get(extension_service->GetBrowserContext());
if (!event_router)
return false;
extensions::events::HistogramValue histogram_value =
extensions::events::EASY_UNLOCK_PRIVATE_ON_USER_INFO_UPDATED;
std::string event_name =
extensions::api::easy_unlock_private::OnUserInfoUpdated::kEventName;
if (!event_router->ExtensionHasEventListener(app_id_, event_name))
return false;
extensions::api::easy_unlock_private::UserInfo info;
info.user_id = user_id;
info.logged_in = is_logged_in;
info.data_ready = data_ready;
std::unique_ptr<base::ListValue> args(new base::ListValue());
args->Append(info.ToValue());
std::unique_ptr<extensions::Event> event(
new extensions::Event(histogram_value, event_name, std::move(args)));
event_router->DispatchEventToExtension(app_id_, std::move(event));
return true;
}
bool EasyUnlockAppManagerImpl::SendAuthAttemptEvent() {
ExtensionService* extension_service = extension_system_->extension_service();
if (!extension_service)
......
......@@ -48,11 +48,6 @@ class EasyUnlockAppManager {
// Reloads Easy Unlock app.
virtual void ReloadApp() = 0;
// Sends easyUnlockPrivate.onUserInfoUpdate event to Easy Unlock app.
virtual bool SendUserUpdatedEvent(const std::string& user_id,
bool is_logged_in,
bool data_ready) = 0;
// Sends screenlockPrivate.onAuthAttempted event to Easy Unlock app.
virtual bool SendAuthAttemptEvent() = 0;
};
......
......@@ -139,9 +139,6 @@ class EasyUnlockAppEventConsumer
void OnDispatchEventToExtension(const std::string& extension_id,
const extensions::Event& event) override {
if (event.event_name ==
easy_unlock_private_api::OnUserInfoUpdated::kEventName) {
ConsumeUserInfoUpdated(event.event_args.get());
} else if (event.event_name ==
screenlock_private_api::OnAuthAttempted::kEventName) {
ConsumeAuthAttempted(event.event_args.get());
} else {
......@@ -233,11 +230,6 @@ class EasyUnlockAppManagerTest : public testing::Test {
.AppendASCII("easy_unlock");
}
int UserUpdatedCount() const {
return event_router_->GetEventCount(
easy_unlock_private_api::OnUserInfoUpdated::kEventName);
}
int AuthAttemptedCount() const {
return event_router_->GetEventCount(
screenlock_private_api::OnAuthAttempted::kEventName);
......@@ -471,72 +463,6 @@ TEST_F(EasyUnlockAppManagerTest, LaunchSetupWhenNotLoaded) {
EXPECT_EQ(0, AppLaunchedCount());
}
TEST_F(EasyUnlockAppManagerTest, SendUserUpdated) {
SetExtensionSystemReady();
app_manager_->LoadApp();
event_router_->AddLazyEventListener(
easy_unlock_private_api::OnUserInfoUpdated::kEventName,
extension_misc::kEasyUnlockAppId);
ASSERT_EQ(0, UserUpdatedCount());
EXPECT_TRUE(app_manager_->SendUserUpdatedEvent("user", true /* logged_in */,
false /* data_ready */));
EXPECT_EQ(1, UserUpdatedCount());
EXPECT_EQ("user", event_consumer_.user_id());
EXPECT_TRUE(event_consumer_.user_logged_in());
EXPECT_FALSE(event_consumer_.user_data_ready());
}
TEST_F(EasyUnlockAppManagerTest, SendUserUpdatedInvertedFlags) {
SetExtensionSystemReady();
app_manager_->LoadApp();
event_router_->AddLazyEventListener(
easy_unlock_private_api::OnUserInfoUpdated::kEventName,
extension_misc::kEasyUnlockAppId);
ASSERT_EQ(0, UserUpdatedCount());
EXPECT_TRUE(app_manager_->SendUserUpdatedEvent("user", false /* logged_in */,
true /* data_ready */));
EXPECT_EQ(1, UserUpdatedCount());
EXPECT_EQ("user", event_consumer_.user_id());
EXPECT_FALSE(event_consumer_.user_logged_in());
EXPECT_TRUE(event_consumer_.user_data_ready());
}
TEST_F(EasyUnlockAppManagerTest, SendUserUpdatedNoRegisteredListeners) {
SetExtensionSystemReady();
app_manager_->LoadApp();
ASSERT_EQ(0, UserUpdatedCount());
EXPECT_FALSE(app_manager_->SendUserUpdatedEvent("user", true, true));
EXPECT_EQ(0, UserUpdatedCount());
}
TEST_F(EasyUnlockAppManagerTest, SendUserUpdatedAppDisabled) {
SetExtensionSystemReady();
app_manager_->LoadApp();
event_router_->AddLazyEventListener(
easy_unlock_private_api::OnUserInfoUpdated::kEventName,
extension_misc::kEasyUnlockAppId);
app_manager_->DisableAppIfLoaded();
ASSERT_EQ(0, UserUpdatedCount());
EXPECT_FALSE(app_manager_->SendUserUpdatedEvent("user", true, true));
EXPECT_EQ(0, UserUpdatedCount());
}
TEST_F(EasyUnlockAppManagerTest, SendAuthAttempted) {
SetExtensionSystemReady();
......@@ -545,8 +471,6 @@ TEST_F(EasyUnlockAppManagerTest, SendAuthAttempted) {
screenlock_private_api::OnAuthAttempted::kEventName,
extension_misc::kEasyUnlockAppId);
ASSERT_EQ(0, UserUpdatedCount());
EXPECT_TRUE(app_manager_->SendAuthAttemptEvent());
EXPECT_EQ(1, AuthAttemptedCount());
}
......
......@@ -70,13 +70,6 @@ class FakeAppManager : public EasyUnlockAppManager {
void ReloadApp() override { ADD_FAILURE() << "Not reached"; }
bool SendUserUpdatedEvent(const std::string& user_id,
bool is_logged_in,
bool data_ready) override {
ADD_FAILURE() << "Not reached";
return false;
}
bool SendAuthAttemptEvent() override {
++auth_attempt_count_;
return !auth_attempt_should_fail_;
......
......@@ -530,14 +530,12 @@ void EasyUnlockService::ReloadAppAndLockScreen() {
// Make sure lock screen state set by the extension gets reset.
ResetScreenlockState();
app_manager_->ReloadApp();
NotifyUserUpdated();
}
void EasyUnlockService::UpdateAppState() {
if (IsAllowed()) {
EnsureTpmKeyPresentIfNeeded();
app_manager_->LoadApp();
NotifyUserUpdated();
if (proximity_auth_system_)
proximity_auth_system_->Start();
......@@ -568,18 +566,6 @@ void EasyUnlockService::DisableAppWithoutResettingScreenlockState() {
app_manager_->DisableAppIfLoaded();
}
void EasyUnlockService::NotifyUserUpdated() {
const AccountId& account_id = GetAccountId();
if (!account_id.is_valid())
return;
// Notify the easy unlock app that the user info changed.
bool logged_in = GetType() == TYPE_REGULAR;
bool data_ready = logged_in || GetRemoteDevices() != NULL;
app_manager_->SendUserUpdatedEvent(account_id.GetUserEmail(), logged_in,
data_ready);
}
void EasyUnlockService::NotifyTurnOffOperationStatusChanged() {
for (EasyUnlockServiceObserver& observer : observers_)
observer.OnTurnOffOperationStatusChanged();
......
......@@ -260,9 +260,6 @@ class EasyUnlockService : public KeyedService {
// the lock screen UI should remain unchanged until the screen unlocks.
void DisableAppWithoutResettingScreenlockState();
// Notifies the easy unlock app that the user state has been updated.
void NotifyUserUpdated();
// Notifies observers that the turn off flow status changed.
void NotifyTurnOffOperationStatusChanged();
......
......@@ -453,14 +453,6 @@ void EasyUnlockServiceRegular::StartAutoPairing(
}
auto_pairing_callback_ = callback;
std::unique_ptr<base::ListValue> args(new base::ListValue());
std::unique_ptr<extensions::Event> event(new extensions::Event(
extensions::events::EASY_UNLOCK_PRIVATE_ON_START_AUTO_PAIRING,
extensions::api::easy_unlock_private::OnStartAutoPairing::kEventName,
std::move(args)));
extensions::EventRouter::Get(profile())->DispatchEventWithLazyListener(
extension_misc::kEasyUnlockAppId, std::move(event));
}
void EasyUnlockServiceRegular::SetAutoPairingResult(bool success,
......
......@@ -443,8 +443,6 @@ void EasyUnlockServiceSignin::OnFocusedUserChanged(
if (should_update_app_state) {
UpdateAppState();
} else {
NotifyUserUpdated();
}
LoadCurrentUserDataIfNeeded();
......@@ -512,11 +510,6 @@ void EasyUnlockServiceSignin::OnUserDataLoaded(
}
}
// If the fetched data belongs to the currently focused user, notify the app
// that it has to refresh it's user data.
if (account_id == account_id_)
NotifyUserUpdated();
if (devices.empty())
return;
......
......@@ -122,13 +122,6 @@ class TestAppManager : public EasyUnlockAppManager {
++reload_count_;
}
bool SendUserUpdatedEvent(const std::string& user_id,
bool is_logged_in,
bool data_ready) override {
// TODO(tbarzic): Make this a bit smarter and add some test to utilize it.
return true;
}
bool SendAuthAttemptEvent() override {
ADD_FAILURE() << "Not reached.";
return false;
......
......@@ -170,63 +170,6 @@ class EasyUnlockPrivateUnwrapSecureMessageFunction
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUnwrapSecureMessageFunction);
};
class EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction
: public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.seekBluetoothDeviceByAddress",
EASYUNLOCKPRIVATE_SEEKBLUETOOTHDEVICEBYADDRESS)
EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction();
private:
~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() override;
// AsyncExtensionFunction:
bool RunAsync() override;
// Callbacks that are called when the seek operation succeeds or fails.
void OnSeekSuccess();
void OnSeekFailure(const std::string& error_message);
DISALLOW_COPY_AND_ASSIGN(
EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction);
};
class EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction
: public api::BluetoothSocketAbstractConnectFunction {
public:
DECLARE_EXTENSION_FUNCTION(
"easyUnlockPrivate.connectToBluetoothServiceInsecurely",
EASYUNLOCKPRIVATE_CONNECTTOBLUETOOTHSERVICEINSECURELY)
EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction();
private:
~EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() override;
// BluetoothSocketAbstractConnectFunction:
void ConnectToService(device::BluetoothDevice* device,
const device::BluetoothUUID& uuid) override;
DISALLOW_COPY_AND_ASSIGN(
EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction);
};
class EasyUnlockPrivateUpdateScreenlockStateFunction
: public UIThreadExtensionFunction {
public:
EasyUnlockPrivateUpdateScreenlockStateFunction();
protected:
~EasyUnlockPrivateUpdateScreenlockStateFunction() override;
ResponseAction Run() override;
private:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.updateScreenlockState",
EASYUNLOCKPRIVATE_UPDATESCREENLOCKSTATE)
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUpdateScreenlockStateFunction);
};
class EasyUnlockPrivateSetPermitAccessFunction
: public UIThreadExtensionFunction {
public:
......@@ -339,41 +282,6 @@ class EasyUnlockPrivateGetRemoteDevicesFunction
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetRemoteDevicesFunction);
};
class EasyUnlockPrivateGetSignInChallengeFunction :
public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getSignInChallenge",
EASYUNLOCKPRIVATE_GETSIGNINCHALLENGE)
EasyUnlockPrivateGetSignInChallengeFunction();
private:
~EasyUnlockPrivateGetSignInChallengeFunction() override;
// AsyncExtensionFunction:
bool RunAsync() override;
// Called when the challenge and the signed nonce have been generated.
void OnDone(const std::string& challenge, const std::string& signed_nonce);
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetSignInChallengeFunction);
};
class EasyUnlockPrivateTrySignInSecretFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.trySignInSecret",
EASYUNLOCKPRIVATE_TRYSIGNINSECRET)
EasyUnlockPrivateTrySignInSecretFunction();
private:
~EasyUnlockPrivateTrySignInSecretFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateTrySignInSecretFunction);
};
class EasyUnlockPrivateGetUserInfoFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getUserInfo",
......@@ -389,25 +297,6 @@ class EasyUnlockPrivateGetUserInfoFunction : public UIThreadExtensionFunction {
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetUserInfoFunction);
};
class EasyUnlockPrivateGetConnectionInfoFunction
: public api::BluetoothExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getConnectionInfo",
EASYUNLOCKPRIVATE_GETCONNECTIONINFO)
EasyUnlockPrivateGetConnectionInfoFunction();
private:
~EasyUnlockPrivateGetConnectionInfoFunction() override;
// BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
void OnConnectionInfo(
const device::BluetoothDevice::ConnectionInfo& connection_info);
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetConnectionInfoFunction);
};
class EasyUnlockPrivateShowErrorBubbleFunction
: public UIThreadExtensionFunction {
public:
......@@ -440,22 +329,6 @@ class EasyUnlockPrivateHideErrorBubbleFunction
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateHideErrorBubbleFunction);
};
class EasyUnlockPrivateSetAutoPairingResultFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setAutoPairingResult",
EASYUNLOCKPRIVATE_SETAUTOPAIRINGRESULT)
EasyUnlockPrivateSetAutoPairingResultFunction();
private:
~EasyUnlockPrivateSetAutoPairingResultFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetAutoPairingResultFunction);
};
class EasyUnlockPrivateFindSetupConnectionFunction
: public AsyncExtensionFunction {
public:
......@@ -486,22 +359,6 @@ class EasyUnlockPrivateFindSetupConnectionFunction
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateFindSetupConnectionFunction);
};
class EasyUnlockPrivateSetupConnectionStatusFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setupConnectionStatus",
EASYUNLOCKPRIVATE_SETUPCONNECTIONSTATUS)
EasyUnlockPrivateSetupConnectionStatusFunction();
private:
~EasyUnlockPrivateSetupConnectionStatusFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetupConnectionStatusFunction);
};
class EasyUnlockPrivateSetupConnectionDisconnectFunction
: public UIThreadExtensionFunction {
public:
......@@ -534,24 +391,6 @@ class EasyUnlockPrivateSetupConnectionSendFunction
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetupConnectionSendFunction);
};
class EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION(
"easyUnlockPrivate.setupConnectionGetDeviceAddress",
EASYUNLOCKPRIVATE_SETUPCONNECTIONGETDEVICEADDRESS)
EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction();
private:
~EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(
EasyUnlockPrivateSetupConnectionGetDeviceAddressFunction);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_
......@@ -61,7 +61,6 @@ using extensions::EasyUnlockPrivateCreateSecureMessageFunction;
using extensions::EasyUnlockPrivateConnectionManager;
using extensions::EasyUnlockPrivateGenerateEcP256KeyPairFunction;
using extensions::EasyUnlockPrivatePerformECDHKeyAgreementFunction;
using extensions::EasyUnlockPrivateSetAutoPairingResultFunction;
using extensions::EasyUnlockPrivateUnwrapSecureMessageFunction;
using extensions::Extension;
using extensions::ExtensionBuilder;
......@@ -503,57 +502,6 @@ struct AutoPairingResult {
std::string error;
};
// Test factory to register EasyUnlockService.
std::unique_ptr<KeyedService> BuildTestEasyUnlockService(
content::BrowserContext* context) {
std::unique_ptr<chromeos::EasyUnlockServiceRegular> service(
new chromeos::EasyUnlockServiceRegular(
Profile::FromBrowserContext(context)));
service->Initialize(chromeos::EasyUnlockAppManager::Create(
extensions::ExtensionSystem::Get(context), -1 /* manifest id */,
base::FilePath()));
return std::move(service);
}
TEST_F(EasyUnlockPrivateApiTest, AutoPairing) {
extensions::TestEventRouter* event_router =
extensions::CreateAndUseTestEventRouter(profile());
event_router->set_expected_extension_id(extension_misc::kEasyUnlockAppId);
chromeos::EasyUnlockServiceFactory::GetInstance()->SetTestingFactoryAndUse(
profile(), &BuildTestEasyUnlockService);
AutoPairingResult result;
// Dispatch OnStartAutoPairing event on EasyUnlockService::StartAutoPairing.
chromeos::EasyUnlockService* service =
chromeos::EasyUnlockService::Get(profile());
service->StartAutoPairing(base::Bind(&AutoPairingResult::SetResult,
base::Unretained(&result)));
EXPECT_EQ(1,
event_router->GetEventCount(extensions::api::easy_unlock_private::
OnStartAutoPairing::kEventName));
// Test SetAutoPairingResult call with failure.
scoped_refptr<EasyUnlockPrivateSetAutoPairingResultFunction> function(
new EasyUnlockPrivateSetAutoPairingResultFunction());
ASSERT_TRUE(extension_function_test_utils::RunFunction(
function.get(), "[{\"success\":false, \"errorMessage\":\"fake_error\"}]",
browser(), extensions::api_test_utils::NONE));
EXPECT_FALSE(result.success);
EXPECT_EQ("fake_error", result.error);
// Test SetAutoPairingResult call with success.
service->StartAutoPairing(base::Bind(&AutoPairingResult::SetResult,
base::Unretained(&result)));
function = new EasyUnlockPrivateSetAutoPairingResultFunction();
ASSERT_TRUE(extension_function_test_utils::RunFunction(
function.get(), "[{\"success\":true}]", browser(),
extensions::api_test_utils::NONE));
EXPECT_TRUE(result.success);
EXPECT_TRUE(result.error.empty());
}
// Tests that no BrowserContext dependencies of EasyUnlockPrivateApi (and its
// dependencies) are referenced after the BrowserContext is torn down. The test
// fails with a crash if such a condition exists.
......
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