Commit 0d60628c authored by tbarzic's avatar tbarzic Committed by Commit bot

easy_unlock: When loading the easy-unlock app, make sure it's enabled

The extension gets disabled when Chrome goes to sleep. If it doesn't
wake up for some reason, the app will stay disabled. To make sure this
doesn't happen, enable the app after loading it (this should be no-op if
the app is already enabled).

TEST=Let a Chromebook battery drain while it's suspended. On next boot the
easy unlock app should be enabled (provided that it was enabled when Chromebook
was suspended).

BUG=410082

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

Cr-Commit-Position: refs/heads/master@{#294980}
parent 21f1f757
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/signin/easy_unlock_service.h" #include "chrome/browser/signin/easy_unlock_service.h"
#include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -126,7 +128,7 @@ class EasyUnlockService::PowerMonitor : ...@@ -126,7 +128,7 @@ class EasyUnlockService::PowerMonitor :
private: private:
// chromeos::PowerManagerClient::Observer: // chromeos::PowerManagerClient::Observer:
virtual void SuspendImminent() OVERRIDE { virtual void SuspendImminent() OVERRIDE {
service_->DisableApp(); service_->DisableAppIfLoaded();
service_->screenlock_state_handler_.reset(); service_->screenlock_state_handler_.reset();
} }
...@@ -358,35 +360,23 @@ void EasyUnlockService::LoadApp() { ...@@ -358,35 +360,23 @@ void EasyUnlockService::LoadApp() {
extensions::ComponentLoader* loader = GetComponentLoader(profile_); extensions::ComponentLoader* loader = GetComponentLoader(profile_);
if (!loader->Exists(extension_misc::kEasyUnlockAppId)) { if (!loader->Exists(extension_misc::kEasyUnlockAppId)) {
loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path);
} else {
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile_);
// If the app is installed but disabled, then enable it.
if (registry->GetExtensionById(extension_misc::kEasyUnlockAppId,
extensions::ExtensionRegistry::DISABLED)) {
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
extension_service->EnableExtension(extension_misc::kEasyUnlockAppId);
}
} }
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
extension_service->EnableExtension(extension_misc::kEasyUnlockAppId);
} }
#endif // defined(GOOGLE_CHROME_BUILD) #endif // defined(GOOGLE_CHROME_BUILD)
} }
void EasyUnlockService::DisableApp() { void EasyUnlockService::DisableAppIfLoaded() {
extensions::ComponentLoader* loader = GetComponentLoader(profile_); extensions::ComponentLoader* loader = GetComponentLoader(profile_);
extensions::ExtensionRegistry* registry = if (!loader->Exists(extension_misc::kEasyUnlockAppId))
extensions::ExtensionRegistry::Get(profile_); return;
if (loader->Exists(extension_misc::kEasyUnlockAppId) && ExtensionService* extension_service =
registry->GetExtensionById(extension_misc::kEasyUnlockAppId, extensions::ExtensionSystem::Get(profile_)->extension_service();
extensions::ExtensionRegistry::ENABLED)) { extension_service->DisableExtension(extension_misc::kEasyUnlockAppId,
ExtensionService* extension_service = extensions::Extension::DISABLE_RELOAD);
extensions::ExtensionSystem::Get(profile_)->extension_service();
extension_service->DisableExtension(extension_misc::kEasyUnlockAppId,
extensions::Extension::DISABLE_RELOAD);
}
} }
void EasyUnlockService::UpdateAppState() { void EasyUnlockService::UpdateAppState() {
...@@ -398,7 +388,7 @@ void EasyUnlockService::UpdateAppState() { ...@@ -398,7 +388,7 @@ void EasyUnlockService::UpdateAppState() {
power_monitor_.reset(new PowerMonitor(this)); power_monitor_.reset(new PowerMonitor(this));
#endif #endif
} else { } else {
DisableApp(); DisableAppIfLoaded();
// Reset the screenlock state handler to make sure Screenlock state set // Reset the screenlock state handler to make sure Screenlock state set
// by Easy Unlock app is reset. // by Easy Unlock app is reset.
screenlock_state_handler_.reset(); screenlock_state_handler_.reset();
......
...@@ -88,8 +88,8 @@ class EasyUnlockService : public KeyedService { ...@@ -88,8 +88,8 @@ class EasyUnlockService : public KeyedService {
// the app if it is installed but disabled. // the app if it is installed but disabled.
void LoadApp(); void LoadApp();
// Disables the Easy unlock component app. // Disables the Easy unlock component app if it's loaded.
void DisableApp(); void DisableAppIfLoaded();
// Checks whether Easy unlock should be running and updates app state. // Checks whether Easy unlock should be running and updates app state.
void UpdateAppState(); void UpdateAppState();
......
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