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

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

Issue 1722843002: MD user manager (html/js/css for create profile flow) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments #6 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
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 SigninCreateProfileHandler::~SigninCreateProfileHandler() { 50 SigninCreateProfileHandler::~SigninCreateProfileHandler() {
51 #if defined(ENABLE_SUPERVISED_USERS) 51 #if defined(ENABLE_SUPERVISED_USERS)
52 // Cancellation is only supported for supervised users. 52 // Cancellation is only supported for supervised users.
53 CancelProfileRegistration(false); 53 CancelProfileRegistration(false);
54 #endif 54 #endif
55 } 55 }
56 56
57 void SigninCreateProfileHandler::GetLocalizedValues( 57 void SigninCreateProfileHandler::GetLocalizedValues(
58 base::DictionaryValue* localized_strings) { 58 base::DictionaryValue* localized_strings) {
59 localized_strings->SetString( 59 localized_strings->SetString(
60 "manageProfilesSupervisedSignedInLabel",
61 l10n_util::GetStringUTF16(
62 IDS_PROFILES_CREATE_SUPERVISED_MULTI_SIGNED_IN_LABEL));
63 localized_strings->SetString(
60 "manageProfilesSupervisedNotSignedIn", 64 "manageProfilesSupervisedNotSignedIn",
61 l10n_util::GetStringUTF16( 65 l10n_util::GetStringUTF16(
62 IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML)); 66 IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML));
63 localized_strings->SetString("createProfileConfirm", 67 localized_strings->SetString("createProfileConfirm",
64 l10n_util::GetStringUTF16(IDS_SAVE)); 68 l10n_util::GetStringUTF16(IDS_SAVE));
65 localized_strings->SetString("learnMore", 69 localized_strings->SetString("learnMore",
66 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 70 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
67 localized_strings->SetString( 71 localized_strings->SetString(
68 "createProfileTitle", 72 "createProfileTitle",
69 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE)); 73 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 116
113 // Add the default avatar icons. 117 // Add the default avatar icons.
114 size_t placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); 118 size_t placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex();
115 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && 119 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() &&
116 i != placeholder_avatar_index; 120 i != placeholder_avatar_index;
117 i++) { 121 i++) {
118 std::string url = profiles::GetDefaultAvatarIconUrl(i); 122 std::string url = profiles::GetDefaultAvatarIconUrl(i);
119 image_url_list.AppendString(url); 123 image_url_list.AppendString(url);
120 } 124 }
121 125
122 web_ui()->CallJavascriptFunction("signin.ProfileApi.updateAvailableIcons", 126 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
127 base::StringValue("profile-icons-received"),
123 image_url_list); 128 image_url_list);
124 } 129 }
125 130
126 void SigninCreateProfileHandler::RequestSignedInProfiles( 131 void SigninCreateProfileHandler::RequestSignedInProfiles(
127 const base::ListValue* args) { 132 const base::ListValue* args) {
128 base::ListValue user_info_list; 133 base::ListValue user_info_list;
129 ProfileInfoCache& cache = 134 ProfileInfoCache& cache =
130 g_browser_process->profile_manager()->GetProfileInfoCache(); 135 g_browser_process->profile_manager()->GetProfileInfoCache();
131 std::vector<ProfileAttributesEntry*> entries = 136 std::vector<ProfileAttributesEntry*> entries =
132 cache.GetAllProfilesAttributes(); 137 cache.GetAllProfilesAttributes();
133 for (auto& entry : entries) { 138 for (auto& entry : entries) {
134 base::string16 username = entry->GetUserName(); 139 base::string16 username = entry->GetUserName();
135 if (username.empty()) 140 if (username.empty())
136 continue; 141 continue;
137 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); 142 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe();
138 scoped_ptr<base::DictionaryValue> user_info(new base::DictionaryValue()); 143 scoped_ptr<base::DictionaryValue> user_info(new base::DictionaryValue());
139 user_info->SetString("username", username); 144 user_info->SetString("username", username);
140 user_info->SetString("profilePath", profile_path); 145 user_info->SetString("profilePath", profile_path);
141 146
142 user_info_list.Append(user_info.release()); 147 user_info_list.Append(user_info.release());
143 } 148 }
144 web_ui()->CallJavascriptFunction("signin.ProfileApi.updateSignedInUsers", 149 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
150 base::StringValue("signedin-users-received"),
145 user_info_list); 151 user_info_list);
146 } 152 }
147 153
148 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { 154 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) {
149 if (!profiles::IsMultipleProfilesEnabled()) 155 if (!profiles::IsMultipleProfilesEnabled())
150 return; 156 return;
151 157
152 // We can have only one in progress profile creation 158 // We can have only one in progress profile creation
153 // at any given moment, if new ones are initiated just 159 // at any given moment, if new ones are initiated just
154 // ignore them until we are done with the old one. 160 // ignore them until we are done with the old one.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); 291 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
286 base::DictionaryValue dict; 292 base::DictionaryValue dict;
287 dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName)); 293 dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName));
288 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); 294 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath()));
289 #if defined(ENABLE_SUPERVISED_USERS) 295 #if defined(ENABLE_SUPERVISED_USERS)
290 bool is_supervised = profile_creation_type_ == SUPERVISED_PROFILE_CREATION || 296 bool is_supervised = profile_creation_type_ == SUPERVISED_PROFILE_CREATION ||
291 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; 297 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT;
292 dict.SetBoolean("isSupervised", is_supervised); 298 dict.SetBoolean("isSupervised", is_supervised);
293 #endif 299 #endif
294 web_ui()->CallJavascriptFunction( 300 web_ui()->CallJavascriptFunction(
295 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict); 301 "cr.webUIListenerCallback",
302 GetWebUIListenerName(PROFILE_CREATION_SUCCESS),
303 dict);
296 304
297 // If the new profile is a supervised user, instead of opening a new window 305 // If the new profile is a supervised user, instead of opening a new window
298 // right away, a confirmation overlay will be shown by JS from the creation 306 // right away, a confirmation overlay will be shown by JS from the creation
299 // dialog. If we are importing an existing supervised profile or creating a 307 // dialog. If we are importing an existing supervised profile or creating a
300 // new non-supervised user profile we don't show any confirmation, so open 308 // new non-supervised user profile we don't show any confirmation, so open
301 // the new window now. 309 // the new window now.
302 bool should_open_new_window = true; 310 bool should_open_new_window = true;
303 #if defined(ENABLE_SUPERVISED_USERS) 311 #if defined(ENABLE_SUPERVISED_USERS)
304 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) 312 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION)
305 should_open_new_window = false; 313 should_open_new_window = false;
306 #endif 314 #endif
307 315
308 if (should_open_new_window) { 316 if (should_open_new_window) {
309 // Opening the new window must be the last action, after all callbacks 317 // Opening the new window must be the last action, after all callbacks
310 // have been run, to give them a chance to initialize the profile. 318 // have been run, to give them a chance to initialize the profile.
311 webui::OpenNewWindowForProfile( 319 webui::OpenNewWindowForProfile(
312 profile, Profile::CREATE_STATUS_INITIALIZED); 320 profile, Profile::CREATE_STATUS_INITIALIZED);
313 } 321 }
314 profile_creation_type_ = NO_CREATION_IN_PROGRESS; 322 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
315 } 323 }
316 324
317 void SigninCreateProfileHandler::ShowProfileCreationError( 325 void SigninCreateProfileHandler::ShowProfileCreationError(
318 Profile* profile, 326 Profile* profile,
319 const base::string16& error) { 327 const base::string16& error) {
320 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); 328 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
321 profile_creation_type_ = NO_CREATION_IN_PROGRESS; 329 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
322 profile_path_being_created_.clear(); 330 profile_path_being_created_.clear();
323 web_ui()->CallJavascriptFunction( 331 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
324 GetJavascriptMethodName(PROFILE_CREATION_ERROR), 332 GetWebUIListenerName(PROFILE_CREATION_ERROR),
325 base::StringValue(error)); 333 base::StringValue(error));
326 // The ProfileManager calls us back with a NULL profile in some cases. 334 // The ProfileManager calls us back with a NULL profile in some cases.
327 if (profile) 335 if (profile)
328 webui::DeleteProfileAtPath(profile->GetPath(), web_ui()); 336 webui::DeleteProfileAtPath(profile->GetPath(), web_ui());
329 } 337 }
330 338
331 void SigninCreateProfileHandler::RecordProfileCreationMetrics( 339 void SigninCreateProfileHandler::RecordProfileCreationMetrics(
332 Profile::CreateStatus status) { 340 Profile::CreateStatus status) {
333 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, 341 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status,
334 Profile::MAX_CREATE_STATUS); 342 Profile::MAX_CREATE_STATUS);
335 UMA_HISTOGRAM_MEDIUM_TIMES( 343 UMA_HISTOGRAM_MEDIUM_TIMES(
(...skipping 23 matching lines...) Expand all
359 367
360 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageSignin() 368 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageSignin()
361 const { 369 const {
362 return l10n_util::GetStringUTF16( 370 return l10n_util::GetStringUTF16(
363 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT 371 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT
364 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR 372 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR
365 : IDS_PROFILES_CREATE_SIGN_IN_ERROR); 373 : IDS_PROFILES_CREATE_SIGN_IN_ERROR);
366 } 374 }
367 #endif 375 #endif
368 376
369 std::string SigninCreateProfileHandler::GetJavascriptMethodName( 377 base::StringValue SigninCreateProfileHandler::GetWebUIListenerName(
370 ProfileCreationStatus status) const { 378 ProfileCreationStatus status) const {
371 switch (profile_creation_type_) { 379 switch (profile_creation_type_) {
372 #if defined(ENABLE_SUPERVISED_USERS) 380 #if defined(ENABLE_SUPERVISED_USERS)
373 case SUPERVISED_PROFILE_IMPORT: 381 case SUPERVISED_PROFILE_IMPORT:
374 switch (status) { 382 switch (status) {
375 case PROFILE_CREATION_SUCCESS: 383 case PROFILE_CREATION_SUCCESS:
376 return "BrowserOptions.showSupervisedUserImportSuccess"; 384 return base::StringValue("create-profile-success");
377 case PROFILE_CREATION_ERROR: 385 case PROFILE_CREATION_ERROR:
378 return "BrowserOptions.showSupervisedUserImportError"; 386 return base::StringValue("create-profile-error");
379 } 387 }
380 break; 388 break;
381 #endif 389 #endif
382 default: 390 default:
383 switch (status) { 391 switch (status) {
384 case PROFILE_CREATION_SUCCESS: 392 case PROFILE_CREATION_SUCCESS:
385 return "signin.ProfileApi.onCreateProfileSuccess"; 393 return base::StringValue("create-profile-success");
386 case PROFILE_CREATION_ERROR: 394 case PROFILE_CREATION_ERROR:
387 return "signin.ProfileApi.onCreateProfileError"; 395 return base::StringValue("create-profile-error");
388 } 396 }
389 break; 397 break;
390 } 398 }
391 399
392 NOTREACHED(); 400 NOTREACHED();
393 return std::string(); 401 return base::StringValue(std::string());
394 } 402 }
395 403
396 #if defined(ENABLE_SUPERVISED_USERS) 404 #if defined(ENABLE_SUPERVISED_USERS)
397 bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs( 405 bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs(
398 const base::ListValue* args, 406 const base::ListValue* args,
399 std::string* supervised_user_id, 407 std::string* supervised_user_id,
400 base::FilePath* supervisor_profile_path) { 408 base::FilePath* supervisor_profile_path) {
401 bool supervised_user = false; 409 bool supervised_user = false;
402 bool success = args->GetBoolean(3, &supervised_user); 410 bool success = args->GetBoolean(3, &supervised_user);
403 DCHECK(success); 411 DCHECK(success);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 error_msg = GetProfileCreateErrorMessageSignin(); 598 error_msg = GetProfileCreateErrorMessageSignin();
591 } else { 599 } else {
592 error_msg = GetProfileCreateErrorMessageRemote(); 600 error_msg = GetProfileCreateErrorMessageRemote();
593 } 601 }
594 ShowProfileCreationError(profile, error_msg); 602 ShowProfileCreationError(profile, error_msg);
595 } 603 }
596 604
597 void SigninCreateProfileHandler::ShowProfileCreationWarning( 605 void SigninCreateProfileHandler::ShowProfileCreationWarning(
598 const base::string16& warning) { 606 const base::string16& warning) {
599 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); 607 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_);
600 web_ui()->CallJavascriptFunction("signin.ProfileApi.onCreateProfileWarning", 608 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
609 base::StringValue("create-profile-warning"),
601 base::StringValue(warning)); 610 base::StringValue(warning));
602 } 611 }
603 612
604 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( 613 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics(
605 GoogleServiceAuthError::State error_state) { 614 GoogleServiceAuthError::State error_state) {
606 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { 615 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) {
607 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", 616 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError",
608 error_state, GoogleServiceAuthError::NUM_STATES); 617 error_state, GoogleServiceAuthError::NUM_STATES);
609 UMA_HISTOGRAM_MEDIUM_TIMES( 618 UMA_HISTOGRAM_MEDIUM_TIMES(
610 "Profile.SupervisedProfileTotalCreateTime", 619 "Profile.SupervisedProfileTotalCreateTime",
611 base::TimeTicks::Now() - profile_creation_start_time_); 620 base::TimeTicks::Now() - profile_creation_start_time_);
612 } else { 621 } else {
613 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); 622 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_);
614 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", 623 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError",
615 error_state, GoogleServiceAuthError::NUM_STATES); 624 error_state, GoogleServiceAuthError::NUM_STATES);
616 UMA_HISTOGRAM_MEDIUM_TIMES( 625 UMA_HISTOGRAM_MEDIUM_TIMES(
617 "Profile.SupervisedProfileTotalImportTime", 626 "Profile.SupervisedProfileTotalImportTime",
618 base::TimeTicks::Now() - profile_creation_start_time_); 627 base::TimeTicks::Now() - profile_creation_start_time_);
619 } 628 }
620 } 629 }
621 630
622 #endif 631 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698