| OLD | NEW |
| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 web_ui()->RegisterMessageCallback( | 178 web_ui()->RegisterMessageCallback( |
| 179 "requestSignedInProfiles", | 179 "requestSignedInProfiles", |
| 180 base::Bind(&SigninCreateProfileHandler::RequestSignedInProfiles, | 180 base::Bind(&SigninCreateProfileHandler::RequestSignedInProfiles, |
| 181 base::Unretained(this))); | 181 base::Unretained(this))); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void SigninCreateProfileHandler::RequestDefaultProfileIcons( | 184 void SigninCreateProfileHandler::RequestDefaultProfileIcons( |
| 185 const base::ListValue* args) { | 185 const base::ListValue* args) { |
| 186 web_ui()->CallJavascriptFunctionUnsafe( | 186 web_ui()->CallJavascriptFunctionUnsafe( |
| 187 "cr.webUIListenerCallback", base::StringValue("profile-icons-received"), | 187 "cr.webUIListenerCallback", base::Value("profile-icons-received"), |
| 188 *profiles::GetDefaultProfileAvatarIconsAndLabels()); | 188 *profiles::GetDefaultProfileAvatarIconsAndLabels()); |
| 189 | 189 |
| 190 SendNewProfileDefaults(); | 190 SendNewProfileDefaults(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void SigninCreateProfileHandler::SendNewProfileDefaults() { | 193 void SigninCreateProfileHandler::SendNewProfileDefaults() { |
| 194 ProfileAttributesStorage& storage = | 194 ProfileAttributesStorage& storage = |
| 195 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 195 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 196 base::DictionaryValue profile_info; | 196 base::DictionaryValue profile_info; |
| 197 profile_info.SetString("name", storage.ChooseNameForNewProfile(0)); | 197 profile_info.SetString("name", storage.ChooseNameForNewProfile(0)); |
| 198 | 198 |
| 199 web_ui()->CallJavascriptFunctionUnsafe( | 199 web_ui()->CallJavascriptFunctionUnsafe( |
| 200 "cr.webUIListenerCallback", | 200 "cr.webUIListenerCallback", base::Value("profile-defaults-received"), |
| 201 base::StringValue("profile-defaults-received"), profile_info); | 201 profile_info); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void SigninCreateProfileHandler::RequestSignedInProfiles( | 204 void SigninCreateProfileHandler::RequestSignedInProfiles( |
| 205 const base::ListValue* args) { | 205 const base::ListValue* args) { |
| 206 base::ListValue user_info_list; | 206 base::ListValue user_info_list; |
| 207 std::vector<ProfileAttributesEntry*> entries = | 207 std::vector<ProfileAttributesEntry*> entries = |
| 208 g_browser_process->profile_manager()-> | 208 g_browser_process->profile_manager()-> |
| 209 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); | 209 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); |
| 210 for (ProfileAttributesEntry* entry : entries) { | 210 for (ProfileAttributesEntry* entry : entries) { |
| 211 base::string16 username = entry->GetUserName(); | 211 base::string16 username = entry->GetUserName(); |
| 212 if (username.empty()) | 212 if (username.empty()) |
| 213 continue; | 213 continue; |
| 214 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); | 214 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); |
| 215 std::unique_ptr<base::DictionaryValue> user_info( | 215 std::unique_ptr<base::DictionaryValue> user_info( |
| 216 new base::DictionaryValue()); | 216 new base::DictionaryValue()); |
| 217 user_info->SetString("username", username); | 217 user_info->SetString("username", username); |
| 218 user_info->SetString("profilePath", profile_path); | 218 user_info->SetString("profilePath", profile_path); |
| 219 | 219 |
| 220 user_info_list.Append(std::move(user_info)); | 220 user_info_list.Append(std::move(user_info)); |
| 221 } | 221 } |
| 222 web_ui()->CallJavascriptFunctionUnsafe( | 222 web_ui()->CallJavascriptFunctionUnsafe("cr.webUIListenerCallback", |
| 223 "cr.webUIListenerCallback", base::StringValue("signedin-users-received"), | 223 base::Value("signedin-users-received"), |
| 224 user_info_list); | 224 user_info_list); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void SigninCreateProfileHandler::OnProfileAuthInfoChanged( | 227 void SigninCreateProfileHandler::OnProfileAuthInfoChanged( |
| 228 const base::FilePath& profile_path) { | 228 const base::FilePath& profile_path) { |
| 229 RequestSignedInProfiles(nullptr); | 229 RequestSignedInProfiles(nullptr); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { | 232 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { |
| 233 if (!profiles::IsMultipleProfilesEnabled()) | 233 if (!profiles::IsMultipleProfilesEnabled()) |
| 234 return; | 234 return; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 UserManagerProfileDialog::ShowSigninDialog( | 432 UserManagerProfileDialog::ShowSigninDialog( |
| 433 web_ui()->GetWebContents()->GetBrowserContext(), profile->GetPath()); | 433 web_ui()->GetWebContents()->GetBrowserContext(), profile->GetPath()); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void SigninCreateProfileHandler::ShowProfileCreationError( | 436 void SigninCreateProfileHandler::ShowProfileCreationError( |
| 437 Profile* profile, | 437 Profile* profile, |
| 438 const base::string16& error) { | 438 const base::string16& error) { |
| 439 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 439 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 440 web_ui()->CallJavascriptFunctionUnsafe( | 440 web_ui()->CallJavascriptFunctionUnsafe( |
| 441 "cr.webUIListenerCallback", GetWebUIListenerName(PROFILE_CREATION_ERROR), | 441 "cr.webUIListenerCallback", GetWebUIListenerName(PROFILE_CREATION_ERROR), |
| 442 base::StringValue(error)); | 442 base::Value(error)); |
| 443 // The ProfileManager calls us back with a NULL profile in some cases. | 443 // The ProfileManager calls us back with a NULL profile in some cases. |
| 444 if (profile) { | 444 if (profile) { |
| 445 webui::DeleteProfileAtPath(profile->GetPath(), | 445 webui::DeleteProfileAtPath(profile->GetPath(), |
| 446 web_ui(), | 446 web_ui(), |
| 447 ProfileMetrics::DELETE_PROFILE_SETTINGS); | 447 ProfileMetrics::DELETE_PROFILE_SETTINGS); |
| 448 } | 448 } |
| 449 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 449 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 450 profile_path_being_created_.clear(); | 450 profile_path_being_created_.clear(); |
| 451 } | 451 } |
| 452 | 452 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // Chrome to close. | 490 // Chrome to close. |
| 491 if (browser && browser->window()) { | 491 if (browser && browser->window()) { |
| 492 UserManager::Hide(); | 492 UserManager::Hide(); |
| 493 } else { | 493 } else { |
| 494 registrar_.Add(this, | 494 registrar_.Add(this, |
| 495 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 495 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 496 content::NotificationService::AllSources()); | 496 content::NotificationService::AllSources()); |
| 497 } | 497 } |
| 498 } | 498 } |
| 499 | 499 |
| 500 base::StringValue SigninCreateProfileHandler::GetWebUIListenerName( | 500 base::Value SigninCreateProfileHandler::GetWebUIListenerName( |
| 501 ProfileCreationStatus status) const { | 501 ProfileCreationStatus status) const { |
| 502 switch (status) { | 502 switch (status) { |
| 503 case PROFILE_CREATION_SUCCESS: | 503 case PROFILE_CREATION_SUCCESS: |
| 504 return base::StringValue("create-profile-success"); | 504 return base::Value("create-profile-success"); |
| 505 case PROFILE_CREATION_ERROR: | 505 case PROFILE_CREATION_ERROR: |
| 506 return base::StringValue("create-profile-error"); | 506 return base::Value("create-profile-error"); |
| 507 } | 507 } |
| 508 NOTREACHED(); | 508 NOTREACHED(); |
| 509 return base::StringValue(std::string()); | 509 return base::Value(std::string()); |
| 510 } | 510 } |
| 511 | 511 |
| 512 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 512 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 513 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageRemote() | 513 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageRemote() |
| 514 const { | 514 const { |
| 515 return l10n_util::GetStringUTF16( | 515 return l10n_util::GetStringUTF16( |
| 516 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT | 516 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT |
| 517 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR | 517 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR |
| 518 : IDS_PROFILES_CREATE_REMOTE_ERROR); | 518 : IDS_PROFILES_CREATE_REMOTE_ERROR); |
| 519 } | 519 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 error_msg = GetProfileCreateErrorMessageSignin(); | 761 error_msg = GetProfileCreateErrorMessageSignin(); |
| 762 } else { | 762 } else { |
| 763 error_msg = GetProfileCreateErrorMessageRemote(); | 763 error_msg = GetProfileCreateErrorMessageRemote(); |
| 764 } | 764 } |
| 765 ShowProfileCreationError(profile, error_msg); | 765 ShowProfileCreationError(profile, error_msg); |
| 766 } | 766 } |
| 767 | 767 |
| 768 void SigninCreateProfileHandler::ShowProfileCreationWarning( | 768 void SigninCreateProfileHandler::ShowProfileCreationWarning( |
| 769 const base::string16& warning) { | 769 const base::string16& warning) { |
| 770 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); | 770 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); |
| 771 web_ui()->CallJavascriptFunctionUnsafe( | 771 web_ui()->CallJavascriptFunctionUnsafe("cr.webUIListenerCallback", |
| 772 "cr.webUIListenerCallback", base::StringValue("create-profile-warning"), | 772 base::Value("create-profile-warning"), |
| 773 base::StringValue(warning)); | 773 base::Value(warning)); |
| 774 } | 774 } |
| 775 | 775 |
| 776 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( | 776 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( |
| 777 GoogleServiceAuthError::State error_state) { | 777 GoogleServiceAuthError::State error_state) { |
| 778 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { | 778 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { |
| 779 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", | 779 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", |
| 780 error_state, GoogleServiceAuthError::NUM_STATES); | 780 error_state, GoogleServiceAuthError::NUM_STATES); |
| 781 UMA_HISTOGRAM_MEDIUM_TIMES( | 781 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 782 "Profile.SupervisedProfileTotalCreateTime", | 782 "Profile.SupervisedProfileTotalCreateTime", |
| 783 base::TimeTicks::Now() - profile_creation_start_time_); | 783 base::TimeTicks::Now() - profile_creation_start_time_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 808 | 808 |
| 809 profiles::OpenBrowserWindowForProfile( | 809 profiles::OpenBrowserWindowForProfile( |
| 810 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, | 810 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, |
| 811 weak_ptr_factory_.GetWeakPtr()), | 811 weak_ptr_factory_.GetWeakPtr()), |
| 812 false, // Don't create a window if one already exists. | 812 false, // Don't create a window if one already exists. |
| 813 true, // Create a first run window. | 813 true, // Create a first run window. |
| 814 profile, | 814 profile, |
| 815 Profile::CREATE_STATUS_INITIALIZED); | 815 Profile::CREATE_STATUS_INITIALIZED); |
| 816 } | 816 } |
| 817 #endif | 817 #endif |
| OLD | NEW |