Chromium Code Reviews| 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 |
| 29 | |
|
Nikita (slow)
2014/10/16 17:36:51
nit: drop this line
merkulova
2014/10/17 07:56:08
Done.
| |
| 28 namespace chromeos { | 30 namespace chromeos { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Adds specified user to the whitelist. Returns false if that user is already | 34 // Adds specified user to the whitelist. Returns false if that user is already |
| 33 // in the whitelist. | 35 // in the whitelist. |
| 34 bool WhitelistUser(const std::string& username) { | 36 bool WhitelistUser(const std::string& username) { |
| 35 CrosSettings* cros_settings = CrosSettings::Get(); | 37 CrosSettings* cros_settings = CrosSettings::Get(); |
| 36 if (cros_settings->FindEmailInList(kAccountsPrefUsers, username, NULL)) | 38 if (cros_settings->FindEmailInList(kAccountsPrefUsers, username, NULL)) |
| 37 return false; | 39 return false; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 50 AccountsOptionsHandler::~AccountsOptionsHandler() { | 52 AccountsOptionsHandler::~AccountsOptionsHandler() { |
| 51 } | 53 } |
| 52 | 54 |
| 53 void AccountsOptionsHandler::RegisterMessages() { | 55 void AccountsOptionsHandler::RegisterMessages() { |
| 54 web_ui()->RegisterMessageCallback("whitelistUser", | 56 web_ui()->RegisterMessageCallback("whitelistUser", |
| 55 base::Bind(&AccountsOptionsHandler::HandleWhitelistUser, | 57 base::Bind(&AccountsOptionsHandler::HandleWhitelistUser, |
| 56 base::Unretained(this))); | 58 base::Unretained(this))); |
| 57 web_ui()->RegisterMessageCallback("unwhitelistUser", | 59 web_ui()->RegisterMessageCallback("unwhitelistUser", |
| 58 base::Bind(&AccountsOptionsHandler::HandleUnwhitelistUser, | 60 base::Bind(&AccountsOptionsHandler::HandleUnwhitelistUser, |
| 59 base::Unretained(this))); | 61 base::Unretained(this))); |
| 60 web_ui()->RegisterMessageCallback("whitelistExistingUsers", | 62 web_ui()->RegisterMessageCallback("updateWhitelist", |
| 61 base::Bind(&AccountsOptionsHandler::HandleWhitelistExistingUsers, | 63 base::Bind(&AccountsOptionsHandler::HandleUpdateWhitelist, |
| 62 base::Unretained(this))); | 64 base::Unretained(this))); |
| 63 } | 65 } |
| 64 | 66 |
| 65 void AccountsOptionsHandler::GetLocalizedValues( | 67 void AccountsOptionsHandler::GetLocalizedValues( |
| 66 base::DictionaryValue* localized_strings) { | 68 base::DictionaryValue* localized_strings) { |
| 67 DCHECK(localized_strings); | 69 DCHECK(localized_strings); |
| 68 | 70 |
| 69 RegisterTitle(localized_strings, "accountsPage", | 71 RegisterTitle(localized_strings, "accountsPage", |
| 70 IDS_OPTIONS_ACCOUNTS_TAB_LABEL); | 72 IDS_OPTIONS_ACCOUNTS_TAB_LABEL); |
| 71 | 73 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 std::string email; | 114 std::string email; |
| 113 if (!args->GetString(0, &email)) { | 115 if (!args->GetString(0, &email)) { |
| 114 return; | 116 return; |
| 115 } | 117 } |
| 116 | 118 |
| 117 base::StringValue canonical_email(gaia::CanonicalizeEmail(email)); | 119 base::StringValue canonical_email(gaia::CanonicalizeEmail(email)); |
| 118 CrosSettings::Get()->RemoveFromList(kAccountsPrefUsers, &canonical_email); | 120 CrosSettings::Get()->RemoveFromList(kAccountsPrefUsers, &canonical_email); |
| 119 user_manager::UserManager::Get()->RemoveUser(email, NULL); | 121 user_manager::UserManager::Get()->RemoveUser(email, NULL); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void AccountsOptionsHandler::HandleWhitelistExistingUsers( | 124 void AccountsOptionsHandler::HandleUpdateWhitelist( |
| 123 const base::ListValue* args) { | 125 const base::ListValue* args) { |
| 124 DCHECK(args && args->empty()); | |
|
Nikita (slow)
2014/10/16 17:36:51
I think this DCHECK should stay since argument lis
merkulova
2014/10/17 07:56:08
Done.
| |
| 125 | |
| 126 // 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 |
| 127 // asynchronous and sequential. Before previous write comes back, cached list | 127 // 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 | 128 // is stale and should not be used for appending. See http://crbug.com/127215 |
| 129 scoped_ptr<base::ListValue> new_list; | 129 scoped_ptr<base::ListValue> new_list; |
| 130 | 130 |
| 131 CrosSettings* cros_settings = CrosSettings::Get(); | 131 CrosSettings* cros_settings = CrosSettings::Get(); |
| 132 const base::ListValue* existing = NULL; | 132 const base::ListValue* existing = NULL; |
| 133 if (cros_settings->GetList(kAccountsPrefUsers, &existing) && existing) | 133 if (cros_settings->GetList(kAccountsPrefUsers, &existing) && existing) |
| 134 new_list.reset(existing->DeepCopy()); | 134 new_list.reset(existing->DeepCopy()); |
| 135 else | 135 else |
| 136 new_list.reset(new base::ListValue); | 136 new_list.reset(new base::ListValue); |
| 137 | 137 |
| 138 // Remove supervised users if they're not present on the device; | |
|
Nikita (slow)
2014/10/16 17:36:51
Not clear from the code where exactly do you check
merkulova
2014/10/17 07:56:08
Done.
Nikita (slow)
2014/10/17 11:05:11
Still it's not quite clear why supervised users ne
| |
| 139 for (size_t i = 0; i < new_list->GetSize(); ++i) { | |
| 140 std::string whitelisted_user; | |
| 141 new_list->GetString(i, &whitelisted_user); | |
| 142 LOG(ERROR) << gaia::ExtractDomainName(whitelisted_user); | |
| 143 if (gaia::ExtractDomainName(whitelisted_user) == | |
| 144 chromeos::login::kSupervisedUserDomain) { | |
| 145 new_list->Remove(i, NULL); | |
| 146 --i; | |
| 147 } | |
| 148 } | |
| 149 | |
| 138 const user_manager::UserList& users = | 150 const user_manager::UserList& users = |
| 139 user_manager::UserManager::Get()->GetUsers(); | 151 user_manager::UserManager::Get()->GetUsers(); |
| 140 for (user_manager::UserList::const_iterator it = users.begin(); | 152 for (user_manager::UserList::const_iterator it = users.begin(); |
| 141 it < users.end(); | 153 it < users.end(); |
| 142 ++it) | 154 ++it) |
| 143 new_list->AppendIfNotPresent(new base::StringValue((*it)->email())); | 155 new_list->AppendIfNotPresent(new base::StringValue((*it)->email())); |
| 144 | 156 |
| 145 cros_settings->Set(kAccountsPrefUsers, *new_list.get()); | 157 cros_settings->Set(kAccountsPrefUsers, *new_list.get()); |
| 146 } | 158 } |
| 147 | 159 |
| 148 } // namespace options | 160 } // namespace options |
| 149 } // namespace chromeos | 161 } // namespace chromeos |
| OLD | NEW |