| 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 // Add the default avatar icons. | 178 // Add the default avatar icons. |
| 179 size_t placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); | 179 size_t placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 180 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && | 180 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && |
| 181 i != placeholder_avatar_index; | 181 i != placeholder_avatar_index; |
| 182 i++) { | 182 i++) { |
| 183 std::string url = profiles::GetDefaultAvatarIconUrl(i); | 183 std::string url = profiles::GetDefaultAvatarIconUrl(i); |
| 184 image_url_list.AppendString(url); | 184 image_url_list.AppendString(url); |
| 185 } | 185 } |
| 186 | 186 |
| 187 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | 187 web_ui()->CallJavascriptFunctionUnsafe( |
| 188 base::StringValue("profile-icons-received"), | 188 "cr.webUIListenerCallback", base::StringValue("profile-icons-received"), |
| 189 image_url_list); | 189 image_url_list); |
| 190 | 190 |
| 191 SendNewProfileDefaults(); | 191 SendNewProfileDefaults(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void SigninCreateProfileHandler::SendNewProfileDefaults() { | 194 void SigninCreateProfileHandler::SendNewProfileDefaults() { |
| 195 ProfileAttributesStorage& storage = | 195 ProfileAttributesStorage& storage = |
| 196 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | 196 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 197 base::DictionaryValue profile_info; | 197 base::DictionaryValue profile_info; |
| 198 profile_info.SetString("name", storage.ChooseNameForNewProfile(0)); | 198 profile_info.SetString("name", storage.ChooseNameForNewProfile(0)); |
| 199 | 199 |
| 200 web_ui()->CallJavascriptFunction( | 200 web_ui()->CallJavascriptFunctionUnsafe( |
| 201 "cr.webUIListenerCallback", | 201 "cr.webUIListenerCallback", |
| 202 base::StringValue("profile-defaults-received"), | 202 base::StringValue("profile-defaults-received"), profile_info); |
| 203 profile_info); | |
| 204 } | 203 } |
| 205 | 204 |
| 206 void SigninCreateProfileHandler::RequestSignedInProfiles( | 205 void SigninCreateProfileHandler::RequestSignedInProfiles( |
| 207 const base::ListValue* args) { | 206 const base::ListValue* args) { |
| 208 base::ListValue user_info_list; | 207 base::ListValue user_info_list; |
| 209 std::vector<ProfileAttributesEntry*> entries = | 208 std::vector<ProfileAttributesEntry*> entries = |
| 210 g_browser_process->profile_manager()-> | 209 g_browser_process->profile_manager()-> |
| 211 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); | 210 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); |
| 212 for (ProfileAttributesEntry* entry : entries) { | 211 for (ProfileAttributesEntry* entry : entries) { |
| 213 base::string16 username = entry->GetUserName(); | 212 base::string16 username = entry->GetUserName(); |
| 214 if (username.empty()) | 213 if (username.empty()) |
| 215 continue; | 214 continue; |
| 216 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); | 215 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); |
| 217 std::unique_ptr<base::DictionaryValue> user_info( | 216 std::unique_ptr<base::DictionaryValue> user_info( |
| 218 new base::DictionaryValue()); | 217 new base::DictionaryValue()); |
| 219 user_info->SetString("username", username); | 218 user_info->SetString("username", username); |
| 220 user_info->SetString("profilePath", profile_path); | 219 user_info->SetString("profilePath", profile_path); |
| 221 | 220 |
| 222 user_info_list.Append(std::move(user_info)); | 221 user_info_list.Append(std::move(user_info)); |
| 223 } | 222 } |
| 224 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | 223 web_ui()->CallJavascriptFunctionUnsafe( |
| 225 base::StringValue("signedin-users-received"), | 224 "cr.webUIListenerCallback", base::StringValue("signedin-users-received"), |
| 226 user_info_list); | 225 user_info_list); |
| 227 } | 226 } |
| 228 | 227 |
| 229 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { | 228 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { |
| 230 if (!profiles::IsMultipleProfilesEnabled()) | 229 if (!profiles::IsMultipleProfilesEnabled()) |
| 231 return; | 230 return; |
| 232 | 231 |
| 233 // We can have only one in progress profile creation | 232 // We can have only one in progress profile creation |
| 234 // at any given moment, if new ones are initiated just | 233 // at any given moment, if new ones are initiated just |
| 235 // ignore them until we are done with the old one. | 234 // ignore them until we are done with the old one. |
| 236 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) | 235 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 385 |
| 387 if (is_supervised) { | 386 if (is_supervised) { |
| 388 DCHECK(custodian_profile); | 387 DCHECK(custodian_profile); |
| 389 if (custodian_profile) { | 388 if (custodian_profile) { |
| 390 std::string custodian_username = custodian_profile->GetProfileUserName(); | 389 std::string custodian_username = custodian_profile->GetProfileUserName(); |
| 391 dict.SetString("custodianUsername", custodian_username); | 390 dict.SetString("custodianUsername", custodian_username); |
| 392 } | 391 } |
| 393 } | 392 } |
| 394 #endif | 393 #endif |
| 395 | 394 |
| 396 web_ui()->CallJavascriptFunction( | 395 web_ui()->CallJavascriptFunctionUnsafe( |
| 397 "cr.webUIListenerCallback", | 396 "cr.webUIListenerCallback", |
| 398 GetWebUIListenerName(PROFILE_CREATION_SUCCESS), | 397 GetWebUIListenerName(PROFILE_CREATION_SUCCESS), dict); |
| 399 dict); | |
| 400 | 398 |
| 401 if (open_new_window) { | 399 if (open_new_window) { |
| 402 // Opening the new window must be the last action, after all callbacks | 400 // Opening the new window must be the last action, after all callbacks |
| 403 // have been run, to give them a chance to initialize the profile. | 401 // have been run, to give them a chance to initialize the profile. |
| 404 OpenNewWindowForProfile(profile, Profile::CREATE_STATUS_INITIALIZED); | 402 OpenNewWindowForProfile(profile, Profile::CREATE_STATUS_INITIALIZED); |
| 405 } | 403 } |
| 406 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 404 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 407 } | 405 } |
| 408 | 406 |
| 409 void SigninCreateProfileHandler::OpenNewWindowForProfile( | 407 void SigninCreateProfileHandler::OpenNewWindowForProfile( |
| 410 Profile* profile, | 408 Profile* profile, |
| 411 Profile::CreateStatus status) { | 409 Profile::CreateStatus status) { |
| 412 profiles::OpenBrowserWindowForProfile( | 410 profiles::OpenBrowserWindowForProfile( |
| 413 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, | 411 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, |
| 414 weak_ptr_factory_.GetWeakPtr()), | 412 weak_ptr_factory_.GetWeakPtr()), |
| 415 false, // Don't create a window if one already exists. | 413 false, // Don't create a window if one already exists. |
| 416 true, // Create a first run window. | 414 true, // Create a first run window. |
| 417 profile, | 415 profile, |
| 418 status); | 416 status); |
| 419 } | 417 } |
| 420 | 418 |
| 421 void SigninCreateProfileHandler::ShowProfileCreationError( | 419 void SigninCreateProfileHandler::ShowProfileCreationError( |
| 422 Profile* profile, | 420 Profile* profile, |
| 423 const base::string16& error) { | 421 const base::string16& error) { |
| 424 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 422 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
| 425 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | 423 web_ui()->CallJavascriptFunctionUnsafe( |
| 426 GetWebUIListenerName(PROFILE_CREATION_ERROR), | 424 "cr.webUIListenerCallback", GetWebUIListenerName(PROFILE_CREATION_ERROR), |
| 427 base::StringValue(error)); | 425 base::StringValue(error)); |
| 428 // The ProfileManager calls us back with a NULL profile in some cases. | 426 // The ProfileManager calls us back with a NULL profile in some cases. |
| 429 if (profile) { | 427 if (profile) { |
| 430 webui::DeleteProfileAtPath(profile->GetPath(), | 428 webui::DeleteProfileAtPath(profile->GetPath(), |
| 431 web_ui(), | 429 web_ui(), |
| 432 ProfileMetrics::DELETE_PROFILE_SETTINGS); | 430 ProfileMetrics::DELETE_PROFILE_SETTINGS); |
| 433 } | 431 } |
| 434 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 432 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
| 435 profile_path_being_created_.clear(); | 433 profile_path_being_created_.clear(); |
| 436 } | 434 } |
| 437 | 435 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 error_msg = GetProfileCreateErrorMessageSignin(); | 746 error_msg = GetProfileCreateErrorMessageSignin(); |
| 749 } else { | 747 } else { |
| 750 error_msg = GetProfileCreateErrorMessageRemote(); | 748 error_msg = GetProfileCreateErrorMessageRemote(); |
| 751 } | 749 } |
| 752 ShowProfileCreationError(profile, error_msg); | 750 ShowProfileCreationError(profile, error_msg); |
| 753 } | 751 } |
| 754 | 752 |
| 755 void SigninCreateProfileHandler::ShowProfileCreationWarning( | 753 void SigninCreateProfileHandler::ShowProfileCreationWarning( |
| 756 const base::string16& warning) { | 754 const base::string16& warning) { |
| 757 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); | 755 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); |
| 758 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | 756 web_ui()->CallJavascriptFunctionUnsafe( |
| 759 base::StringValue("create-profile-warning"), | 757 "cr.webUIListenerCallback", base::StringValue("create-profile-warning"), |
| 760 base::StringValue(warning)); | 758 base::StringValue(warning)); |
| 761 } | 759 } |
| 762 | 760 |
| 763 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( | 761 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( |
| 764 GoogleServiceAuthError::State error_state) { | 762 GoogleServiceAuthError::State error_state) { |
| 765 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { | 763 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { |
| 766 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", | 764 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", |
| 767 error_state, GoogleServiceAuthError::NUM_STATES); | 765 error_state, GoogleServiceAuthError::NUM_STATES); |
| 768 UMA_HISTOGRAM_MEDIUM_TIMES( | 766 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 769 "Profile.SupervisedProfileTotalCreateTime", | 767 "Profile.SupervisedProfileTotalCreateTime", |
| 770 base::TimeTicks::Now() - profile_creation_start_time_); | 768 base::TimeTicks::Now() - profile_creation_start_time_); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 796 profiles::OpenBrowserWindowForProfile( | 794 profiles::OpenBrowserWindowForProfile( |
| 797 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, | 795 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, |
| 798 weak_ptr_factory_.GetWeakPtr()), | 796 weak_ptr_factory_.GetWeakPtr()), |
| 799 false, // Don't create a window if one already exists. | 797 false, // Don't create a window if one already exists. |
| 800 true, // Create a first run window. | 798 true, // Create a first run window. |
| 801 profile, | 799 profile, |
| 802 Profile::CREATE_STATUS_INITIALIZED); | 800 Profile::CREATE_STATUS_INITIALIZED); |
| 803 } | 801 } |
| 804 | 802 |
| 805 #endif | 803 #endif |
| OLD | NEW |