ExtensionSyncService: listen for relevant changes instead of being explicitly called...
[chromium-blink-merge.git] / chrome / browser / chromeos / login / easy_unlock / bootstrap_manager.cc
blob7ad5ddeaaaa4f4faa7a497ef3f7e811afb6a6c3a
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"
13 namespace chromeos {
15 namespace {
17 // A pref list of users who have not finished Easy bootstrapping.
18 const char kPendingEasyBootstrapUsers[] = "PendingEasyBootstrapUsers";
20 } // namespace
22 // static
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, &current_user) && user_id == current_user) {
49 update->Remove(i, NULL);
50 break;
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, &current_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, &current_user) && user_id == current_user)
78 return true;
80 return false;
83 } // namespace chromeos