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/policy/browser_policy_connector_chromeos.h" | 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 18 #include "chrome/browser/chromeos/settings/cros_settings.h" |
19 #include "chrome/browser/profiles/profile.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 "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 22 #include "chromeos/login/user_names.h" |
22 #include "chromeos/settings/cros_settings_names.h" | 23 #include "chromeos/settings/cros_settings_names.h" |
23 #include "components/user_manager/user_manager.h" | 24 #include "components/user_manager/user_manager.h" |
24 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
25 #include "google_apis/gaia/gaia_auth_util.h" | 26 #include "google_apis/gaia/gaia_auth_util.h" |
26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
27 | 28 |
28 namespace chromeos { | 29 namespace chromeos { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
(...skipping 18 matching lines...) Expand all Loading... |
50 AccountsOptionsHandler::~AccountsOptionsHandler() { | 51 AccountsOptionsHandler::~AccountsOptionsHandler() { |
51 } | 52 } |
52 | 53 |
53 void AccountsOptionsHandler::RegisterMessages() { | 54 void AccountsOptionsHandler::RegisterMessages() { |
54 web_ui()->RegisterMessageCallback("whitelistUser", | 55 web_ui()->RegisterMessageCallback("whitelistUser", |
55 base::Bind(&AccountsOptionsHandler::HandleWhitelistUser, | 56 base::Bind(&AccountsOptionsHandler::HandleWhitelistUser, |
56 base::Unretained(this))); | 57 base::Unretained(this))); |
57 web_ui()->RegisterMessageCallback("unwhitelistUser", | 58 web_ui()->RegisterMessageCallback("unwhitelistUser", |
58 base::Bind(&AccountsOptionsHandler::HandleUnwhitelistUser, | 59 base::Bind(&AccountsOptionsHandler::HandleUnwhitelistUser, |
59 base::Unretained(this))); | 60 base::Unretained(this))); |
60 web_ui()->RegisterMessageCallback("whitelistExistingUsers", | 61 web_ui()->RegisterMessageCallback("updateWhitelist", |
61 base::Bind(&AccountsOptionsHandler::HandleWhitelistExistingUsers, | 62 base::Bind(&AccountsOptionsHandler::HandleUpdateWhitelist, |
62 base::Unretained(this))); | 63 base::Unretained(this))); |
63 } | 64 } |
64 | 65 |
65 void AccountsOptionsHandler::GetLocalizedValues( | 66 void AccountsOptionsHandler::GetLocalizedValues( |
66 base::DictionaryValue* localized_strings) { | 67 base::DictionaryValue* localized_strings) { |
67 DCHECK(localized_strings); | 68 DCHECK(localized_strings); |
68 | 69 |
69 RegisterTitle(localized_strings, "accountsPage", | 70 RegisterTitle(localized_strings, "accountsPage", |
70 IDS_OPTIONS_ACCOUNTS_TAB_LABEL); | 71 IDS_OPTIONS_ACCOUNTS_TAB_LABEL); |
71 | 72 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 std::string email; | 113 std::string email; |
113 if (!args->GetString(0, &email)) { | 114 if (!args->GetString(0, &email)) { |
114 return; | 115 return; |
115 } | 116 } |
116 | 117 |
117 base::StringValue canonical_email(gaia::CanonicalizeEmail(email)); | 118 base::StringValue canonical_email(gaia::CanonicalizeEmail(email)); |
118 CrosSettings::Get()->RemoveFromList(kAccountsPrefUsers, &canonical_email); | 119 CrosSettings::Get()->RemoveFromList(kAccountsPrefUsers, &canonical_email); |
119 user_manager::UserManager::Get()->RemoveUser(email, NULL); | 120 user_manager::UserManager::Get()->RemoveUser(email, NULL); |
120 } | 121 } |
121 | 122 |
122 void AccountsOptionsHandler::HandleWhitelistExistingUsers( | 123 void AccountsOptionsHandler::HandleUpdateWhitelist( |
123 const base::ListValue* args) { | 124 const base::ListValue* args) { |
124 DCHECK(args && args->empty()); | 125 DCHECK(args && args->empty()); |
125 | 126 |
126 // Creates one list to set. This is needed because user white list update is | 127 // Creates one list to set. This is needed because user white list update is |
127 // asynchronous and sequential. Before previous write comes back, cached list | 128 // asynchronous and sequential. Before previous write comes back, cached list |
128 // is stale and should not be used for appending. See http://crbug.com/127215 | 129 // is stale and should not be used for appending. See http://crbug.com/127215 |
129 scoped_ptr<base::ListValue> new_list; | 130 scoped_ptr<base::ListValue> new_list; |
130 | 131 |
131 CrosSettings* cros_settings = CrosSettings::Get(); | 132 CrosSettings* cros_settings = CrosSettings::Get(); |
132 const base::ListValue* existing = NULL; | 133 const base::ListValue* existing = NULL; |
133 if (cros_settings->GetList(kAccountsPrefUsers, &existing) && existing) | 134 if (cros_settings->GetList(kAccountsPrefUsers, &existing) && existing) |
134 new_list.reset(existing->DeepCopy()); | 135 new_list.reset(existing->DeepCopy()); |
135 else | 136 else |
136 new_list.reset(new base::ListValue); | 137 new_list.reset(new base::ListValue); |
137 | 138 |
| 139 // Remove all supervised users. On the next step only supervised users present |
| 140 // on the device will be added back. Thus not present SU are removed. |
| 141 // No need to remove usual users as they can simply login back. |
| 142 for (size_t i = 0; i < new_list->GetSize(); ++i) { |
| 143 std::string whitelisted_user; |
| 144 new_list->GetString(i, &whitelisted_user); |
| 145 LOG(ERROR) << gaia::ExtractDomainName(whitelisted_user); |
| 146 if (gaia::ExtractDomainName(whitelisted_user) == |
| 147 chromeos::login::kSupervisedUserDomain) { |
| 148 new_list->Remove(i, NULL); |
| 149 --i; |
| 150 } |
| 151 } |
| 152 |
138 const user_manager::UserList& users = | 153 const user_manager::UserList& users = |
139 user_manager::UserManager::Get()->GetUsers(); | 154 user_manager::UserManager::Get()->GetUsers(); |
140 for (user_manager::UserList::const_iterator it = users.begin(); | 155 for (user_manager::UserList::const_iterator it = users.begin(); |
141 it < users.end(); | 156 it < users.end(); |
142 ++it) | 157 ++it) |
143 new_list->AppendIfNotPresent(new base::StringValue((*it)->email())); | 158 new_list->AppendIfNotPresent(new base::StringValue((*it)->email())); |
144 | 159 |
145 cros_settings->Set(kAccountsPrefUsers, *new_list.get()); | 160 cros_settings->Set(kAccountsPrefUsers, *new_list.get()); |
146 } | 161 } |
147 | 162 |
148 } // namespace options | 163 } // namespace options |
149 } // namespace chromeos | 164 } // namespace chromeos |
OLD | NEW |