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

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: Created 4 years, 9 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(
74 "createProfileTitle", 72 "createProfileTitle",
75 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE)); 73 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE));
76
77 localized_strings->SetString( 74 localized_strings->SetString(
78 "supervisedUserLearnMoreTitle", 75 "supervisedUserLearnMoreTitle",
79 l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE)); 76 l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE));
80 localized_strings->SetString( 77 localized_strings->SetString(
81 "supervisedUserLearnMoreDone", 78 "supervisedUserLearnMoreDone",
82 l10n_util::GetStringUTF16( 79 l10n_util::GetStringUTF16(
83 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON)); 80 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON));
84 localized_strings->SetString( 81 localized_strings->SetString(
85 "supervisedUserLearnMoreText", 82 "supervisedUserLearnMoreText",
86 l10n_util::GetStringFUTF16( 83 l10n_util::GetStringFUTF16(
87 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TEXT, 84 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TEXT,
88 base::ASCIIToUTF16( 85 base::ASCIIToUTF16(
89 chrome::kLegacySupervisedUserManagementDisplayURL))); 86 chrome::kLegacySupervisedUserManagementDisplayURL)));
87 localized_strings->SetString(
88 "manageProfilesExistingSupervisedUser",
89 l10n_util::GetStringUTF16(
90 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_REMOTELY));
91 localized_strings->SetString(
92 "managedProfilesExistingLocalSupervisedUser",
93 l10n_util::GetStringUTF16(
94 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_LOCALLY));
95 localized_strings->SetString(
96 "supervisorAccountDetailsOutofDateError",
97 l10n_util::GetStringUTF16(
98 IDS_PROFILES_CREATE_SUPERVISOR_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR));
Pam (message me for reviews) 2016/03/24 19:53:14 Existing bugs and docs and other code refer to the
Moe 2016/03/24 22:07:57 Done.
99 localized_strings->SetString(
100 "supervisorAccountNotSelectedError",
101 l10n_util::GetStringUTF16(
102 IDS_PROFILES_CREATE_NO_SUPERVISOR_ACCOUNT_ERROR));
90 } 103 }
91 104
92 void SigninCreateProfileHandler::RegisterMessages() { 105 void SigninCreateProfileHandler::RegisterMessages() {
93 #if defined(ENABLE_SUPERVISED_USERS) 106 #if defined(ENABLE_SUPERVISED_USERS)
94 // Cancellation is only supported for supervised users. 107 // Cancellation is only supported for supervised users.
95 web_ui()->RegisterMessageCallback( 108 web_ui()->RegisterMessageCallback(
96 "cancelCreateProfile", 109 "cancelCreateProfile",
97 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation, 110 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation,
98 base::Unretained(this))); 111 base::Unretained(this)));
99 #endif 112 #endif
(...skipping 21 matching lines...) Expand all
121 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && 134 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() &&
122 i != placeholder_avatar_index; 135 i != placeholder_avatar_index;
123 i++) { 136 i++) {
124 std::string url = profiles::GetDefaultAvatarIconUrl(i); 137 std::string url = profiles::GetDefaultAvatarIconUrl(i);
125 image_url_list.AppendString(url); 138 image_url_list.AppendString(url);
126 } 139 }
127 140
128 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 141 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
129 base::StringValue("profile-icons-received"), 142 base::StringValue("profile-icons-received"),
130 image_url_list); 143 image_url_list);
144
145 SendNewProfileDefaults();
146 }
147
148 void SigninCreateProfileHandler::SendNewProfileDefaults() {
149 ProfileInfoCache& cache =
150 g_browser_process->profile_manager()->GetProfileInfoCache();
151 base::DictionaryValue profile_info;
152 profile_info.SetString("name", cache.ChooseNameForNewProfile(0));
153
154 web_ui()->CallJavascriptFunction(
155 "cr.webUIListenerCallback",
156 base::StringValue("profile-defaults-received"),
157 profile_info);
131 } 158 }
132 159
133 void SigninCreateProfileHandler::RequestSignedInProfiles( 160 void SigninCreateProfileHandler::RequestSignedInProfiles(
134 const base::ListValue* args) { 161 const base::ListValue* args) {
135 base::ListValue user_info_list; 162 base::ListValue user_info_list;
136 std::vector<ProfileAttributesEntry*> entries = 163 std::vector<ProfileAttributesEntry*> entries =
137 g_browser_process->profile_manager()-> 164 g_browser_process->profile_manager()->
138 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); 165 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName();
139 for (ProfileAttributesEntry* entry : entries) { 166 for (ProfileAttributesEntry* entry : entries) {
140 base::string16 username = entry->GetUserName(); 167 base::string16 username = entry->GetUserName();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 webui::OpenNewWindowForProfile( 347 webui::OpenNewWindowForProfile(
321 profile, Profile::CREATE_STATUS_INITIALIZED); 348 profile, Profile::CREATE_STATUS_INITIALIZED);
322 } 349 }
323 profile_creation_type_ = NO_CREATION_IN_PROGRESS; 350 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
324 } 351 }
325 352
326 void SigninCreateProfileHandler::ShowProfileCreationError( 353 void SigninCreateProfileHandler::ShowProfileCreationError(
327 Profile* profile, 354 Profile* profile,
328 const base::string16& error) { 355 const base::string16& error) {
329 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); 356 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
330 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
331 profile_path_being_created_.clear();
332 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 357 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
333 GetWebUIListenerName(PROFILE_CREATION_ERROR), 358 GetWebUIListenerName(PROFILE_CREATION_ERROR),
334 base::StringValue(error)); 359 base::StringValue(error));
335 // The ProfileManager calls us back with a NULL profile in some cases. 360 // The ProfileManager calls us back with a NULL profile in some cases.
336 if (profile) 361 if (profile)
337 webui::DeleteProfileAtPath(profile->GetPath(), web_ui()); 362 webui::DeleteProfileAtPath(profile->GetPath(), web_ui());
363 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
364 profile_path_being_created_.clear();
338 } 365 }
339 366
340 void SigninCreateProfileHandler::RecordProfileCreationMetrics( 367 void SigninCreateProfileHandler::RecordProfileCreationMetrics(
341 Profile::CreateStatus status) { 368 Profile::CreateStatus status) {
342 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, 369 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status,
343 Profile::MAX_CREATE_STATUS); 370 Profile::MAX_CREATE_STATUS);
344 UMA_HISTOGRAM_MEDIUM_TIMES( 371 UMA_HISTOGRAM_MEDIUM_TIMES(
345 "Profile.CreateTimeNoTimeout", 372 "Profile.CreateTimeNoTimeout",
346 base::TimeTicks::Now() - profile_creation_start_time_); 373 base::TimeTicks::Now() - profile_creation_start_time_);
347 } 374 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); 466 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal());
440 break; 467 break;
441 } 468 }
442 case Profile::CREATE_STATUS_CREATED: { 469 case Profile::CREATE_STATUS_CREATED: {
443 // Ignore the intermediate status. 470 // Ignore the intermediate status.
444 break; 471 break;
445 } 472 }
446 case Profile::CREATE_STATUS_INITIALIZED: { 473 case Profile::CREATE_STATUS_INITIALIZED: {
447 // We are only interested in Profile::CREATE_STATUS_INITIALIZED when 474 // We are only interested in Profile::CREATE_STATUS_INITIALIZED when
448 // everything is ready. 475 // everything is ready.
449 // TODO(mahmadi): display proper error message to the user. 476 if (!IsAccountConnected(supervisor_profile) ||
477 HasAuthError(supervisor_profile)) {
478 ShowProfileCreationError(nullptr, l10n_util::GetStringUTF16(
479 IDS_PROFILES_CREATE_SUPERVISOR_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR));
480 return;
481 }
482
450 PrefService* prefs = supervisor_profile->GetPrefs(); 483 PrefService* prefs = supervisor_profile->GetPrefs();
451 if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)) 484 if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed))
452 return; 485 return;
453 486
454 if (!supervised_user_id.empty()) { 487 if (!supervised_user_id.empty()) {
455 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; 488 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT;
456 489
457 SupervisedUserSyncService* supervised_user_sync_service = 490 SupervisedUserSyncService* supervised_user_sync_service =
458 SupervisedUserSyncServiceFactory::GetForProfile(supervisor_profile); 491 SupervisedUserSyncServiceFactory::GetForProfile(supervisor_profile);
459 if (supervised_user_sync_service) { 492 if (supervised_user_sync_service) {
(...skipping 27 matching lines...) Expand all
487 } 520 }
488 case Profile::CREATE_STATUS_CANCELED: 521 case Profile::CREATE_STATUS_CANCELED:
489 case Profile::CREATE_STATUS_REMOTE_FAIL: 522 case Profile::CREATE_STATUS_REMOTE_FAIL:
490 case Profile::MAX_CREATE_STATUS: { 523 case Profile::MAX_CREATE_STATUS: {
491 NOTREACHED(); 524 NOTREACHED();
492 break; 525 break;
493 } 526 }
494 } 527 }
495 } 528 }
496 529
530 bool SigninCreateProfileHandler::IsAccountConnected(Profile* profile)
531 const {
532 SigninManagerBase* signin_manager =
533 SigninManagerFactory::GetForProfile(profile);
534 return signin_manager && signin_manager->IsAuthenticated();
535 }
536
537 bool SigninCreateProfileHandler::HasAuthError(Profile* profile)
538 const {
539 SigninErrorController* error_controller =
540 SigninErrorControllerFactory::GetForProfile(profile);
541 if (!error_controller)
542 return true;
543
544 GoogleServiceAuthError::State state = error_controller->auth_error().state();
545
546 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS ||
547 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP ||
548 state == GoogleServiceAuthError::ACCOUNT_DELETED ||
549 state == GoogleServiceAuthError::ACCOUNT_DISABLED;
Roger Tawa OOO till Jul 10th 2016/03/24 14:39:05 Is there a specific reason to handle these 4 state
Moe 2016/03/24 22:07:57 No specific reason. These 4 states were being chec
550 }
551
497 void SigninCreateProfileHandler::DoCreateProfileIfPossible( 552 void SigninCreateProfileHandler::DoCreateProfileIfPossible(
498 const base::string16& name, 553 const base::string16& name,
499 const std::string& icon_url, 554 const std::string& icon_url,
500 bool create_shortcut, 555 bool create_shortcut,
501 const std::string& supervised_user_id, 556 const std::string& supervised_user_id,
502 Profile* supervisor_profile, 557 Profile* supervisor_profile,
503 const base::DictionaryValue* dict) { 558 const base::DictionaryValue* dict) {
504 DCHECK(dict); 559 DCHECK(dict);
505 if (!dict->HasKey(supervised_user_id)) 560 if (!dict->HasKey(supervised_user_id))
506 return; 561 return;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); 677 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_);
623 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", 678 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError",
624 error_state, GoogleServiceAuthError::NUM_STATES); 679 error_state, GoogleServiceAuthError::NUM_STATES);
625 UMA_HISTOGRAM_MEDIUM_TIMES( 680 UMA_HISTOGRAM_MEDIUM_TIMES(
626 "Profile.SupervisedProfileTotalImportTime", 681 "Profile.SupervisedProfileTotalImportTime",
627 base::TimeTicks::Now() - profile_creation_start_time_); 682 base::TimeTicks::Now() - profile_creation_start_time_);
628 } 683 }
629 } 684 }
630 685
631 #endif 686 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698