Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/signin/easy_unlock_service.h" | 5 #include "chrome/browser/signin/easy_unlock_service.h" |
| 6 | 6 |
| 7 #include <string> | |
|
Tim Song
2014/09/15 23:53:53
Why do you need this?
tbarzic
2014/09/16 00:05:02
just fixing error reported by git cl lint (we use
| |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 12 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 13 #include "base/prefs/scoped_user_pref_update.h" | 15 #include "base/prefs/scoped_user_pref_update.h" |
| 14 #include "base/values.h" | 16 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/component_loader.h" | 17 #include "chrome/browser/extensions/component_loader.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 } | 121 } |
| 120 | 122 |
| 121 virtual ~PowerMonitor() { | 123 virtual ~PowerMonitor() { |
| 122 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 124 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 123 RemoveObserver(this); | 125 RemoveObserver(this); |
| 124 } | 126 } |
| 125 | 127 |
| 126 private: | 128 private: |
| 127 // chromeos::PowerManagerClient::Observer: | 129 // chromeos::PowerManagerClient::Observer: |
| 128 virtual void SuspendImminent() OVERRIDE { | 130 virtual void SuspendImminent() OVERRIDE { |
| 129 service_->DisableApp(); | 131 service_->DisableAppIfLoaded(); |
| 130 service_->screenlock_state_handler_.reset(); | 132 service_->screenlock_state_handler_.reset(); |
| 131 } | 133 } |
| 132 | 134 |
| 133 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE { | 135 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE { |
| 134 service_->LoadApp(); | 136 service_->LoadApp(); |
| 135 } | 137 } |
| 136 | 138 |
| 137 EasyUnlockService* service_; | 139 EasyUnlockService* service_; |
| 138 | 140 |
| 139 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); | 141 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { | 350 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { |
| 349 easy_unlock_path = | 351 easy_unlock_path = |
| 350 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); | 352 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); |
| 351 } | 353 } |
| 352 #endif // !defined(NDEBUG) | 354 #endif // !defined(NDEBUG) |
| 353 | 355 |
| 354 if (!easy_unlock_path.empty()) { | 356 if (!easy_unlock_path.empty()) { |
| 355 extensions::ComponentLoader* loader = GetComponentLoader(profile_); | 357 extensions::ComponentLoader* loader = GetComponentLoader(profile_); |
| 356 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) { | 358 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) { |
| 357 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); | 359 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); |
| 358 } else { | |
| 359 extensions::ExtensionRegistry* registry = | |
| 360 extensions::ExtensionRegistry::Get(profile_); | |
| 361 | |
| 362 // If the app is installed but disabled, then enable it. | |
| 363 if (registry->GetExtensionById(extension_misc::kEasyUnlockAppId, | |
| 364 extensions::ExtensionRegistry::DISABLED)) { | |
| 365 ExtensionService* extension_service = | |
| 366 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
| 367 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); | |
| 368 } | |
| 369 } | 360 } |
| 361 ExtensionService* extension_service = | |
| 362 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
| 363 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); | |
| 370 } | 364 } |
| 371 #endif // defined(GOOGLE_CHROME_BUILD) | 365 #endif // defined(GOOGLE_CHROME_BUILD) |
| 372 } | 366 } |
| 373 | 367 |
| 374 void EasyUnlockService::DisableApp() { | 368 void EasyUnlockService::DisableAppIfLoaded() { |
| 375 extensions::ComponentLoader* loader = GetComponentLoader(profile_); | 369 extensions::ComponentLoader* loader = GetComponentLoader(profile_); |
| 376 extensions::ExtensionRegistry* registry = | 370 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) |
| 377 extensions::ExtensionRegistry::Get(profile_); | 371 return; |
| 378 | 372 |
| 379 if (loader->Exists(extension_misc::kEasyUnlockAppId) && | 373 ExtensionService* extension_service = |
| 380 registry->GetExtensionById(extension_misc::kEasyUnlockAppId, | 374 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 381 extensions::ExtensionRegistry::ENABLED)) { | 375 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, |
| 382 ExtensionService* extension_service = | 376 extensions::Extension::DISABLE_RELOAD); |
| 383 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
| 384 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, | |
| 385 extensions::Extension::DISABLE_RELOAD); | |
| 386 } | |
| 387 } | 377 } |
| 388 | 378 |
| 389 void EasyUnlockService::UpdateAppState() { | 379 void EasyUnlockService::UpdateAppState() { |
| 390 if (IsAllowed()) { | 380 if (IsAllowed()) { |
| 391 LoadApp(); | 381 LoadApp(); |
| 392 | 382 |
| 393 #if defined(OS_CHROMEOS) | 383 #if defined(OS_CHROMEOS) |
| 394 if (!power_monitor_) | 384 if (!power_monitor_) |
| 395 power_monitor_.reset(new PowerMonitor(this)); | 385 power_monitor_.reset(new PowerMonitor(this)); |
| 396 #endif | 386 #endif |
| 397 } else { | 387 } else { |
| 398 DisableApp(); | 388 DisableAppIfLoaded(); |
| 399 // Reset the screenlock state handler to make sure Screenlock state set | 389 // Reset the screenlock state handler to make sure Screenlock state set |
| 400 // by Easy Unlock app is reset. | 390 // by Easy Unlock app is reset. |
| 401 screenlock_state_handler_.reset(); | 391 screenlock_state_handler_.reset(); |
| 402 | 392 |
| 403 #if defined(OS_CHROMEOS) | 393 #if defined(OS_CHROMEOS) |
| 404 power_monitor_.reset(); | 394 power_monitor_.reset(); |
| 405 #endif | 395 #endif |
| 406 } | 396 } |
| 407 } | 397 } |
| 408 | 398 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 434 // Make sure lock screen state set by the extension gets reset. | 424 // Make sure lock screen state set by the extension gets reset. |
| 435 screenlock_state_handler_.reset(); | 425 screenlock_state_handler_.reset(); |
| 436 | 426 |
| 437 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { | 427 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { |
| 438 extensions::ExtensionSystem* extension_system = | 428 extensions::ExtensionSystem* extension_system = |
| 439 extensions::ExtensionSystem::Get(profile_); | 429 extensions::ExtensionSystem::Get(profile_); |
| 440 extension_system->extension_service()->ReloadExtension( | 430 extension_system->extension_service()->ReloadExtension( |
| 441 extension_misc::kEasyUnlockAppId); | 431 extension_misc::kEasyUnlockAppId); |
| 442 } | 432 } |
| 443 } | 433 } |
| OLD | NEW |