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

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

Issue 384023002: Rename "managed (mode|user)" to "supervised user" (part 6) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: break long lines Created 6 years, 5 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/managed_user_import_handler.h" 5 #include "chrome/browser/ui/webui/options/supervised_user_import_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 14 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
15 #include "chrome/browser/profiles/profile_info_cache.h" 15 #include "chrome/browser/profiles/profile_info_cache.h"
(...skipping 24 matching lines...) Expand all
40 avatar_icons->Append(new base::StringValue(avatar_url)); 40 avatar_icons->Append(new base::StringValue(avatar_url));
41 } 41 }
42 42
43 return avatar_icons.Pass(); 43 return avatar_icons.Pass();
44 } 44 }
45 45
46 } // namespace 46 } // namespace
47 47
48 namespace options { 48 namespace options {
49 49
50 ManagedUserImportHandler::ManagedUserImportHandler() 50 SupervisedUserImportHandler::SupervisedUserImportHandler()
51 : observer_(this), 51 : observer_(this),
52 weak_ptr_factory_(this) {} 52 weak_ptr_factory_(this) {}
53 53
54 ManagedUserImportHandler::~ManagedUserImportHandler() { 54 SupervisedUserImportHandler::~SupervisedUserImportHandler() {
55 Profile* profile = Profile::FromWebUI(web_ui()); 55 Profile* profile = Profile::FromWebUI(web_ui());
56 if (!profile->IsSupervised()) { 56 if (!profile->IsSupervised()) {
57 SupervisedUserSyncService* service = 57 SupervisedUserSyncService* service =
58 SupervisedUserSyncServiceFactory::GetForProfile(profile); 58 SupervisedUserSyncServiceFactory::GetForProfile(profile);
59 if (service) 59 if (service)
60 service->RemoveObserver(this); 60 service->RemoveObserver(this);
61 subscription_.reset(); 61 subscription_.reset();
62 } 62 }
63 } 63 }
64 64
65 void ManagedUserImportHandler::GetLocalizedValues( 65 void SupervisedUserImportHandler::GetLocalizedValues(
66 base::DictionaryValue* localized_strings) { 66 base::DictionaryValue* localized_strings) {
67 DCHECK(localized_strings); 67 DCHECK(localized_strings);
68 68
69 static OptionsStringResource resources[] = { 69 static OptionsStringResource resources[] = {
70 { "managedUserImportTitle", IDS_IMPORT_EXISTING_SUPERVISED_USER_TITLE }, 70 { "managedUserImportTitle", IDS_IMPORT_EXISTING_SUPERVISED_USER_TITLE },
71 { "managedUserImportText", IDS_IMPORT_EXISTING_SUPERVISED_USER_TEXT }, 71 { "managedUserImportText", IDS_IMPORT_EXISTING_SUPERVISED_USER_TEXT },
72 { "createNewUserLink", IDS_CREATE_NEW_USER_LINK }, 72 { "createNewUserLink", IDS_CREATE_NEW_USER_LINK },
73 { "managedUserImportOk", IDS_IMPORT_EXISTING_SUPERVISED_USER_OK }, 73 { "managedUserImportOk", IDS_IMPORT_EXISTING_SUPERVISED_USER_OK },
74 { "managedUserImportSigninError", 74 { "managedUserImportSigninError",
75 IDS_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR }, 75 IDS_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR },
76 { "managedUserAlreadyOnThisDevice", 76 { "managedUserAlreadyOnThisDevice",
77 IDS_SUPERVISED_USER_ALREADY_ON_THIS_DEVICE }, 77 IDS_SUPERVISED_USER_ALREADY_ON_THIS_DEVICE },
78 { "noExistingManagedUsers", IDS_SUPERVISED_USER_NO_EXISTING_ERROR }, 78 { "noExistingManagedUsers", IDS_SUPERVISED_USER_NO_EXISTING_ERROR },
79 { "managedUserSelectAvatarTitle", 79 { "managedUserSelectAvatarTitle",
80 IDS_SUPERVISED_USER_SELECT_AVATAR_TITLE }, 80 IDS_SUPERVISED_USER_SELECT_AVATAR_TITLE },
81 { "managedUserSelectAvatarText", IDS_SUPERVISED_USER_SELECT_AVATAR_TEXT }, 81 { "managedUserSelectAvatarText", IDS_SUPERVISED_USER_SELECT_AVATAR_TEXT },
82 { "managedUserSelectAvatarOk", IDS_SUPERVISED_USER_SELECT_AVATAR_OK }, 82 { "managedUserSelectAvatarOk", IDS_SUPERVISED_USER_SELECT_AVATAR_OK },
83 }; 83 };
84 84
85 RegisterStrings(localized_strings, resources, arraysize(resources)); 85 RegisterStrings(localized_strings, resources, arraysize(resources));
86 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); 86 localized_strings->Set("avatarIcons", GetAvatarIcons().release());
87 } 87 }
88 88
89 void ManagedUserImportHandler::InitializeHandler() { 89 void SupervisedUserImportHandler::InitializeHandler() {
90 Profile* profile = Profile::FromWebUI(web_ui()); 90 Profile* profile = Profile::FromWebUI(web_ui());
91 if (!profile->IsSupervised()) { 91 if (!profile->IsSupervised()) {
92 SupervisedUserSyncService* sync_service = 92 SupervisedUserSyncService* sync_service =
93 SupervisedUserSyncServiceFactory::GetForProfile(profile); 93 SupervisedUserSyncServiceFactory::GetForProfile(profile);
94 if (sync_service) { 94 if (sync_service) {
95 sync_service->AddObserver(this); 95 sync_service->AddObserver(this);
96 observer_.Add(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> 96 observer_.Add(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->
97 signin_error_controller()); 97 signin_error_controller());
98 SupervisedUserSharedSettingsService* settings_service = 98 SupervisedUserSharedSettingsService* settings_service =
99 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( 99 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
100 profile); 100 profile);
101 subscription_ = settings_service->Subscribe( 101 subscription_ = settings_service->Subscribe(
102 base::Bind(&ManagedUserImportHandler::OnSharedSettingChanged, 102 base::Bind(&SupervisedUserImportHandler::OnSharedSettingChanged,
103 weak_ptr_factory_.GetWeakPtr())); 103 weak_ptr_factory_.GetWeakPtr()));
104 } else { 104 } else {
105 DCHECK(!SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( 105 DCHECK(!SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
106 profile)); 106 profile));
107 DCHECK(!ProfileOAuth2TokenServiceFactory::GetForProfile(profile)); 107 DCHECK(!ProfileOAuth2TokenServiceFactory::GetForProfile(profile));
108 } 108 }
109 } 109 }
110 } 110 }
111 111
112 void ManagedUserImportHandler::RegisterMessages() { 112 void SupervisedUserImportHandler::RegisterMessages() {
113 web_ui()->RegisterMessageCallback("requestManagedUserImportUpdate", 113 web_ui()->RegisterMessageCallback("requestManagedUserImportUpdate",
114 base::Bind(&ManagedUserImportHandler::RequestManagedUserImportUpdate, 114 base::Bind(&SupervisedUserImportHandler::
115 RequestSupervisedUserImportUpdate,
115 base::Unretained(this))); 116 base::Unretained(this)));
116 } 117 }
117 118
118 void ManagedUserImportHandler::OnSupervisedUsersChanged() { 119 void SupervisedUserImportHandler::OnSupervisedUsersChanged() {
119 FetchManagedUsers(); 120 FetchSupervisedUsers();
120 } 121 }
121 122
122 void ManagedUserImportHandler::FetchManagedUsers() { 123 void SupervisedUserImportHandler::FetchSupervisedUsers() {
123 web_ui()->CallJavascriptFunction("options.ManagedUserListData.resetPromise"); 124 web_ui()->CallJavascriptFunction("options.ManagedUserListData.resetPromise");
124 RequestManagedUserImportUpdate(NULL); 125 RequestSupervisedUserImportUpdate(NULL);
125 } 126 }
126 127
127 void ManagedUserImportHandler::RequestManagedUserImportUpdate( 128 void SupervisedUserImportHandler::RequestSupervisedUserImportUpdate(
128 const base::ListValue* /* args */) { 129 const base::ListValue* /* args */) {
129 if (Profile::FromWebUI(web_ui())->IsSupervised()) 130 if (Profile::FromWebUI(web_ui())->IsSupervised())
130 return; 131 return;
131 132
132 if (!IsAccountConnected() || HasAuthError()) { 133 if (!IsAccountConnected() || HasAuthError()) {
133 ClearManagedUsersAndShowError(); 134 ClearSupervisedUsersAndShowError();
134 } else { 135 } else {
135 SupervisedUserSyncService* supervised_user_sync_service = 136 SupervisedUserSyncService* supervised_user_sync_service =
136 SupervisedUserSyncServiceFactory::GetForProfile( 137 SupervisedUserSyncServiceFactory::GetForProfile(
137 Profile::FromWebUI(web_ui())); 138 Profile::FromWebUI(web_ui()));
138 if (supervised_user_sync_service) { 139 if (supervised_user_sync_service) {
139 supervised_user_sync_service->GetSupervisedUsersAsync( 140 supervised_user_sync_service->GetSupervisedUsersAsync(
140 base::Bind(&ManagedUserImportHandler::SendExistingManagedUsers, 141 base::Bind(&SupervisedUserImportHandler::SendExistingSupervisedUsers,
141 weak_ptr_factory_.GetWeakPtr())); 142 weak_ptr_factory_.GetWeakPtr()));
142 } 143 }
143 } 144 }
144 } 145 }
145 146
146 void ManagedUserImportHandler::SendExistingManagedUsers( 147 void SupervisedUserImportHandler::SendExistingSupervisedUsers(
147 const base::DictionaryValue* dict) { 148 const base::DictionaryValue* dict) {
148 DCHECK(dict); 149 DCHECK(dict);
149 const ProfileInfoCache& cache = 150 const ProfileInfoCache& cache =
150 g_browser_process->profile_manager()->GetProfileInfoCache(); 151 g_browser_process->profile_manager()->GetProfileInfoCache();
151 152
152 // Collect the ids of local supervised user profiles. 153 // Collect the ids of local supervised user profiles.
153 std::set<std::string> supervised_user_ids; 154 std::set<std::string> supervised_user_ids;
154 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { 155 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
155 if (cache.ProfileIsSupervisedAtIndex(i)) 156 if (cache.ProfileIsSupervisedAtIndex(i))
156 supervised_user_ids.insert(cache.GetSupervisedUserIdOfProfileAtIndex(i)); 157 supervised_user_ids.insert(cache.GetSupervisedUserIdOfProfileAtIndex(i));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 supervised_user->SetBoolean("onCurrentDevice", on_current_device); 202 supervised_user->SetBoolean("onCurrentDevice", on_current_device);
202 203
203 supervised_users.Append(supervised_user); 204 supervised_users.Append(supervised_user);
204 } 205 }
205 206
206 web_ui()->CallJavascriptFunction( 207 web_ui()->CallJavascriptFunction(
207 "options.ManagedUserListData.receiveExistingManagedUsers", 208 "options.ManagedUserListData.receiveExistingManagedUsers",
208 supervised_users); 209 supervised_users);
209 } 210 }
210 211
211 void ManagedUserImportHandler::ClearManagedUsersAndShowError() { 212 void SupervisedUserImportHandler::ClearSupervisedUsersAndShowError() {
212 web_ui()->CallJavascriptFunction("options.ManagedUserListData.onSigninError"); 213 web_ui()->CallJavascriptFunction("options.ManagedUserListData.onSigninError");
213 } 214 }
214 215
215 bool ManagedUserImportHandler::IsAccountConnected() const { 216 bool SupervisedUserImportHandler::IsAccountConnected() const {
216 Profile* profile = Profile::FromWebUI(web_ui()); 217 Profile* profile = Profile::FromWebUI(web_ui());
217 SigninManagerBase* signin_manager = 218 SigninManagerBase* signin_manager =
218 SigninManagerFactory::GetForProfile(profile); 219 SigninManagerFactory::GetForProfile(profile);
219 return signin_manager && !signin_manager->GetAuthenticatedUsername().empty(); 220 return signin_manager && !signin_manager->GetAuthenticatedUsername().empty();
220 } 221 }
221 222
222 bool ManagedUserImportHandler::HasAuthError() const { 223 bool SupervisedUserImportHandler::HasAuthError() const {
223 Profile* profile = Profile::FromWebUI(web_ui()); 224 Profile* profile = Profile::FromWebUI(web_ui());
224 ProfileOAuth2TokenService* token_service = 225 ProfileOAuth2TokenService* token_service =
225 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 226 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
226 if (!token_service) 227 if (!token_service)
227 return true; 228 return true;
228 229
229 SigninErrorController* error_controller = 230 SigninErrorController* error_controller =
230 token_service->signin_error_controller(); 231 token_service->signin_error_controller();
231 232
232 GoogleServiceAuthError::State state = error_controller->auth_error().state(); 233 GoogleServiceAuthError::State state = error_controller->auth_error().state();
233 234
234 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || 235 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS ||
235 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || 236 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP ||
236 state == GoogleServiceAuthError::ACCOUNT_DELETED || 237 state == GoogleServiceAuthError::ACCOUNT_DELETED ||
237 state == GoogleServiceAuthError::ACCOUNT_DISABLED; 238 state == GoogleServiceAuthError::ACCOUNT_DISABLED;
238 } 239 }
239 240
240 void ManagedUserImportHandler::OnSharedSettingChanged( 241 void SupervisedUserImportHandler::OnSharedSettingChanged(
241 const std::string& supervised_user_id, 242 const std::string& supervised_user_id,
242 const std::string& key) { 243 const std::string& key) {
243 if (key == supervised_users::kChromeAvatarIndex) 244 if (key == supervised_users::kChromeAvatarIndex)
244 FetchManagedUsers(); 245 FetchSupervisedUsers();
245 } 246 }
246 247
247 void ManagedUserImportHandler::OnErrorChanged() { 248 void SupervisedUserImportHandler::OnErrorChanged() {
248 FetchManagedUsers(); 249 FetchSupervisedUsers();
249 } 250 }
250 251
251 } // namespace options 252 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698