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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/easy_unlock/bootstrap_manager.h"
7 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
17 // A pref list of users who have not finished Easy bootstrapping.
18 const char kPendingEasyBootstrapUsers
[] = "PendingEasyBootstrapUsers";
23 void BootstrapManager::RegisterPrefs(PrefRegistrySimple
* registry
) {
24 registry
->RegisterListPref(kPendingEasyBootstrapUsers
);
27 BootstrapManager::BootstrapManager(Delegate
* delegate
)
28 : delegate_(delegate
) {
31 BootstrapManager::~BootstrapManager() {
34 void BootstrapManager::AddPendingBootstrap(const std::string
& user_id
) {
35 DCHECK(!user_id
.empty());
36 PrefService
* local_state
= g_browser_process
->local_state();
38 ListPrefUpdate
update(local_state
, kPendingEasyBootstrapUsers
);
39 update
->AppendString(user_id
);
42 void BootstrapManager::FinishPendingBootstrap(const std::string
& user_id
) {
43 PrefService
* local_state
= g_browser_process
->local_state();
45 ListPrefUpdate
update(local_state
, kPendingEasyBootstrapUsers
);
46 for (size_t i
= 0; i
< update
->GetSize(); ++i
) {
47 std::string current_user
;
48 if (update
->GetString(i
, ¤t_user
) && user_id
== current_user
) {
49 update
->Remove(i
, NULL
);
55 void BootstrapManager::RemoveAllPendingBootstrap() {
56 PrefService
* local_state
= g_browser_process
->local_state();
58 const base::ListValue
* users
=
59 local_state
->GetList(kPendingEasyBootstrapUsers
);
60 for (size_t i
= 0; i
< users
->GetSize(); ++i
) {
61 std::string current_user
;
62 if (users
->GetString(i
, ¤t_user
))
63 delegate_
->RemovePendingBootstrapUser(current_user
);
66 local_state
->ClearPref(kPendingEasyBootstrapUsers
);
67 local_state
->CommitPendingWrite();
70 bool BootstrapManager::HasPendingBootstrap(const std::string
& user_id
) const {
71 PrefService
* local_state
= g_browser_process
->local_state();
73 const base::ListValue
* users
=
74 local_state
->GetList(kPendingEasyBootstrapUsers
);
75 for (size_t i
= 0; i
< users
->GetSize(); ++i
) {
76 std::string current_user
;
77 if (users
->GetString(i
, ¤t_user
) && user_id
== current_user
)
83 } // namespace chromeos