| 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> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 9 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 14 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 15 #include "base/prefs/scoped_user_pref_update.h" | |
| 16 #include "base/values.h" | 12 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/component_loader.h" | 13 #include "chrome/browser/extensions/component_loader.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 16 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 21 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 17 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
| 22 #include "chrome/browser/signin/easy_unlock_service_observer.h" | 18 #include "chrome/browser/signin/easy_unlock_service_observer.h" |
| 23 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" | |
| 24 #include "chrome/browser/signin/screenlock_bridge.h" | 19 #include "chrome/browser/signin/screenlock_bridge.h" |
| 25 #include "chrome/browser/ui/extensions/application_launch.h" | |
| 26 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/extensions/extension_constants.h" |
| 27 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 28 #include "components/pref_registry/pref_registry_syncable.h" | 23 #include "components/pref_registry/pref_registry_syncable.h" |
| 29 #include "device/bluetooth/bluetooth_adapter.h" | 24 #include "device/bluetooth/bluetooth_adapter.h" |
| 30 #include "device/bluetooth/bluetooth_adapter_factory.h" | 25 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 31 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 33 #include "extensions/common/one_shot_event.h" | 28 #include "extensions/common/one_shot_event.h" |
| 34 #include "grit/browser_resources.h" | 29 #include "grit/browser_resources.h" |
| 35 | 30 |
| 36 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 37 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 38 #include "chromeos/dbus/dbus_thread_manager.h" | 32 #include "chromeos/dbus/dbus_thread_manager.h" |
| 39 #include "chromeos/dbus/power_manager_client.h" | 33 #include "chromeos/dbus/power_manager_client.h" |
| 40 #include "components/user_manager/user_manager.h" | |
| 41 #endif | 34 #endif |
| 42 | 35 |
| 43 namespace { | 36 namespace { |
| 44 | 37 |
| 45 // Key name of the local device permit record dictonary in kEasyUnlockPairing. | |
| 46 const char kKeyPermitAccess[] = "permitAccess"; | |
| 47 | |
| 48 // Key name of the remote device list in kEasyUnlockPairing. | |
| 49 const char kKeyDevices[] = "devices"; | |
| 50 | |
| 51 // Key name of the phone public key in a device dictionary. | |
| 52 const char kKeyPhoneId[] = "permitRecord.id"; | |
| 53 | |
| 54 extensions::ComponentLoader* GetComponentLoader( | 38 extensions::ComponentLoader* GetComponentLoader( |
| 55 content::BrowserContext* context) { | 39 content::BrowserContext* context) { |
| 56 extensions::ExtensionSystem* extension_system = | 40 extensions::ExtensionSystem* extension_system = |
| 57 extensions::ExtensionSystem::Get(context); | 41 extensions::ExtensionSystem::Get(context); |
| 58 ExtensionService* extension_service = extension_system->extension_service(); | 42 ExtensionService* extension_service = extension_system->extension_service(); |
| 59 return extension_service->component_loader(); | 43 return extension_service->component_loader(); |
| 60 } | 44 } |
| 61 | 45 |
| 62 } // namespace | 46 } // namespace |
| 63 | 47 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 106 |
| 123 virtual ~PowerMonitor() { | 107 virtual ~PowerMonitor() { |
| 124 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 108 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 125 RemoveObserver(this); | 109 RemoveObserver(this); |
| 126 } | 110 } |
| 127 | 111 |
| 128 private: | 112 private: |
| 129 // chromeos::PowerManagerClient::Observer: | 113 // chromeos::PowerManagerClient::Observer: |
| 130 virtual void SuspendImminent() OVERRIDE { | 114 virtual void SuspendImminent() OVERRIDE { |
| 131 service_->DisableAppIfLoaded(); | 115 service_->DisableAppIfLoaded(); |
| 132 service_->screenlock_state_handler_.reset(); | |
| 133 } | 116 } |
| 134 | 117 |
| 135 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE { | 118 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE { |
| 136 service_->LoadApp(); | 119 service_->LoadApp(); |
| 137 } | 120 } |
| 138 | 121 |
| 139 EasyUnlockService* service_; | 122 EasyUnlockService* service_; |
| 140 | 123 |
| 141 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); | 124 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); |
| 142 }; | 125 }; |
| 143 #endif | 126 #endif |
| 144 | 127 |
| 145 EasyUnlockService::EasyUnlockService(Profile* profile) | 128 EasyUnlockService::EasyUnlockService(Profile* profile) |
| 146 : profile_(profile), | 129 : profile_(profile), |
| 130 turn_off_flow_status_(IDLE), |
| 147 bluetooth_detector_(new BluetoothDetector(this)), | 131 bluetooth_detector_(new BluetoothDetector(this)), |
| 148 turn_off_flow_status_(IDLE), | |
| 149 weak_ptr_factory_(this) { | 132 weak_ptr_factory_(this) { |
| 150 extensions::ExtensionSystem::Get(profile_)->ready().Post( | 133 extensions::ExtensionSystem::Get(profile_)->ready().Post( |
| 151 FROM_HERE, | 134 FROM_HERE, |
| 152 base::Bind(&EasyUnlockService::Initialize, | 135 base::Bind(&EasyUnlockService::Initialize, |
| 153 weak_ptr_factory_.GetWeakPtr())); | 136 weak_ptr_factory_.GetWeakPtr())); |
| 154 } | 137 } |
| 155 | 138 |
| 156 EasyUnlockService::~EasyUnlockService() { | 139 EasyUnlockService::~EasyUnlockService() { |
| 157 } | 140 } |
| 158 | 141 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 170 registry->RegisterDictionaryPref( | 153 registry->RegisterDictionaryPref( |
| 171 prefs::kEasyUnlockPairing, | 154 prefs::kEasyUnlockPairing, |
| 172 new base::DictionaryValue(), | 155 new base::DictionaryValue(), |
| 173 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 156 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 174 registry->RegisterBooleanPref( | 157 registry->RegisterBooleanPref( |
| 175 prefs::kEasyUnlockAllowed, | 158 prefs::kEasyUnlockAllowed, |
| 176 true, | 159 true, |
| 177 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 160 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 178 } | 161 } |
| 179 | 162 |
| 180 void EasyUnlockService::LaunchSetup() { | |
| 181 ExtensionService* service = | |
| 182 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
| 183 const extensions::Extension* extension = | |
| 184 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); | |
| 185 | |
| 186 OpenApplication(AppLaunchParams( | |
| 187 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); | |
| 188 } | |
| 189 | |
| 190 bool EasyUnlockService::IsAllowed() { | 163 bool EasyUnlockService::IsAllowed() { |
| 191 #if defined(OS_CHROMEOS) | 164 if (!IsAllowedInternal()) |
| 192 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser()) | |
| 193 return false; | 165 return false; |
| 194 | 166 |
| 195 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile_)) | 167 #if defined(OS_CHROMEOS) |
| 196 return false; | |
| 197 | |
| 198 if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) | 168 if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) |
| 199 return false; | 169 return false; |
| 200 | 170 |
| 201 // Respect existing policy and skip finch test. | 171 // Respect existing policy and skip finch test. |
| 202 if (!profile_->GetPrefs()->IsManagedPreference(prefs::kEasyUnlockAllowed)) { | 172 if (!profile_->GetPrefs()->IsManagedPreference(prefs::kEasyUnlockAllowed)) { |
| 203 // It is disabled when the trial exists and is in "Disable" group. | 173 // It is disabled when the trial exists and is in "Disable" group. |
| 204 if (base::FieldTrialList::FindFullName("EasyUnlock") == "Disable") | 174 if (base::FieldTrialList::FindFullName("EasyUnlock") == "Disable") |
| 205 return false; | 175 return false; |
| 206 } | 176 } |
| 207 | 177 |
| 208 if (!bluetooth_detector_->IsPresent()) | 178 if (!bluetooth_detector_->IsPresent()) |
| 209 return false; | 179 return false; |
| 210 | 180 |
| 211 return true; | 181 return true; |
| 212 #else | 182 #else |
| 213 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | 183 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
| 214 return false; | 184 return false; |
| 215 #endif | 185 #endif |
| 216 } | 186 } |
| 217 | 187 |
| 218 EasyUnlockScreenlockStateHandler* | 188 EasyUnlockScreenlockStateHandler* |
| 219 EasyUnlockService::GetScreenlockStateHandler() { | 189 EasyUnlockService::GetScreenlockStateHandler() { |
| 220 if (!IsAllowed()) | 190 if (!IsAllowed()) |
| 221 return NULL; | 191 return NULL; |
| 222 if (!screenlock_state_handler_) { | 192 if (!screenlock_state_handler_) { |
| 223 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 193 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
| 224 ScreenlockBridge::GetAuthenticatedUserEmail(profile_), | 194 GetUserEmail(), |
| 225 profile_->GetPrefs(), | 195 GetType() == TYPE_REGULAR ? profile_->GetPrefs() : NULL, |
| 226 ScreenlockBridge::Get())); | 196 ScreenlockBridge::Get())); |
| 227 } | 197 } |
| 228 return screenlock_state_handler_.get(); | 198 return screenlock_state_handler_.get(); |
| 229 } | 199 } |
| 230 | 200 |
| 231 const base::DictionaryValue* EasyUnlockService::GetPermitAccess() const { | |
| 232 const base::DictionaryValue* pairing_dict = | |
| 233 profile_->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); | |
| 234 const base::DictionaryValue* permit_dict = NULL; | |
| 235 if (pairing_dict && | |
| 236 pairing_dict->GetDictionary(kKeyPermitAccess, &permit_dict)) { | |
| 237 return permit_dict; | |
| 238 } | |
| 239 | |
| 240 return NULL; | |
| 241 } | |
| 242 | |
| 243 void EasyUnlockService::SetPermitAccess(const base::DictionaryValue& permit) { | |
| 244 DictionaryPrefUpdate pairing_update(profile_->GetPrefs(), | |
| 245 prefs::kEasyUnlockPairing); | |
| 246 pairing_update->SetWithoutPathExpansion(kKeyPermitAccess, permit.DeepCopy()); | |
| 247 } | |
| 248 | |
| 249 void EasyUnlockService::ClearPermitAccess() { | |
| 250 DictionaryPrefUpdate pairing_update(profile_->GetPrefs(), | |
| 251 prefs::kEasyUnlockPairing); | |
| 252 pairing_update->RemoveWithoutPathExpansion(kKeyPermitAccess, NULL); | |
| 253 } | |
| 254 | |
| 255 const base::ListValue* EasyUnlockService::GetRemoteDevices() const { | |
| 256 const base::DictionaryValue* pairing_dict = | |
| 257 profile_->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); | |
| 258 const base::ListValue* devices = NULL; | |
| 259 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) { | |
| 260 return devices; | |
| 261 } | |
| 262 | |
| 263 return NULL; | |
| 264 } | |
| 265 | |
| 266 void EasyUnlockService::SetRemoteDevices(const base::ListValue& devices) { | |
| 267 DictionaryPrefUpdate pairing_update(profile_->GetPrefs(), | |
| 268 prefs::kEasyUnlockPairing); | |
| 269 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy()); | |
| 270 } | |
| 271 | |
| 272 void EasyUnlockService::ClearRemoteDevices() { | |
| 273 DictionaryPrefUpdate pairing_update(profile_->GetPrefs(), | |
| 274 prefs::kEasyUnlockPairing); | |
| 275 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); | |
| 276 } | |
| 277 | |
| 278 void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) { | 201 void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) { |
| 279 observers_.AddObserver(observer); | 202 observers_.AddObserver(observer); |
| 280 } | 203 } |
| 281 | 204 |
| 282 void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) { | 205 void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) { |
| 283 observers_.RemoveObserver(observer); | 206 observers_.RemoveObserver(observer); |
| 284 } | 207 } |
| 285 | 208 |
| 286 void EasyUnlockService::RunTurnOffFlow() { | |
| 287 if (turn_off_flow_status_ == PENDING) | |
| 288 return; | |
| 289 | |
| 290 SetTurnOffFlowStatus(PENDING); | |
| 291 | |
| 292 // Currently there should only be one registered phone. | |
| 293 // TODO(xiyuan): Revisit this when server supports toggle for all or | |
| 294 // there are multiple phones. | |
| 295 const base::DictionaryValue* pairing_dict = | |
| 296 profile_->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); | |
| 297 const base::ListValue* devices_list = NULL; | |
| 298 const base::DictionaryValue* first_device = NULL; | |
| 299 std::string phone_public_key; | |
| 300 if (!pairing_dict || !pairing_dict->GetList(kKeyDevices, &devices_list) || | |
| 301 !devices_list || !devices_list->GetDictionary(0, &first_device) || | |
| 302 !first_device || | |
| 303 !first_device->GetString(kKeyPhoneId, &phone_public_key)) { | |
| 304 LOG(WARNING) << "Bad easy unlock pairing data, wiping out local data"; | |
| 305 OnTurnOffFlowFinished(true); | |
| 306 return; | |
| 307 } | |
| 308 | |
| 309 turn_off_flow_.reset(new EasyUnlockToggleFlow( | |
| 310 profile_, | |
| 311 phone_public_key, | |
| 312 false, | |
| 313 base::Bind(&EasyUnlockService::OnTurnOffFlowFinished, | |
| 314 base::Unretained(this)))); | |
| 315 turn_off_flow_->Start(); | |
| 316 } | |
| 317 | |
| 318 void EasyUnlockService::ResetTurnOffFlow() { | |
| 319 turn_off_flow_.reset(); | |
| 320 SetTurnOffFlowStatus(IDLE); | |
| 321 } | |
| 322 | |
| 323 void EasyUnlockService::Initialize() { | |
| 324 registrar_.Init(profile_->GetPrefs()); | |
| 325 registrar_.Add( | |
| 326 prefs::kEasyUnlockAllowed, | |
| 327 base::Bind(&EasyUnlockService::OnPrefsChanged, base::Unretained(this))); | |
| 328 OnPrefsChanged(); | |
| 329 | |
| 330 #if defined(OS_CHROMEOS) | |
| 331 // Only start Bluetooth detection for ChromeOS since the feature is | |
| 332 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms | |
| 333 // previously introduced a performance regression: http://crbug.com/404482 | |
| 334 // Make sure not to reintroduce a performance regression if re-enabling on | |
| 335 // additional platforms. | |
| 336 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | |
| 337 bluetooth_detector_->Initialize(); | |
| 338 #endif // defined(OS_CHROMEOS) | |
| 339 } | |
| 340 | |
| 341 void EasyUnlockService::LoadApp() { | 209 void EasyUnlockService::LoadApp() { |
| 342 DCHECK(IsAllowed()); | 210 DCHECK(IsAllowed()); |
| 343 | 211 |
| 344 #if defined(GOOGLE_CHROME_BUILD) | 212 #if defined(GOOGLE_CHROME_BUILD) |
| 345 base::FilePath easy_unlock_path; | 213 base::FilePath easy_unlock_path; |
| 346 #if defined(OS_CHROMEOS) | 214 #if defined(OS_CHROMEOS) |
| 347 easy_unlock_path = base::FilePath("/usr/share/chromeos-assets/easy_unlock"); | 215 easy_unlock_path = base::FilePath("/usr/share/chromeos-assets/easy_unlock"); |
| 348 #endif // defined(OS_CHROMEOS) | 216 #endif // defined(OS_CHROMEOS) |
| 349 | 217 |
| 350 #ifndef NDEBUG | 218 #ifndef NDEBUG |
| 351 // Only allow app path override switch for debug build. | 219 // Only allow app path override switch for debug build. |
| 352 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 220 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 353 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { | 221 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { |
| 354 easy_unlock_path = | 222 easy_unlock_path = |
| 355 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); | 223 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); |
| 356 } | 224 } |
| 357 #endif // !defined(NDEBUG) | 225 #endif // !defined(NDEBUG) |
| 358 | 226 |
| 359 if (!easy_unlock_path.empty()) { | 227 if (!easy_unlock_path.empty()) { |
| 360 extensions::ComponentLoader* loader = GetComponentLoader(profile_); | 228 extensions::ComponentLoader* loader = GetComponentLoader(profile_); |
| 361 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) { | 229 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) |
| 362 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); | 230 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); |
| 363 } | 231 |
| 364 ExtensionService* extension_service = | 232 ExtensionService* extension_service = |
| 365 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 233 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 366 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); | 234 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); |
| 367 } | 235 } |
| 368 #endif // defined(GOOGLE_CHROME_BUILD) | 236 #endif // defined(GOOGLE_CHROME_BUILD) |
| 369 } | 237 } |
| 370 | 238 |
| 371 void EasyUnlockService::DisableAppIfLoaded() { | 239 void EasyUnlockService::DisableAppIfLoaded() { |
| 240 // Make sure lock screen state set by the extension gets reset. |
| 241 screenlock_state_handler_.reset(); |
| 242 |
| 372 extensions::ComponentLoader* loader = GetComponentLoader(profile_); | 243 extensions::ComponentLoader* loader = GetComponentLoader(profile_); |
| 373 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) | 244 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) |
| 374 return; | 245 return; |
| 375 | 246 |
| 376 ExtensionService* extension_service = | 247 ExtensionService* extension_service = |
| 377 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 248 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 378 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, | 249 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, |
| 379 extensions::Extension::DISABLE_RELOAD); | 250 extensions::Extension::DISABLE_RELOAD); |
| 380 } | 251 } |
| 381 | 252 |
| 253 void EasyUnlockService::ReloadApp() { |
| 254 // Make sure lock screen state set by the extension gets reset. |
| 255 screenlock_state_handler_.reset(); |
| 256 |
| 257 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { |
| 258 extensions::ExtensionSystem* extension_system = |
| 259 extensions::ExtensionSystem::Get(profile_); |
| 260 extension_system->extension_service()->ReloadExtension( |
| 261 extension_misc::kEasyUnlockAppId); |
| 262 } |
| 263 } |
| 264 |
| 382 void EasyUnlockService::UpdateAppState() { | 265 void EasyUnlockService::UpdateAppState() { |
| 383 if (IsAllowed()) { | 266 if (IsAllowed()) { |
| 384 LoadApp(); | 267 LoadApp(); |
| 385 | 268 |
| 386 #if defined(OS_CHROMEOS) | 269 #if defined(OS_CHROMEOS) |
| 387 if (!power_monitor_) | 270 if (!power_monitor_) |
| 388 power_monitor_.reset(new PowerMonitor(this)); | 271 power_monitor_.reset(new PowerMonitor(this)); |
| 389 #endif | 272 #endif |
| 390 } else { | 273 } else { |
| 391 DisableAppIfLoaded(); | 274 DisableAppIfLoaded(); |
| 392 // Reset the screenlock state handler to make sure Screenlock state set | |
| 393 // by Easy Unlock app is reset. | |
| 394 screenlock_state_handler_.reset(); | |
| 395 | |
| 396 #if defined(OS_CHROMEOS) | 275 #if defined(OS_CHROMEOS) |
| 397 power_monitor_.reset(); | 276 power_monitor_.reset(); |
| 398 #endif | 277 #endif |
| 399 } | 278 } |
| 400 } | 279 } |
| 401 | 280 |
| 402 void EasyUnlockService::OnPrefsChanged() { | 281 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { |
| 403 UpdateAppState(); | 282 FOR_EACH_OBSERVER( |
| 283 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); |
| 284 } |
| 285 |
| 286 void EasyUnlockService::Initialize() { |
| 287 InitializeInternal(); |
| 288 |
| 289 #if defined(OS_CHROMEOS) |
| 290 // Only start Bluetooth detection for ChromeOS since the feature is |
| 291 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms |
| 292 // previously introduced a performance regression: http://crbug.com/404482 |
| 293 // Make sure not to reintroduce a performance regression if re-enabling on |
| 294 // additional platforms. |
| 295 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
| 296 bluetooth_detector_->Initialize(); |
| 297 #endif // defined(OS_CHROMEOS) |
| 404 } | 298 } |
| 405 | 299 |
| 406 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { | 300 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { |
| 407 UpdateAppState(); | 301 UpdateAppState(); |
| 408 } | 302 } |
| 409 | 303 |
| 410 void EasyUnlockService::SetTurnOffFlowStatus(TurnOffFlowStatus status) { | |
| 411 turn_off_flow_status_ = status; | |
| 412 FOR_EACH_OBSERVER( | |
| 413 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); | |
| 414 } | |
| 415 | |
| 416 void EasyUnlockService::OnTurnOffFlowFinished(bool success) { | |
| 417 turn_off_flow_.reset(); | |
| 418 | |
| 419 if (!success) { | |
| 420 SetTurnOffFlowStatus(FAIL); | |
| 421 return; | |
| 422 } | |
| 423 | |
| 424 ClearRemoteDevices(); | |
| 425 SetTurnOffFlowStatus(IDLE); | |
| 426 | |
| 427 // Make sure lock screen state set by the extension gets reset. | |
| 428 screenlock_state_handler_.reset(); | |
| 429 | |
| 430 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { | |
| 431 extensions::ExtensionSystem* extension_system = | |
| 432 extensions::ExtensionSystem::Get(profile_); | |
| 433 extension_system->extension_service()->ReloadExtension( | |
| 434 extension_misc::kEasyUnlockAppId); | |
| 435 } | |
| 436 } | |
| OLD | NEW |