| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/options/chromeos/accounts_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/accounts_options_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
| 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 18 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" | 20 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" |
| 21 #include "chromeos/settings/cros_settings_names.h" | 21 #include "chromeos/settings/cros_settings_names.h" |
| 22 #include "components/user_manager/user_manager.h" |
| 22 #include "content/public/browser/web_ui.h" | 23 #include "content/public/browser/web_ui.h" |
| 23 #include "google_apis/gaia/gaia_auth_util.h" | 24 #include "google_apis/gaia/gaia_auth_util.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 | 27 |
| 27 namespace chromeos { | 28 namespace chromeos { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // Adds specified user to the whitelist. Returns false if that user is already | 32 // Adds specified user to the whitelist. Returns false if that user is already |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 109 |
| 109 void AccountsOptionsHandler::HandleUnwhitelistUser( | 110 void AccountsOptionsHandler::HandleUnwhitelistUser( |
| 110 const base::ListValue* args) { | 111 const base::ListValue* args) { |
| 111 std::string email; | 112 std::string email; |
| 112 if (!args->GetString(0, &email)) { | 113 if (!args->GetString(0, &email)) { |
| 113 return; | 114 return; |
| 114 } | 115 } |
| 115 | 116 |
| 116 base::StringValue canonical_email(gaia::CanonicalizeEmail(email)); | 117 base::StringValue canonical_email(gaia::CanonicalizeEmail(email)); |
| 117 CrosSettings::Get()->RemoveFromList(kAccountsPrefUsers, &canonical_email); | 118 CrosSettings::Get()->RemoveFromList(kAccountsPrefUsers, &canonical_email); |
| 118 UserManager::Get()->RemoveUser(email, NULL); | 119 user_manager::UserManager::Get()->RemoveUser(email, NULL); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void AccountsOptionsHandler::HandleWhitelistExistingUsers( | 122 void AccountsOptionsHandler::HandleWhitelistExistingUsers( |
| 122 const base::ListValue* args) { | 123 const base::ListValue* args) { |
| 123 DCHECK(args && args->empty()); | 124 DCHECK(args && args->empty()); |
| 124 | 125 |
| 125 // Creates one list to set. This is needed because user white list update is | 126 // Creates one list to set. This is needed because user white list update is |
| 126 // asynchronous and sequential. Before previous write comes back, cached list | 127 // asynchronous and sequential. Before previous write comes back, cached list |
| 127 // is stale and should not be used for appending. See http://crbug.com/127215 | 128 // is stale and should not be used for appending. See http://crbug.com/127215 |
| 128 scoped_ptr<base::ListValue> new_list; | 129 scoped_ptr<base::ListValue> new_list; |
| 129 | 130 |
| 130 CrosSettings* cros_settings = CrosSettings::Get(); | 131 CrosSettings* cros_settings = CrosSettings::Get(); |
| 131 const base::ListValue* existing = NULL; | 132 const base::ListValue* existing = NULL; |
| 132 if (cros_settings->GetList(kAccountsPrefUsers, &existing) && existing) | 133 if (cros_settings->GetList(kAccountsPrefUsers, &existing) && existing) |
| 133 new_list.reset(existing->DeepCopy()); | 134 new_list.reset(existing->DeepCopy()); |
| 134 else | 135 else |
| 135 new_list.reset(new base::ListValue); | 136 new_list.reset(new base::ListValue); |
| 136 | 137 |
| 137 const user_manager::UserList& users = UserManager::Get()->GetUsers(); | 138 const user_manager::UserList& users = |
| 139 user_manager::UserManager::Get()->GetUsers(); |
| 138 for (user_manager::UserList::const_iterator it = users.begin(); | 140 for (user_manager::UserList::const_iterator it = users.begin(); |
| 139 it < users.end(); | 141 it < users.end(); |
| 140 ++it) | 142 ++it) |
| 141 new_list->AppendIfNotPresent(new base::StringValue((*it)->email())); | 143 new_list->AppendIfNotPresent(new base::StringValue((*it)->email())); |
| 142 | 144 |
| 143 cros_settings->Set(kAccountsPrefUsers, *new_list.get()); | 145 cros_settings->Set(kAccountsPrefUsers, *new_list.get()); |
| 144 } | 146 } |
| 145 | 147 |
| 146 } // namespace options | 148 } // namespace options |
| 147 } // namespace chromeos | 149 } // namespace chromeos |
| OLD | NEW |