| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromeos/login/easy_unlock/bootstrap_manager.h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/bootstrap_manager.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 registry->RegisterListPref(kPendingEasyBootstrapUsers); | 24 registry->RegisterListPref(kPendingEasyBootstrapUsers); |
| 25 } | 25 } |
| 26 | 26 |
| 27 BootstrapManager::BootstrapManager(Delegate* delegate) | 27 BootstrapManager::BootstrapManager(Delegate* delegate) |
| 28 : delegate_(delegate) { | 28 : delegate_(delegate) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 BootstrapManager::~BootstrapManager() { | 31 BootstrapManager::~BootstrapManager() { |
| 32 } | 32 } |
| 33 | 33 |
| 34 void BootstrapManager::AddPendingBootstrap(const std::string& user_id) { | 34 void BootstrapManager::AddPendingBootstrap(const AccountId& account_id) { |
| 35 DCHECK(!user_id.empty()); | 35 DCHECK(account_id.is_valid()); |
| 36 PrefService* local_state = g_browser_process->local_state(); | 36 PrefService* local_state = g_browser_process->local_state(); |
| 37 | 37 |
| 38 ListPrefUpdate update(local_state, kPendingEasyBootstrapUsers); | 38 ListPrefUpdate update(local_state, kPendingEasyBootstrapUsers); |
| 39 update->AppendString(user_id); | 39 update->AppendString(account_id.GetUserEmail()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void BootstrapManager::FinishPendingBootstrap(const std::string& user_id) { | 42 void BootstrapManager::FinishPendingBootstrap(const AccountId& account_id) { |
| 43 PrefService* local_state = g_browser_process->local_state(); | 43 PrefService* local_state = g_browser_process->local_state(); |
| 44 | 44 |
| 45 ListPrefUpdate update(local_state, kPendingEasyBootstrapUsers); | 45 ListPrefUpdate update(local_state, kPendingEasyBootstrapUsers); |
| 46 for (size_t i = 0; i < update->GetSize(); ++i) { | 46 for (size_t i = 0; i < update->GetSize(); ++i) { |
| 47 std::string current_user; | 47 std::string current_user_email; |
| 48 if (update->GetString(i, ¤t_user) && user_id == current_user) { | 48 if (update->GetString(i, ¤t_user_email) && |
| 49 account_id.GetUserEmail() == current_user_email) { |
| 49 update->Remove(i, NULL); | 50 update->Remove(i, NULL); |
| 50 break; | 51 break; |
| 51 } | 52 } |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 | 55 |
| 55 void BootstrapManager::RemoveAllPendingBootstrap() { | 56 void BootstrapManager::RemoveAllPendingBootstrap() { |
| 56 PrefService* local_state = g_browser_process->local_state(); | 57 PrefService* local_state = g_browser_process->local_state(); |
| 57 | 58 |
| 58 const base::ListValue* users = | 59 const base::ListValue* users = |
| 59 local_state->GetList(kPendingEasyBootstrapUsers); | 60 local_state->GetList(kPendingEasyBootstrapUsers); |
| 60 for (size_t i = 0; i < users->GetSize(); ++i) { | 61 for (size_t i = 0; i < users->GetSize(); ++i) { |
| 61 std::string current_user; | 62 std::string current_user_email; |
| 62 if (users->GetString(i, ¤t_user)) | 63 if (users->GetString(i, ¤t_user_email)) { |
| 63 delegate_->RemovePendingBootstrapUser(current_user); | 64 delegate_->RemovePendingBootstrapUser( |
| 65 user_manager::UserManager::Get()->GetKnownUserAccountId( |
| 66 current_user_email, std::string() /* gaia_id */)); |
| 67 } |
| 64 } | 68 } |
| 65 | 69 |
| 66 local_state->ClearPref(kPendingEasyBootstrapUsers); | 70 local_state->ClearPref(kPendingEasyBootstrapUsers); |
| 67 local_state->CommitPendingWrite(); | 71 local_state->CommitPendingWrite(); |
| 68 } | 72 } |
| 69 | 73 |
| 70 bool BootstrapManager::HasPendingBootstrap(const std::string& user_id) const { | 74 bool BootstrapManager::HasPendingBootstrap(const AccountId& account_id) const { |
| 71 PrefService* local_state = g_browser_process->local_state(); | 75 PrefService* local_state = g_browser_process->local_state(); |
| 72 | 76 |
| 73 const base::ListValue* users = | 77 const base::ListValue* users = |
| 74 local_state->GetList(kPendingEasyBootstrapUsers); | 78 local_state->GetList(kPendingEasyBootstrapUsers); |
| 75 for (size_t i = 0; i < users->GetSize(); ++i) { | 79 for (size_t i = 0; i < users->GetSize(); ++i) { |
| 76 std::string current_user; | 80 std::string current_user; |
| 77 if (users->GetString(i, ¤t_user) && user_id == current_user) | 81 if (users->GetString(i, ¤t_user) && |
| 82 account_id.GetUserEmail() == current_user) |
| 78 return true; | 83 return true; |
| 79 } | 84 } |
| 80 return false; | 85 return false; |
| 81 } | 86 } |
| 82 | 87 |
| 83 } // namespace chromeos | 88 } // namespace chromeos |
| OLD | NEW |