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/guid.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
11 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
13 #include "base/prefs/scoped_user_pref_update.h" | 14 #include "base/prefs/scoped_user_pref_update.h" |
14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 new base::DictionaryValue(), | 213 new base::DictionaryValue(), |
213 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 214 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
214 registry->RegisterBooleanPref( | 215 registry->RegisterBooleanPref( |
215 prefs::kEasyUnlockProximityRequired, | 216 prefs::kEasyUnlockProximityRequired, |
216 false, | 217 false, |
217 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 218 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
218 } | 219 } |
219 | 220 |
220 // static | 221 // static |
221 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { | 222 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 223 registry->RegisterStringPref(prefs::kEasyUnlockDeviceId, std::string()); |
| 224 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); |
222 registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs); | 225 registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs); |
223 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); | |
224 #if defined(OS_CHROMEOS) | 226 #if defined(OS_CHROMEOS) |
225 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry); | 227 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry); |
226 #endif | 228 #endif |
227 } | 229 } |
228 | 230 |
229 // static | 231 // static |
230 void EasyUnlockService::ResetLocalStateForUser(const std::string& user_id) { | 232 void EasyUnlockService::ResetLocalStateForUser(const std::string& user_id) { |
231 DCHECK(!user_id.empty()); | 233 DCHECK(!user_id.empty()); |
232 | 234 |
233 PrefService* local_state = GetLocalState(); | 235 PrefService* local_state = GetLocalState(); |
(...skipping 28 matching lines...) Expand all Loading... |
262 &user_prefs_dict)) | 264 &user_prefs_dict)) |
263 return user_settings; | 265 return user_settings; |
264 | 266 |
265 user_prefs_dict->GetBooleanWithoutPathExpansion( | 267 user_prefs_dict->GetBooleanWithoutPathExpansion( |
266 prefs::kEasyUnlockProximityRequired, | 268 prefs::kEasyUnlockProximityRequired, |
267 &user_settings.require_close_proximity); | 269 &user_settings.require_close_proximity); |
268 | 270 |
269 return user_settings; | 271 return user_settings; |
270 } | 272 } |
271 | 273 |
| 274 // static |
| 275 std::string EasyUnlockService::GetDeviceId() { |
| 276 PrefService* local_state = GetLocalState(); |
| 277 if (!local_state) |
| 278 return std::string(); |
| 279 |
| 280 std::string device_id = local_state->GetString(prefs::kEasyUnlockDeviceId); |
| 281 if (device_id.empty()) { |
| 282 device_id = base::GenerateGUID(); |
| 283 local_state->SetString(prefs::kEasyUnlockDeviceId, device_id); |
| 284 } |
| 285 return device_id; |
| 286 } |
| 287 |
272 void EasyUnlockService::Initialize( | 288 void EasyUnlockService::Initialize( |
273 scoped_ptr<EasyUnlockAppManager> app_manager) { | 289 scoped_ptr<EasyUnlockAppManager> app_manager) { |
274 app_manager_ = app_manager.Pass(); | 290 app_manager_ = app_manager.Pass(); |
275 app_manager_->EnsureReady( | 291 app_manager_->EnsureReady( |
276 base::Bind(&EasyUnlockService::InitializeOnAppManagerReady, | 292 base::Bind(&EasyUnlockService::InitializeOnAppManagerReady, |
277 weak_ptr_factory_.GetWeakPtr())); | 293 weak_ptr_factory_.GetWeakPtr())); |
278 } | 294 } |
279 | 295 |
280 bool EasyUnlockService::IsAllowed() const { | 296 bool EasyUnlockService::IsAllowed() const { |
281 if (shut_down_) | 297 if (shut_down_) |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 | 765 |
750 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 766 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
751 // failed. | 767 // failed. |
752 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 768 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
753 ->PrepareTpmKey(true /* check_private_key */, | 769 ->PrepareTpmKey(true /* check_private_key */, |
754 base::Closure()); | 770 base::Closure()); |
755 #endif // defined(OS_CHROMEOS) | 771 #endif // defined(OS_CHROMEOS) |
756 | 772 |
757 tpm_key_checked_ = true; | 773 tpm_key_checked_ = true; |
758 } | 774 } |
OLD | NEW |