Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(798)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/accounts_options_handler.cc

Issue 7867044: PART1: Initiated the SignedSettings refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final rebase to ToT before hitting the CQ. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/cros_settings.h"
14 #include "chrome/browser/chromeos/cros_settings_names.h" 15 #include "chrome/browser/chromeos/cros_settings_names.h"
15 #include "chrome/browser/chromeos/login/authenticator.h" 16 #include "chrome/browser/chromeos/login/authenticator.h"
16 #include "chrome/browser/chromeos/login/user_manager.h" 17 #include "chrome/browser/chromeos/login/user_manager.h"
17 #include "chrome/browser/chromeos/user_cros_settings_provider.h" 18 #include "chrome/browser/chromeos/user_cros_settings_provider.h"
18 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/policy/browser_policy_connector.h" 20 #include "chrome/browser/policy/browser_policy_connector.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 23
23 namespace chromeos { 24 namespace chromeos {
24 25
25 AccountsOptionsHandler::AccountsOptionsHandler() 26 AccountsOptionsHandler::AccountsOptionsHandler() {
26 : CrosOptionsPageUIHandler(new UserCrosSettingsProvider) {
27 } 27 }
28 28
29 AccountsOptionsHandler::~AccountsOptionsHandler() { 29 AccountsOptionsHandler::~AccountsOptionsHandler() {
30 } 30 }
31 31
32 void AccountsOptionsHandler::RegisterMessages() { 32 void AccountsOptionsHandler::RegisterMessages() {
33 DCHECK(web_ui_); 33 DCHECK(web_ui_);
34 web_ui_->RegisterMessageCallback("whitelistUser", 34 web_ui_->RegisterMessageCallback("whitelistUser",
35 base::Bind(&AccountsOptionsHandler::WhitelistUser, 35 base::Bind(&AccountsOptionsHandler::WhitelistUser,
36 base::Unretained(this))); 36 base::Unretained(this)));
37 web_ui_->RegisterMessageCallback("unwhitelistUser", 37 web_ui_->RegisterMessageCallback("unwhitelistUser",
38 base::Bind(&AccountsOptionsHandler::UnwhitelistUser, 38 base::Bind(&AccountsOptionsHandler::UnwhitelistUser,
39 base::Unretained(this))); 39 base::Unretained(this)));
40 web_ui_->RegisterMessageCallback("whitelistExistingUsers", 40 web_ui_->RegisterMessageCallback("whitelistExistingUsers",
41 base::Bind(&AccountsOptionsHandler::WhitelistExistingUsers, 41 base::Bind(&AccountsOptionsHandler::WhitelistExistingUsers,
42 base::Unretained(this))); 42 base::Unretained(this)));
43 } 43 }
44 44
45 void AccountsOptionsHandler::GetLocalizedValues( 45 void AccountsOptionsHandler::GetLocalizedValues(
46 DictionaryValue* localized_strings) { 46 base::DictionaryValue* localized_strings) {
47 DCHECK(localized_strings); 47 DCHECK(localized_strings);
48 48
49 RegisterTitle(localized_strings, "accountsPage", 49 RegisterTitle(localized_strings, "accountsPage",
50 IDS_OPTIONS_ACCOUNTS_TAB_LABEL); 50 IDS_OPTIONS_ACCOUNTS_TAB_LABEL);
51 51
52 localized_strings->SetString("allow_BWSI", l10n_util::GetStringUTF16( 52 localized_strings->SetString("allow_BWSI", l10n_util::GetStringUTF16(
53 IDS_OPTIONS_ACCOUNTS_ALLOW_BWSI_DESCRIPTION)); 53 IDS_OPTIONS_ACCOUNTS_ALLOW_BWSI_DESCRIPTION));
54 localized_strings->SetString("use_whitelist",l10n_util::GetStringUTF16( 54 localized_strings->SetString("use_whitelist",l10n_util::GetStringUTF16(
55 IDS_OPTIONS_ACCOUNTS_USE_WHITELIST_DESCRIPTION)); 55 IDS_OPTIONS_ACCOUNTS_USE_WHITELIST_DESCRIPTION));
56 localized_strings->SetString("show_user_on_signin",l10n_util::GetStringUTF16( 56 localized_strings->SetString("show_user_on_signin",l10n_util::GetStringUTF16(
57 IDS_OPTIONS_ACCOUNTS_SHOW_USER_NAMES_ON_SINGIN_DESCRIPTION)); 57 IDS_OPTIONS_ACCOUNTS_SHOW_USER_NAMES_ON_SINGIN_DESCRIPTION));
58 localized_strings->SetString("username_edit_hint",l10n_util::GetStringUTF16( 58 localized_strings->SetString("username_edit_hint",l10n_util::GetStringUTF16(
59 IDS_OPTIONS_ACCOUNTS_USERNAME_EDIT_HINT)); 59 IDS_OPTIONS_ACCOUNTS_USERNAME_EDIT_HINT));
60 localized_strings->SetString("username_format",l10n_util::GetStringUTF16( 60 localized_strings->SetString("username_format",l10n_util::GetStringUTF16(
61 IDS_OPTIONS_ACCOUNTS_USERNAME_FORMAT)); 61 IDS_OPTIONS_ACCOUNTS_USERNAME_FORMAT));
62 localized_strings->SetString("add_users",l10n_util::GetStringUTF16( 62 localized_strings->SetString("add_users",l10n_util::GetStringUTF16(
63 IDS_OPTIONS_ACCOUNTS_ADD_USERS)); 63 IDS_OPTIONS_ACCOUNTS_ADD_USERS));
64 localized_strings->SetString("owner_only", l10n_util::GetStringUTF16( 64 localized_strings->SetString("owner_only", l10n_util::GetStringUTF16(
65 IDS_OPTIONS_ACCOUNTS_OWNER_ONLY)); 65 IDS_OPTIONS_ACCOUNTS_OWNER_ONLY));
66 localized_strings->SetString("owner_user_id", UTF8ToUTF16( 66
67 UserCrosSettingsProvider::cached_owner())); 67 std::string owner;
68 CrosSettings::Get()->GetString(kDeviceOwner, &owner);
69 localized_strings->SetString("owner_user_id", UTF8ToUTF16(owner));
68 70
69 localized_strings->SetString("current_user_is_owner", 71 localized_strings->SetString("current_user_is_owner",
70 UserManager::Get()->current_user_is_owner() ? 72 UserManager::Get()->current_user_is_owner() ?
71 ASCIIToUTF16("true") : ASCIIToUTF16("false")); 73 ASCIIToUTF16("true") : ASCIIToUTF16("false"));
72 localized_strings->SetString("logged_in_as_guest", 74 localized_strings->SetString("logged_in_as_guest",
73 UserManager::Get()->IsLoggedInAsGuest() ? 75 UserManager::Get()->IsLoggedInAsGuest() ?
74 ASCIIToUTF16("true") : ASCIIToUTF16("false")); 76 ASCIIToUTF16("true") : ASCIIToUTF16("false"));
75 localized_strings->SetString("whitelist_is_managed", 77 localized_strings->SetString("whitelist_is_managed",
76 g_browser_process->browser_policy_connector()->IsEnterpriseManaged() ? 78 g_browser_process->browser_policy_connector()->IsEnterpriseManaged() ?
77 ASCIIToUTF16("true") : ASCIIToUTF16("false")); 79 ASCIIToUTF16("true") : ASCIIToUTF16("false"));
78 } 80 }
79 81
80 UserCrosSettingsProvider* AccountsOptionsHandler::users_settings() const { 82 void AccountsOptionsHandler::WhitelistUser(const base::ListValue* args) {
81 return static_cast<UserCrosSettingsProvider*>(settings_provider_.get());
82 }
83
84 void AccountsOptionsHandler::WhitelistUser(const ListValue* args) {
85 std::string email; 83 std::string email;
86 if (!args->GetString(0, &email)) { 84 if (!args->GetString(0, &email)) {
87 return; 85 return;
88 } 86 }
89 87 // TODO(pastarmovj): Those will change to CrosSettings ops in phase 2.
90 users_settings()->WhitelistUser(Authenticator::Canonicalize(email)); 88 UserCrosSettingsProvider::WhitelistUser(Authenticator::Canonicalize(email));
91 } 89 }
92 90
93 void AccountsOptionsHandler::UnwhitelistUser(const ListValue* args) { 91 void AccountsOptionsHandler::UnwhitelistUser(const base::ListValue* args) {
94 std::string email; 92 std::string email;
95 if (!args->GetString(0, &email)) { 93 if (!args->GetString(0, &email)) {
96 return; 94 return;
97 } 95 }
98 96 // TODO(pastarmovj): Those will change to CrosSettings ops in phase 2.
99 users_settings()->UnwhitelistUser(Authenticator::Canonicalize(email)); 97 UserCrosSettingsProvider::UnwhitelistUser(Authenticator::Canonicalize(email));
100 UserManager::Get()->RemoveUser(email, NULL); 98 UserManager::Get()->RemoveUser(email, NULL);
101 } 99 }
102 100
103 void AccountsOptionsHandler::WhitelistExistingUsers(const ListValue* args) { 101 void AccountsOptionsHandler::WhitelistExistingUsers(
104 ListValue whitelist_users; 102 const base::ListValue* args) {
105 103 base::ListValue whitelist_users;
104 const base::ListValue *user_list;
105 CrosSettings::Get()->GetList(kAccountsPrefUsers, &user_list);
106 const UserList& users = UserManager::Get()->GetUsers(); 106 const UserList& users = UserManager::Get()->GetUsers();
107 for (UserList::const_iterator it = users.begin(); it < users.end(); ++it) { 107 for (UserList::const_iterator it = users.begin(); it < users.end(); ++it) {
108 const std::string& email = (*it)->email(); 108 const std::string& email = (*it)->email();
109 if (!UserCrosSettingsProvider::IsEmailInCachedWhitelist(email)) { 109 base::StringValue email_value(email);
110 DictionaryValue* user_dict = new DictionaryValue; 110 if (user_list->Find(email_value) == user_list->end()) {
111 base::DictionaryValue* user_dict = new DictionaryValue;
111 user_dict->SetString("name", (*it)->GetDisplayName()); 112 user_dict->SetString("name", (*it)->GetDisplayName());
112 user_dict->SetString("email", email); 113 user_dict->SetString("email", email);
113 user_dict->SetBoolean("owner", false); 114 user_dict->SetBoolean("owner", false);
114 115
115 whitelist_users.Append(user_dict); 116 whitelist_users.Append(user_dict);
116 } 117 }
117 } 118 }
118 119
119 web_ui_->CallJavascriptFunction("AccountsOptions.addUsers", whitelist_users); 120 web_ui_->CallJavascriptFunction("AccountsOptions.addUsers", whitelist_users);
120 } 121 }
121 122
122 } // namespace chromeos 123 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698