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

Side by Side Diff: chrome/browser/ui/webui/signin/signin_create_profile_handler.cc

Issue 1826903002: updated UI, default profile name, check for existing supervised user before create (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/signin/signin_create_profile_handler.h" 5 #include "chrome/browser/ui/webui/signin/signin_create_profile_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/task_runner_util.h" 16 #include "base/task_runner_util.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/value_conversions.h" 18 #include "base/value_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/profiles/profile_attributes_entry.h" 21 #include "chrome/browser/profiles/profile_attributes_entry.h"
22 #include "chrome/browser/profiles/profile_attributes_storage.h" 22 #include "chrome/browser/profiles/profile_attributes_storage.h"
23 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 23 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
24 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/profiles/profile_metrics.h" 25 #include "chrome/browser/profiles/profile_metrics.h"
26 #include "chrome/browser/profiles/profiles_state.h" 26 #include "chrome/browser/profiles/profiles_state.h"
27 #include "chrome/browser/signin/signin_error_controller_factory.h"
27 #include "chrome/browser/signin/signin_manager_factory.h" 28 #include "chrome/browser/signin/signin_manager_factory.h"
28 #include "chrome/browser/sync/profile_sync_service_factory.h" 29 #include "chrome/browser/sync/profile_sync_service_factory.h"
29 #include "chrome/browser/ui/webui/profile_helper.h" 30 #include "chrome/browser/ui/webui/profile_helper.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
32 #include "chrome/grit/generated_resources.h" 33 #include "chrome/grit/generated_resources.h"
33 #include "components/browser_sync/browser/profile_sync_service.h" 34 #include "components/browser_sync/browser/profile_sync_service.h"
34 #include "components/prefs/pref_service.h" 35 #include "components/prefs/pref_service.h"
36 #include "components/signin/core/browser/signin_error_controller.h"
35 #include "components/strings/grit/components_strings.h" 37 #include "components/strings/grit/components_strings.h"
36 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/web_ui.h" 39 #include "content/public/browser/web_ui.h"
38 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
39 41
40 #if defined(ENABLE_SUPERVISED_USERS) 42 #if defined(ENABLE_SUPERVISED_USERS)
41 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti lity.h" 43 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti lity.h"
42 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" 44 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h"
43 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac tory.h" 45 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac tory.h"
44 #include "chrome/browser/supervised_user/supervised_user_service.h" 46 #include "chrome/browser/supervised_user/supervised_user_service.h"
(...skipping 10 matching lines...) Expand all
55 CancelProfileRegistration(false); 57 CancelProfileRegistration(false);
56 #endif 58 #endif
57 } 59 }
58 60
59 void SigninCreateProfileHandler::GetLocalizedValues( 61 void SigninCreateProfileHandler::GetLocalizedValues(
60 base::DictionaryValue* localized_strings) { 62 base::DictionaryValue* localized_strings) {
61 localized_strings->SetString( 63 localized_strings->SetString(
62 "manageProfilesSupervisedSignedInLabel", 64 "manageProfilesSupervisedSignedInLabel",
63 l10n_util::GetStringUTF16( 65 l10n_util::GetStringUTF16(
64 IDS_PROFILES_CREATE_SUPERVISED_MULTI_SIGNED_IN_LABEL)); 66 IDS_PROFILES_CREATE_SUPERVISED_MULTI_SIGNED_IN_LABEL));
65 localized_strings->SetString(
66 "manageProfilesSupervisedNotSignedIn",
67 l10n_util::GetStringUTF16(
68 IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML));
69 localized_strings->SetString("createProfileConfirm", 67 localized_strings->SetString("createProfileConfirm",
70 l10n_util::GetStringUTF16(IDS_SAVE)); 68 l10n_util::GetStringUTF16(IDS_SAVE));
71 localized_strings->SetString("learnMore", 69 localized_strings->SetString("learnMore",
72 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 70 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
73 localized_strings->SetString( 71 localized_strings->SetString(
72 "selectAnAccount",
73 l10n_util::GetStringUTF16(
74 IDS_PROFILES_CREATE_SUPERVISED_SENTINEL_MENU_ITEM_TEXT));
75 localized_strings->SetString(
74 "createProfileTitle", 76 "createProfileTitle",
75 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE)); 77 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE));
76
77 localized_strings->SetString( 78 localized_strings->SetString(
78 "supervisedUserLearnMoreTitle", 79 "supervisedUserLearnMoreTitle",
79 l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE)); 80 l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE));
80 localized_strings->SetString( 81 localized_strings->SetString(
81 "supervisedUserLearnMoreDone", 82 "supervisedUserLearnMoreDone",
82 l10n_util::GetStringUTF16( 83 l10n_util::GetStringUTF16(
83 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON)); 84 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON));
84 localized_strings->SetString( 85 localized_strings->SetString(
85 "supervisedUserLearnMoreText", 86 "supervisedUserLearnMoreText",
86 l10n_util::GetStringFUTF16( 87 l10n_util::GetStringFUTF16(
87 IDS_SUPERVISED_USER_LEARN_MORE_TEXT, 88 IDS_SUPERVISED_USER_LEARN_MORE_TEXT,
88 base::ASCIIToUTF16( 89 base::ASCIIToUTF16(
89 chrome::kLegacySupervisedUserManagementURL), 90 chrome::kLegacySupervisedUserManagementURL),
90 base::ASCIIToUTF16( 91 base::ASCIIToUTF16(
91 chrome::kLegacySupervisedUserManagementDisplayURL))); 92 chrome::kLegacySupervisedUserManagementDisplayURL)));
93 localized_strings->SetString(
94 "manageProfilesExistingSupervisedUser",
95 l10n_util::GetStringUTF16(
96 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_REMOTELY));
97 localized_strings->SetString(
98 "managedProfilesExistingLocalSupervisedUser",
99 l10n_util::GetStringUTF16(
100 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_LOCALLY));
101 localized_strings->SetString(
102 "custodianAccountNotSelectedError",
103 l10n_util::GetStringUTF16(
104 IDS_PROFILES_CREATE_NO_CUSTODIAN_ACCOUNT_ERROR));
92 } 105 }
93 106
94 void SigninCreateProfileHandler::RegisterMessages() { 107 void SigninCreateProfileHandler::RegisterMessages() {
95 #if defined(ENABLE_SUPERVISED_USERS) 108 #if defined(ENABLE_SUPERVISED_USERS)
96 // Cancellation is only supported for supervised users. 109 // Cancellation is only supported for supervised users.
97 web_ui()->RegisterMessageCallback( 110 web_ui()->RegisterMessageCallback(
98 "cancelCreateProfile", 111 "cancelCreateProfile",
99 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation, 112 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation,
100 base::Unretained(this))); 113 base::Unretained(this)));
101 #endif 114 #endif
(...skipping 21 matching lines...) Expand all
123 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && 136 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() &&
124 i != placeholder_avatar_index; 137 i != placeholder_avatar_index;
125 i++) { 138 i++) {
126 std::string url = profiles::GetDefaultAvatarIconUrl(i); 139 std::string url = profiles::GetDefaultAvatarIconUrl(i);
127 image_url_list.AppendString(url); 140 image_url_list.AppendString(url);
128 } 141 }
129 142
130 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 143 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
131 base::StringValue("profile-icons-received"), 144 base::StringValue("profile-icons-received"),
132 image_url_list); 145 image_url_list);
146
147 SendNewProfileDefaults();
148 }
149
150 void SigninCreateProfileHandler::SendNewProfileDefaults() {
151 ProfileInfoCache& cache =
152 g_browser_process->profile_manager()->GetProfileInfoCache();
153 base::DictionaryValue profile_info;
154 profile_info.SetString("name", cache.ChooseNameForNewProfile(0));
155
156 web_ui()->CallJavascriptFunction(
157 "cr.webUIListenerCallback",
158 base::StringValue("profile-defaults-received"),
159 profile_info);
133 } 160 }
134 161
135 void SigninCreateProfileHandler::RequestSignedInProfiles( 162 void SigninCreateProfileHandler::RequestSignedInProfiles(
136 const base::ListValue* args) { 163 const base::ListValue* args) {
137 base::ListValue user_info_list; 164 base::ListValue user_info_list;
138 std::vector<ProfileAttributesEntry*> entries = 165 std::vector<ProfileAttributesEntry*> entries =
139 g_browser_process->profile_manager()-> 166 g_browser_process->profile_manager()->
140 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); 167 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName();
141 for (ProfileAttributesEntry* entry : entries) { 168 for (ProfileAttributesEntry* entry : entries) {
142 base::string16 username = entry->GetUserName(); 169 base::string16 username = entry->GetUserName();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 base::TrimWhitespace(name, base::TRIM_ALL, &name); 204 base::TrimWhitespace(name, base::TRIM_ALL, &name);
178 CHECK(!name.empty()); 205 CHECK(!name.empty());
179 #ifndef NDEBUG 206 #ifndef NDEBUG
180 size_t icon_index; 207 size_t icon_index;
181 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); 208 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index));
182 #endif 209 #endif
183 args->GetBoolean(2, &create_shortcut); 210 args->GetBoolean(2, &create_shortcut);
184 } 211 }
185 #if defined(ENABLE_SUPERVISED_USERS) 212 #if defined(ENABLE_SUPERVISED_USERS)
186 std::string supervised_user_id; 213 std::string supervised_user_id;
187 base::FilePath supervisor_profile_path; 214 base::FilePath custodian_profile_path;
188 if (GetSupervisedCreateProfileArgs(args, &supervised_user_id, 215 if (GetSupervisedCreateProfileArgs(args, &supervised_user_id,
189 &supervisor_profile_path)) { 216 &custodian_profile_path)) {
190 // Load supervisor profile. 217 // Load custodian profile.
191 g_browser_process->profile_manager()->CreateProfileAsync( 218 g_browser_process->profile_manager()->CreateProfileAsync(
192 supervisor_profile_path, 219 custodian_profile_path,
193 base::Bind(&SigninCreateProfileHandler::LoadSupervisorProfileCallback, 220 base::Bind(&SigninCreateProfileHandler::LoadCustodianProfileCallback,
194 weak_ptr_factory_.GetWeakPtr(), name, icon_url, 221 weak_ptr_factory_.GetWeakPtr(), name, icon_url,
195 create_shortcut, supervised_user_id), 222 create_shortcut, supervised_user_id),
196 base::string16(), std::string(), std::string()); 223 base::string16(), std::string(), std::string());
197 } else { 224 } else {
198 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); 225 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr);
199 } 226 }
200 #else 227 #else
201 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); 228 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr);
202 #endif 229 #endif
203 } 230 }
204 231
205 void SigninCreateProfileHandler::DoCreateProfile( 232 void SigninCreateProfileHandler::DoCreateProfile(
206 const base::string16& name, 233 const base::string16& name,
207 const std::string& icon_url, 234 const std::string& icon_url,
208 bool create_shortcut, 235 bool create_shortcut,
209 const std::string& supervised_user_id, 236 const std::string& supervised_user_id,
210 Profile* supervisor_profile) { 237 Profile* custodian_profile) {
211 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); 238 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG);
212 239
213 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( 240 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync(
214 name, icon_url, 241 name, icon_url,
215 base::Bind(&SigninCreateProfileHandler::OnProfileCreated, 242 base::Bind(&SigninCreateProfileHandler::OnProfileCreated,
216 weak_ptr_factory_.GetWeakPtr(), create_shortcut, 243 weak_ptr_factory_.GetWeakPtr(), create_shortcut,
217 supervised_user_id, supervisor_profile), 244 supervised_user_id, custodian_profile),
218 supervised_user_id); 245 supervised_user_id);
219 } 246 }
220 247
221 void SigninCreateProfileHandler::OnProfileCreated( 248 void SigninCreateProfileHandler::OnProfileCreated(
222 bool create_shortcut, 249 bool create_shortcut,
223 const std::string& supervised_user_id, 250 const std::string& supervised_user_id,
224 Profile* supervisor_profile, 251 Profile* custodian_profile,
225 Profile* profile, 252 Profile* profile,
226 Profile::CreateStatus status) { 253 Profile::CreateStatus status) {
227 if (status != Profile::CREATE_STATUS_CREATED) 254 if (status != Profile::CREATE_STATUS_CREATED)
228 RecordProfileCreationMetrics(status); 255 RecordProfileCreationMetrics(status);
229 256
230 switch (status) { 257 switch (status) {
231 case Profile::CREATE_STATUS_LOCAL_FAIL: { 258 case Profile::CREATE_STATUS_LOCAL_FAIL: {
232 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); 259 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal());
233 break; 260 break;
234 } 261 }
235 case Profile::CREATE_STATUS_CREATED: { 262 case Profile::CREATE_STATUS_CREATED: {
236 // Do nothing for an intermediate status. 263 // Do nothing for an intermediate status.
237 break; 264 break;
238 } 265 }
239 case Profile::CREATE_STATUS_INITIALIZED: { 266 case Profile::CREATE_STATUS_INITIALIZED: {
240 HandleProfileCreationSuccess(create_shortcut, supervised_user_id, 267 HandleProfileCreationSuccess(create_shortcut, supervised_user_id,
241 supervisor_profile, profile); 268 custodian_profile, profile);
242 break; 269 break;
243 } 270 }
244 // User-initiated cancellation is handled in CancelProfileRegistration and 271 // User-initiated cancellation is handled in CancelProfileRegistration and
245 // does not call this callback. 272 // does not call this callback.
246 case Profile::CREATE_STATUS_CANCELED: 273 case Profile::CREATE_STATUS_CANCELED:
247 // Supervised user registration errors are handled in 274 // Supervised user registration errors are handled in
248 // OnSupervisedUserRegistered(). 275 // OnSupervisedUserRegistered().
249 case Profile::CREATE_STATUS_REMOTE_FAIL: 276 case Profile::CREATE_STATUS_REMOTE_FAIL:
250 case Profile::MAX_CREATE_STATUS: { 277 case Profile::MAX_CREATE_STATUS: {
251 NOTREACHED(); 278 NOTREACHED();
252 break; 279 break;
253 } 280 }
254 } 281 }
255 } 282 }
256 283
257 void SigninCreateProfileHandler::HandleProfileCreationSuccess( 284 void SigninCreateProfileHandler::HandleProfileCreationSuccess(
258 bool create_shortcut, 285 bool create_shortcut,
259 const std::string& supervised_user_id, 286 const std::string& supervised_user_id,
260 Profile* supervisor_profile, 287 Profile* custodian_profile,
261 Profile* profile) { 288 Profile* profile) {
262 switch (profile_creation_type_) { 289 switch (profile_creation_type_) {
263 case NON_SUPERVISED_PROFILE_CREATION: { 290 case NON_SUPERVISED_PROFILE_CREATION: {
264 DCHECK(supervised_user_id.empty()); 291 DCHECK(supervised_user_id.empty());
265 CreateShortcutAndShowSuccess(create_shortcut, profile); 292 CreateShortcutAndShowSuccess(create_shortcut, profile);
266 break; 293 break;
267 } 294 }
268 #if defined(ENABLE_SUPERVISED_USERS) 295 #if defined(ENABLE_SUPERVISED_USERS)
269 case SUPERVISED_PROFILE_CREATION: 296 case SUPERVISED_PROFILE_CREATION:
270 case SUPERVISED_PROFILE_IMPORT: 297 case SUPERVISED_PROFILE_IMPORT:
271 RegisterSupervisedUser(create_shortcut, supervised_user_id, 298 RegisterSupervisedUser(create_shortcut, supervised_user_id,
272 supervisor_profile, profile); 299 custodian_profile, profile);
273 break; 300 break;
274 #endif 301 #endif
275 case NO_CREATION_IN_PROGRESS: 302 case NO_CREATION_IN_PROGRESS:
276 NOTREACHED(); 303 NOTREACHED();
277 break; 304 break;
278 } 305 }
279 } 306 }
280 307
281 void SigninCreateProfileHandler::CreateShortcutAndShowSuccess( 308 void SigninCreateProfileHandler::CreateShortcutAndShowSuccess(
282 bool create_shortcut, 309 bool create_shortcut,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 webui::OpenNewWindowForProfile( 349 webui::OpenNewWindowForProfile(
323 profile, Profile::CREATE_STATUS_INITIALIZED); 350 profile, Profile::CREATE_STATUS_INITIALIZED);
324 } 351 }
325 profile_creation_type_ = NO_CREATION_IN_PROGRESS; 352 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
326 } 353 }
327 354
328 void SigninCreateProfileHandler::ShowProfileCreationError( 355 void SigninCreateProfileHandler::ShowProfileCreationError(
329 Profile* profile, 356 Profile* profile,
330 const base::string16& error) { 357 const base::string16& error) {
331 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); 358 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
332 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
333 profile_path_being_created_.clear();
334 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 359 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
335 GetWebUIListenerName(PROFILE_CREATION_ERROR), 360 GetWebUIListenerName(PROFILE_CREATION_ERROR),
336 base::StringValue(error)); 361 base::StringValue(error));
337 // The ProfileManager calls us back with a NULL profile in some cases. 362 // The ProfileManager calls us back with a NULL profile in some cases.
338 if (profile) 363 if (profile)
339 webui::DeleteProfileAtPath(profile->GetPath(), web_ui()); 364 webui::DeleteProfileAtPath(profile->GetPath(), web_ui());
365 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
366 profile_path_being_created_.clear();
340 } 367 }
341 368
342 void SigninCreateProfileHandler::RecordProfileCreationMetrics( 369 void SigninCreateProfileHandler::RecordProfileCreationMetrics(
343 Profile::CreateStatus status) { 370 Profile::CreateStatus status) {
344 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, 371 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status,
345 Profile::MAX_CREATE_STATUS); 372 Profile::MAX_CREATE_STATUS);
346 UMA_HISTOGRAM_MEDIUM_TIMES( 373 UMA_HISTOGRAM_MEDIUM_TIMES(
347 "Profile.CreateTimeNoTimeout", 374 "Profile.CreateTimeNoTimeout",
348 base::TimeTicks::Now() - profile_creation_start_time_); 375 base::TimeTicks::Now() - profile_creation_start_time_);
349 } 376 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 428 }
402 429
403 NOTREACHED(); 430 NOTREACHED();
404 return base::StringValue(std::string()); 431 return base::StringValue(std::string());
405 } 432 }
406 433
407 #if defined(ENABLE_SUPERVISED_USERS) 434 #if defined(ENABLE_SUPERVISED_USERS)
408 bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs( 435 bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs(
409 const base::ListValue* args, 436 const base::ListValue* args,
410 std::string* supervised_user_id, 437 std::string* supervised_user_id,
411 base::FilePath* supervisor_profile_path) { 438 base::FilePath* custodian_profile_path) {
412 bool supervised_user = false; 439 bool supervised_user = false;
413 bool success = args->GetBoolean(3, &supervised_user); 440 bool success = args->GetBoolean(3, &supervised_user);
414 DCHECK(success); 441 DCHECK(success);
415 442
416 if (!supervised_user) 443 if (!supervised_user)
417 return false; 444 return false;
418 445
419 success = args->GetString(4, supervised_user_id); 446 success = args->GetString(4, supervised_user_id);
420 DCHECK(success); 447 DCHECK(success);
421 const base::Value* path_value; 448 const base::Value* path_value;
422 success = args->Get(5, &path_value); 449 success = args->Get(5, &path_value);
423 DCHECK(success); 450 DCHECK(success);
424 success = base::GetValueAsFilePath(*path_value, supervisor_profile_path); 451 success = base::GetValueAsFilePath(*path_value, custodian_profile_path);
425 DCHECK(success); 452 DCHECK(success);
426 453
427 return !supervisor_profile_path->empty(); 454 return !custodian_profile_path->empty();
428 } 455 }
429 456
430 void SigninCreateProfileHandler::LoadSupervisorProfileCallback( 457 void SigninCreateProfileHandler::LoadCustodianProfileCallback(
431 const base::string16& name, 458 const base::string16& name,
432 const std::string& icon_url, 459 const std::string& icon_url,
433 bool create_shortcut, 460 bool create_shortcut,
434 const std::string& supervised_user_id, 461 const std::string& supervised_user_id,
435 Profile* supervisor_profile, 462 Profile* custodian_profile,
436 Profile::CreateStatus status) { 463 Profile::CreateStatus status) {
437 // This method gets called once before with Profile::CREATE_STATUS_CREATED. 464 // This method gets called once before with Profile::CREATE_STATUS_CREATED.
438 switch (status) { 465 switch (status) {
439 case Profile::CREATE_STATUS_LOCAL_FAIL: { 466 case Profile::CREATE_STATUS_LOCAL_FAIL: {
440 // TODO(mahmadi): see if a better error message is required here. 467 // TODO(mahmadi): see if a better error message is required here.
441 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); 468 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal());
442 break; 469 break;
443 } 470 }
444 case Profile::CREATE_STATUS_CREATED: { 471 case Profile::CREATE_STATUS_CREATED: {
445 // Ignore the intermediate status. 472 // Ignore the intermediate status.
446 break; 473 break;
447 } 474 }
448 case Profile::CREATE_STATUS_INITIALIZED: { 475 case Profile::CREATE_STATUS_INITIALIZED: {
449 // We are only interested in Profile::CREATE_STATUS_INITIALIZED when 476 // We are only interested in Profile::CREATE_STATUS_INITIALIZED when
450 // everything is ready. 477 // everything is ready.
451 // TODO(mahmadi): display proper error message to the user. 478 if (!IsAccountConnected(custodian_profile) ||
452 PrefService* prefs = supervisor_profile->GetPrefs(); 479 HasAuthError(custodian_profile)) {
480 ShowProfileCreationError(nullptr, l10n_util::GetStringUTF16(
481 IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR));
482 return;
483 }
484
485 PrefService* prefs = custodian_profile->GetPrefs();
453 if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)) 486 if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed))
454 return; 487 return;
455 488
456 if (!supervised_user_id.empty()) { 489 if (!supervised_user_id.empty()) {
457 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; 490 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT;
458 491
459 SupervisedUserSyncService* supervised_user_sync_service = 492 SupervisedUserSyncService* supervised_user_sync_service =
460 SupervisedUserSyncServiceFactory::GetForProfile(supervisor_profile); 493 SupervisedUserSyncServiceFactory::GetForProfile(custodian_profile);
461 if (supervised_user_sync_service) { 494 if (supervised_user_sync_service) {
462 supervised_user_sync_service->GetSupervisedUsersAsync(base::Bind( 495 supervised_user_sync_service->GetSupervisedUsersAsync(base::Bind(
463 &SigninCreateProfileHandler::DoCreateProfileIfPossible, 496 &SigninCreateProfileHandler::DoCreateProfileIfPossible,
464 weak_ptr_factory_.GetWeakPtr(), name, icon_url, create_shortcut, 497 weak_ptr_factory_.GetWeakPtr(), name, icon_url, create_shortcut,
465 supervised_user_id, supervisor_profile)); 498 supervised_user_id, custodian_profile));
466 } 499 }
467 } else { 500 } else {
468 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; 501 profile_creation_type_ = SUPERVISED_PROFILE_CREATION;
469 std::string new_supervised_user_id = 502 std::string new_supervised_user_id =
470 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); 503 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId();
471 504
472 // If sync is not yet fully initialized, the creation may take extra 505 // If sync is not yet fully initialized, the creation may take extra
473 // time, so show a message. Import doesn't wait for an acknowledgment, 506 // time, so show a message. Import doesn't wait for an acknowledgment,
474 // so it won't have the same potential delay. 507 // so it won't have the same potential delay.
475 ProfileSyncService* sync_service = 508 ProfileSyncService* sync_service =
476 ProfileSyncServiceFactory::GetInstance()->GetForProfile( 509 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
477 supervisor_profile); 510 custodian_profile);
478 ProfileSyncService::SyncStatusSummary status = 511 ProfileSyncService::SyncStatusSummary status =
479 sync_service->QuerySyncStatusSummary(); 512 sync_service->QuerySyncStatusSummary();
480 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { 513 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) {
481 ShowProfileCreationWarning(l10n_util::GetStringUTF16( 514 ShowProfileCreationWarning(l10n_util::GetStringUTF16(
482 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); 515 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN));
483 } 516 }
484 517
485 DoCreateProfile(name, icon_url, create_shortcut, new_supervised_user_id, 518 DoCreateProfile(name, icon_url, create_shortcut, new_supervised_user_id,
486 supervisor_profile); 519 custodian_profile);
487 } 520 }
488 break; 521 break;
489 } 522 }
490 case Profile::CREATE_STATUS_CANCELED: 523 case Profile::CREATE_STATUS_CANCELED:
491 case Profile::CREATE_STATUS_REMOTE_FAIL: 524 case Profile::CREATE_STATUS_REMOTE_FAIL:
492 case Profile::MAX_CREATE_STATUS: { 525 case Profile::MAX_CREATE_STATUS: {
493 NOTREACHED(); 526 NOTREACHED();
494 break; 527 break;
495 } 528 }
496 } 529 }
497 } 530 }
498 531
532 bool SigninCreateProfileHandler::IsAccountConnected(Profile* profile)
533 const {
534 SigninManagerBase* signin_manager =
535 SigninManagerFactory::GetForProfile(profile);
536 return signin_manager && signin_manager->IsAuthenticated();
537 }
538
539 bool SigninCreateProfileHandler::HasAuthError(Profile* profile)
540 const {
541 SigninErrorController* error_controller =
542 SigninErrorControllerFactory::GetForProfile(profile);
543 if (!error_controller)
544 return true;
545
546 GoogleServiceAuthError::State state = error_controller->auth_error().state();
547 return state != GoogleServiceAuthError::NONE;
548 }
549
499 void SigninCreateProfileHandler::DoCreateProfileIfPossible( 550 void SigninCreateProfileHandler::DoCreateProfileIfPossible(
500 const base::string16& name, 551 const base::string16& name,
501 const std::string& icon_url, 552 const std::string& icon_url,
502 bool create_shortcut, 553 bool create_shortcut,
503 const std::string& supervised_user_id, 554 const std::string& supervised_user_id,
504 Profile* supervisor_profile, 555 Profile* custodian_profile,
505 const base::DictionaryValue* dict) { 556 const base::DictionaryValue* dict) {
506 DCHECK(dict); 557 DCHECK(dict);
507 if (!dict->HasKey(supervised_user_id)) 558 if (!dict->HasKey(supervised_user_id))
508 return; 559 return;
509 560
510 // Check if this supervised user already exists on this machine. 561 // Check if this supervised user already exists on this machine.
511 std::vector<ProfileAttributesEntry*> entries = 562 std::vector<ProfileAttributesEntry*> entries =
512 g_browser_process->profile_manager()-> 563 g_browser_process->profile_manager()->
513 GetProfileAttributesStorage().GetAllProfilesAttributes(); 564 GetProfileAttributesStorage().GetAllProfilesAttributes();
514 for (ProfileAttributesEntry* entry : entries) { 565 for (ProfileAttributesEntry* entry : entries) {
515 if (supervised_user_id == entry->GetSupervisedUserId()) { 566 if (supervised_user_id == entry->GetSupervisedUserId()) {
516 // TODO(mahmadi): see whether we need a more specific error message here. 567 // TODO(mahmadi): see whether we need a more specific error message here.
517 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); 568 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal());
518 return; 569 return;
519 } 570 }
520 } 571 }
521 572
522 DoCreateProfile(name, icon_url, create_shortcut, supervised_user_id, 573 DoCreateProfile(name, icon_url, create_shortcut, supervised_user_id,
523 supervisor_profile); 574 custodian_profile);
524 } 575 }
525 576
526 void SigninCreateProfileHandler::HandleCancelProfileCreation( 577 void SigninCreateProfileHandler::HandleCancelProfileCreation(
527 const base::ListValue* args) { 578 const base::ListValue* args) {
528 CancelProfileRegistration(true); 579 CancelProfileRegistration(true);
529 } 580 }
530 581
531 // Non-supervised user creation cannot be canceled. (Creating a non-supervised 582 // Non-supervised user creation cannot be canceled. (Creating a non-supervised
532 // profile shouldn't take significant time, and it can easily be deleted 583 // profile shouldn't take significant time, and it can easily be deleted
533 // afterward.) 584 // afterward.)
(...skipping 22 matching lines...) Expand all
556 607
557 // Canceling registration means the callback passed into 608 // Canceling registration means the callback passed into
558 // RegisterAndInitSync() won't be called, so the cleanup must be done here. 609 // RegisterAndInitSync() won't be called, so the cleanup must be done here.
559 profile_path_being_created_.clear(); 610 profile_path_being_created_.clear();
560 webui::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); 611 webui::DeleteProfileAtPath(new_profile->GetPath(), web_ui());
561 } 612 }
562 613
563 void SigninCreateProfileHandler::RegisterSupervisedUser( 614 void SigninCreateProfileHandler::RegisterSupervisedUser(
564 bool create_shortcut, 615 bool create_shortcut,
565 const std::string& supervised_user_id, 616 const std::string& supervised_user_id,
566 Profile* supervisor_profile, 617 Profile* custodian_profile,
567 Profile* new_profile) { 618 Profile* new_profile) {
568 DCHECK_EQ(profile_path_being_created_.value(), 619 DCHECK_EQ(profile_path_being_created_.value(),
569 new_profile->GetPath().value()); 620 new_profile->GetPath().value());
570 621
571 SupervisedUserService* supervised_user_service = 622 SupervisedUserService* supervised_user_service =
572 SupervisedUserServiceFactory::GetForProfile(new_profile); 623 SupervisedUserServiceFactory::GetForProfile(new_profile);
573 624
574 // Register the supervised user using the profile of the custodian. 625 // Register the supervised user using the profile of the custodian.
575 supervised_user_registration_utility_ = 626 supervised_user_registration_utility_ =
576 SupervisedUserRegistrationUtility::Create(supervisor_profile); 627 SupervisedUserRegistrationUtility::Create(custodian_profile);
577 supervised_user_service->RegisterAndInitSync( 628 supervised_user_service->RegisterAndInitSync(
578 supervised_user_registration_utility_.get(), supervisor_profile, 629 supervised_user_registration_utility_.get(), custodian_profile,
579 supervised_user_id, 630 supervised_user_id,
580 base::Bind(&SigninCreateProfileHandler::OnSupervisedUserRegistered, 631 base::Bind(&SigninCreateProfileHandler::OnSupervisedUserRegistered,
581 weak_ptr_factory_.GetWeakPtr(), create_shortcut, new_profile)); 632 weak_ptr_factory_.GetWeakPtr(), create_shortcut, new_profile));
582 } 633 }
583 634
584 void SigninCreateProfileHandler::OnSupervisedUserRegistered( 635 void SigninCreateProfileHandler::OnSupervisedUserRegistered(
585 bool create_shortcut, 636 bool create_shortcut,
586 Profile* profile, 637 Profile* profile,
587 const GoogleServiceAuthError& error) { 638 const GoogleServiceAuthError& error) {
588 GoogleServiceAuthError::State state = error.state(); 639 GoogleServiceAuthError::State state = error.state();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); 675 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_);
625 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", 676 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError",
626 error_state, GoogleServiceAuthError::NUM_STATES); 677 error_state, GoogleServiceAuthError::NUM_STATES);
627 UMA_HISTOGRAM_MEDIUM_TIMES( 678 UMA_HISTOGRAM_MEDIUM_TIMES(
628 "Profile.SupervisedProfileTotalImportTime", 679 "Profile.SupervisedProfileTotalImportTime",
629 base::TimeTicks::Now() - profile_creation_start_time_); 680 base::TimeTicks::Now() - profile_creation_start_time_);
630 } 681 }
631 } 682 }
632 683
633 #endif 684 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698