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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 new base::DictionaryValue(), | 180 new base::DictionaryValue(), |
| 181 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 181 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 182 registry->RegisterBooleanPref( | 182 registry->RegisterBooleanPref( |
| 183 prefs::kEasyUnlockAllowed, | 183 prefs::kEasyUnlockAllowed, |
| 184 true, | 184 true, |
| 185 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 185 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 186 } | 186 } |
| 187 | 187 |
| 188 // static | 188 // static |
| 189 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { | 189 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 190 registry->RegisterDictionaryPref(prefs::kEasyUnlockFirstRunComplete); | |
| 190 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); | 191 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); |
| 191 } | 192 } |
| 192 | 193 |
| 193 // static | 194 // static |
| 194 void EasyUnlockService::RemoveHardlockStateForUser(const std::string& user_id) { | 195 void EasyUnlockService::ResetLocalStateForUser(const std::string& user_id) { |
| 195 DCHECK(!user_id.empty()); | 196 DCHECK(!user_id.empty()); |
| 196 | 197 |
| 197 PrefService* local_state = GetLocalState(); | 198 PrefService* local_state = GetLocalState(); |
| 198 if (!local_state) | 199 if (!local_state) |
| 199 return; | 200 return; |
| 200 | 201 |
| 201 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); | 202 DictionaryPrefUpdate hardlock_update(local_state, |
| 202 update->RemoveWithoutPathExpansion(user_id, NULL); | 203 prefs::kEasyUnlockHardlockState); |
| 204 hardlock_update->RemoveWithoutPathExpansion(user_id, NULL); | |
| 205 | |
| 206 DictionaryPrefUpdate first_run_update(local_state, | |
| 207 prefs::kEasyUnlockFirstRunComplete); | |
| 208 first_run_update->RemoveWithoutPathExpansion(user_id, NULL); | |
| 203 } | 209 } |
| 204 | 210 |
| 205 bool EasyUnlockService::IsAllowed() { | 211 bool EasyUnlockService::IsAllowed() { |
| 206 if (shut_down_) | 212 if (shut_down_) |
| 207 return false; | 213 return false; |
| 208 | 214 |
| 209 if (!IsAllowedInternal()) | 215 if (!IsAllowedInternal()) |
| 210 return false; | 216 return false; |
| 211 | 217 |
| 212 #if defined(OS_CHROMEOS) | 218 #if defined(OS_CHROMEOS) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 return; | 259 return; |
| 254 if (GetScreenlockStateHandler()) | 260 if (GetScreenlockStateHandler()) |
| 255 screenlock_state_handler_->MaybeShowHardlockUI(); | 261 screenlock_state_handler_->MaybeShowHardlockUI(); |
| 256 } | 262 } |
| 257 | 263 |
| 258 EasyUnlockScreenlockStateHandler* | 264 EasyUnlockScreenlockStateHandler* |
| 259 EasyUnlockService::GetScreenlockStateHandler() { | 265 EasyUnlockService::GetScreenlockStateHandler() { |
| 260 if (!IsAllowed()) | 266 if (!IsAllowed()) |
| 261 return NULL; | 267 return NULL; |
| 262 if (!screenlock_state_handler_) { | 268 if (!screenlock_state_handler_) { |
| 269 std::string user_id = GetUserEmail(); | |
| 270 if (GetType() == TYPE_REGULAR) | |
| 271 MaybeMigrateShowTutorialPref(user_id); | |
| 263 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 272 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
| 264 GetUserEmail(), | 273 user_id, |
| 265 GetHardlockState(), | 274 GetHardlockState(), |
| 266 GetType() == TYPE_REGULAR ? profile_->GetPrefs() : NULL, | 275 GetLocalState(), |
| 267 ScreenlockBridge::Get())); | 276 ScreenlockBridge::Get())); |
| 268 } | 277 } |
| 269 return screenlock_state_handler_.get(); | 278 return screenlock_state_handler_.get(); |
| 270 } | 279 } |
| 271 | 280 |
| 272 bool EasyUnlockService::UpdateScreenlockState( | 281 bool EasyUnlockService::UpdateScreenlockState( |
| 273 EasyUnlockScreenlockStateHandler::State state) { | 282 EasyUnlockScreenlockStateHandler::State state) { |
| 274 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); | 283 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); |
| 275 if (!handler) | 284 if (!handler) |
| 276 return false; | 285 return false; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 if (!local_state) | 523 if (!local_state) |
| 515 return; | 524 return; |
| 516 | 525 |
| 517 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); | 526 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); |
| 518 update->SetIntegerWithoutPathExpansion(user_id, static_cast<int>(state)); | 527 update->SetIntegerWithoutPathExpansion(user_id, static_cast<int>(state)); |
| 519 | 528 |
| 520 if (GetUserEmail() == user_id) | 529 if (GetUserEmail() == user_id) |
| 521 SetScreenlockHardlockedState(state); | 530 SetScreenlockHardlockedState(state); |
| 522 } | 531 } |
| 523 | 532 |
| 533 void EasyUnlockService::MaybeMigrateShowTutorialPref( | |
| 534 const std::string& user_id) { | |
| 535 DCHECK_EQ(TYPE_REGULAR, GetType()); | |
| 536 | |
| 537 PrefService* local_state = GetLocalState(); | |
| 538 // The default value for kEasyUnlockShowTutorial pref is true. | |
| 539 if (user_id.empty() || !local_state || | |
| 540 profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockShowTutorial)) | |
| 541 return; | |
| 542 profile_->GetPrefs()->SetBoolean(prefs::kEasyUnlockShowTutorial, true); | |
|
xiyuan
2014/10/08 19:57:25
nit: How about ClearPref() here?
tbarzic
2014/10/09 02:43:24
Done.
| |
| 543 | |
| 544 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockFirstRunComplete); | |
| 545 update->SetBooleanWithoutPathExpansion(user_id, true); | |
| 546 } | |
| 547 | |
| 524 #if defined(OS_CHROMEOS) | 548 #if defined(OS_CHROMEOS) |
| 525 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( | 549 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( |
| 526 const std::string& user_id, | 550 const std::string& user_id, |
| 527 const std::set<std::string> paired_devices, | 551 const std::set<std::string> paired_devices, |
| 528 bool success, | 552 bool success, |
| 529 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) { | 553 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) { |
| 530 DCHECK(!user_id.empty() && !paired_devices.empty()); | 554 DCHECK(!user_id.empty() && !paired_devices.empty()); |
| 531 | 555 |
| 532 if (!success) { | 556 if (!success) { |
| 533 SetHardlockStateForUser(user_id, | 557 SetHardlockStateForUser(user_id, |
| 534 EasyUnlockScreenlockStateHandler::NO_PAIRING); | 558 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
| 535 return; | 559 return; |
| 536 } | 560 } |
| 537 | 561 |
| 538 std::set<std::string> devices_in_cryptohome; | 562 std::set<std::string> devices_in_cryptohome; |
| 539 for (const auto& device_key_data : key_data_list) | 563 for (const auto& device_key_data : key_data_list) |
| 540 devices_in_cryptohome.insert(device_key_data.public_key); | 564 devices_in_cryptohome.insert(device_key_data.public_key); |
| 541 | 565 |
| 542 if (paired_devices != devices_in_cryptohome) { | 566 if (paired_devices != devices_in_cryptohome) { |
| 543 SetHardlockStateForUser(user_id, | 567 SetHardlockStateForUser(user_id, |
| 544 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); | 568 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
| 545 } | 569 } |
| 546 } | 570 } |
| 547 #endif | 571 #endif |
| 548 | 572 |
| OLD | NEW |