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

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

Issue 1995113002: Rename WebUI::CallJavascriptFunction to WebUI::CallJavascriptFunctionUnsafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 new base::DictionaryValue()); 184 new base::DictionaryValue());
185 avatar_info->SetString("url", profiles::GetDefaultAvatarIconUrl(i)); 185 avatar_info->SetString("url", profiles::GetDefaultAvatarIconUrl(i));
186 avatar_info->SetString( 186 avatar_info->SetString(
187 "label", 187 "label",
188 l10n_util::GetStringUTF16( 188 l10n_util::GetStringUTF16(
189 profiles::GetDefaultAvatarLabelResourceIDAtIndex(i))); 189 profiles::GetDefaultAvatarLabelResourceIDAtIndex(i)));
190 190
191 image_url_list.Append(std::move(avatar_info)); 191 image_url_list.Append(std::move(avatar_info));
192 } 192 }
193 193
194 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 194 web_ui()->CallJavascriptFunctionUnsafe(
195 base::StringValue("profile-icons-received"), 195 "cr.webUIListenerCallback", base::StringValue("profile-icons-received"),
196 image_url_list); 196 image_url_list);
197 197
198 SendNewProfileDefaults(); 198 SendNewProfileDefaults();
199 } 199 }
200 200
201 void SigninCreateProfileHandler::SendNewProfileDefaults() { 201 void SigninCreateProfileHandler::SendNewProfileDefaults() {
202 ProfileAttributesStorage& storage = 202 ProfileAttributesStorage& storage =
203 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 203 g_browser_process->profile_manager()->GetProfileAttributesStorage();
204 base::DictionaryValue profile_info; 204 base::DictionaryValue profile_info;
205 profile_info.SetString("name", storage.ChooseNameForNewProfile(0)); 205 profile_info.SetString("name", storage.ChooseNameForNewProfile(0));
206 206
207 web_ui()->CallJavascriptFunction( 207 web_ui()->CallJavascriptFunctionUnsafe(
208 "cr.webUIListenerCallback", 208 "cr.webUIListenerCallback",
209 base::StringValue("profile-defaults-received"), 209 base::StringValue("profile-defaults-received"), profile_info);
210 profile_info);
211 } 210 }
212 211
213 void SigninCreateProfileHandler::RequestSignedInProfiles( 212 void SigninCreateProfileHandler::RequestSignedInProfiles(
214 const base::ListValue* args) { 213 const base::ListValue* args) {
215 base::ListValue user_info_list; 214 base::ListValue user_info_list;
216 std::vector<ProfileAttributesEntry*> entries = 215 std::vector<ProfileAttributesEntry*> entries =
217 g_browser_process->profile_manager()-> 216 g_browser_process->profile_manager()->
218 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName(); 217 GetProfileAttributesStorage().GetAllProfilesAttributesSortedByName();
219 for (ProfileAttributesEntry* entry : entries) { 218 for (ProfileAttributesEntry* entry : entries) {
220 base::string16 username = entry->GetUserName(); 219 base::string16 username = entry->GetUserName();
221 if (username.empty()) 220 if (username.empty())
222 continue; 221 continue;
223 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); 222 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe();
224 std::unique_ptr<base::DictionaryValue> user_info( 223 std::unique_ptr<base::DictionaryValue> user_info(
225 new base::DictionaryValue()); 224 new base::DictionaryValue());
226 user_info->SetString("username", username); 225 user_info->SetString("username", username);
227 user_info->SetString("profilePath", profile_path); 226 user_info->SetString("profilePath", profile_path);
228 227
229 user_info_list.Append(std::move(user_info)); 228 user_info_list.Append(std::move(user_info));
230 } 229 }
231 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 230 web_ui()->CallJavascriptFunctionUnsafe(
232 base::StringValue("signedin-users-received"), 231 "cr.webUIListenerCallback", base::StringValue("signedin-users-received"),
233 user_info_list); 232 user_info_list);
234 } 233 }
235 234
236 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { 235 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) {
237 if (!profiles::IsMultipleProfilesEnabled()) 236 if (!profiles::IsMultipleProfilesEnabled())
238 return; 237 return;
239 238
240 // We can have only one in progress profile creation 239 // We can have only one in progress profile creation
241 // at any given moment, if new ones are initiated just 240 // at any given moment, if new ones are initiated just
242 // ignore them until we are done with the old one. 241 // ignore them until we are done with the old one.
243 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) 242 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS)
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 392
394 if (is_supervised) { 393 if (is_supervised) {
395 DCHECK(custodian_profile); 394 DCHECK(custodian_profile);
396 if (custodian_profile) { 395 if (custodian_profile) {
397 std::string custodian_username = custodian_profile->GetProfileUserName(); 396 std::string custodian_username = custodian_profile->GetProfileUserName();
398 dict.SetString("custodianUsername", custodian_username); 397 dict.SetString("custodianUsername", custodian_username);
399 } 398 }
400 } 399 }
401 #endif 400 #endif
402 401
403 web_ui()->CallJavascriptFunction( 402 web_ui()->CallJavascriptFunctionUnsafe(
404 "cr.webUIListenerCallback", 403 "cr.webUIListenerCallback",
405 GetWebUIListenerName(PROFILE_CREATION_SUCCESS), 404 GetWebUIListenerName(PROFILE_CREATION_SUCCESS), dict);
406 dict);
407 405
408 if (open_new_window) { 406 if (open_new_window) {
409 // Opening the new window must be the last action, after all callbacks 407 // Opening the new window must be the last action, after all callbacks
410 // have been run, to give them a chance to initialize the profile. 408 // have been run, to give them a chance to initialize the profile.
411 OpenNewWindowForProfile(profile, Profile::CREATE_STATUS_INITIALIZED); 409 OpenNewWindowForProfile(profile, Profile::CREATE_STATUS_INITIALIZED);
412 } 410 }
413 profile_creation_type_ = NO_CREATION_IN_PROGRESS; 411 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
414 } 412 }
415 413
416 void SigninCreateProfileHandler::OpenNewWindowForProfile( 414 void SigninCreateProfileHandler::OpenNewWindowForProfile(
417 Profile* profile, 415 Profile* profile,
418 Profile::CreateStatus status) { 416 Profile::CreateStatus status) {
419 profiles::OpenBrowserWindowForProfile( 417 profiles::OpenBrowserWindowForProfile(
420 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, 418 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback,
421 weak_ptr_factory_.GetWeakPtr()), 419 weak_ptr_factory_.GetWeakPtr()),
422 false, // Don't create a window if one already exists. 420 false, // Don't create a window if one already exists.
423 true, // Create a first run window. 421 true, // Create a first run window.
424 profile, 422 profile,
425 status); 423 status);
426 } 424 }
427 425
428 void SigninCreateProfileHandler::ShowProfileCreationError( 426 void SigninCreateProfileHandler::ShowProfileCreationError(
429 Profile* profile, 427 Profile* profile,
430 const base::string16& error) { 428 const base::string16& error) {
431 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); 429 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
432 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 430 web_ui()->CallJavascriptFunctionUnsafe(
433 GetWebUIListenerName(PROFILE_CREATION_ERROR), 431 "cr.webUIListenerCallback", GetWebUIListenerName(PROFILE_CREATION_ERROR),
434 base::StringValue(error)); 432 base::StringValue(error));
435 // The ProfileManager calls us back with a NULL profile in some cases. 433 // The ProfileManager calls us back with a NULL profile in some cases.
436 if (profile) { 434 if (profile) {
437 webui::DeleteProfileAtPath(profile->GetPath(), 435 webui::DeleteProfileAtPath(profile->GetPath(),
438 web_ui(), 436 web_ui(),
439 ProfileMetrics::DELETE_PROFILE_SETTINGS); 437 ProfileMetrics::DELETE_PROFILE_SETTINGS);
440 } 438 }
441 profile_creation_type_ = NO_CREATION_IN_PROGRESS; 439 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
442 profile_path_being_created_.clear(); 440 profile_path_being_created_.clear();
443 } 441 }
444 442
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 error_msg = GetProfileCreateErrorMessageSignin(); 753 error_msg = GetProfileCreateErrorMessageSignin();
756 } else { 754 } else {
757 error_msg = GetProfileCreateErrorMessageRemote(); 755 error_msg = GetProfileCreateErrorMessageRemote();
758 } 756 }
759 ShowProfileCreationError(profile, error_msg); 757 ShowProfileCreationError(profile, error_msg);
760 } 758 }
761 759
762 void SigninCreateProfileHandler::ShowProfileCreationWarning( 760 void SigninCreateProfileHandler::ShowProfileCreationWarning(
763 const base::string16& warning) { 761 const base::string16& warning) {
764 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); 762 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_);
765 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", 763 web_ui()->CallJavascriptFunctionUnsafe(
766 base::StringValue("create-profile-warning"), 764 "cr.webUIListenerCallback", base::StringValue("create-profile-warning"),
767 base::StringValue(warning)); 765 base::StringValue(warning));
768 } 766 }
769 767
770 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( 768 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics(
771 GoogleServiceAuthError::State error_state) { 769 GoogleServiceAuthError::State error_state) {
772 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { 770 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) {
773 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", 771 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError",
774 error_state, GoogleServiceAuthError::NUM_STATES); 772 error_state, GoogleServiceAuthError::NUM_STATES);
775 UMA_HISTOGRAM_MEDIUM_TIMES( 773 UMA_HISTOGRAM_MEDIUM_TIMES(
776 "Profile.SupervisedProfileTotalCreateTime", 774 "Profile.SupervisedProfileTotalCreateTime",
777 base::TimeTicks::Now() - profile_creation_start_time_); 775 base::TimeTicks::Now() - profile_creation_start_time_);
(...skipping 25 matching lines...) Expand all
803 profiles::OpenBrowserWindowForProfile( 801 profiles::OpenBrowserWindowForProfile(
804 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, 802 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback,
805 weak_ptr_factory_.GetWeakPtr()), 803 weak_ptr_factory_.GetWeakPtr()),
806 false, // Don't create a window if one already exists. 804 false, // Don't create a window if one already exists.
807 true, // Create a first run window. 805 true, // Create a first run window.
808 profile, 806 profile,
809 Profile::CREATE_STATUS_INITIALIZED); 807 Profile::CREATE_STATUS_INITIALIZED);
810 } 808 }
811 809
812 #endif 810 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698