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

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

Issue 1248613003: Issue 501916 : Add data type counts to profile deletion flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ninth draft - singular/plural strings handled correctly Created 5 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/user_manager_screen_handler.h" 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const char kKeyProfilePath[] = "profilePath"; 64 const char kKeyProfilePath[] = "profilePath";
65 const char kKeyPublicAccount[] = "publicAccount"; 65 const char kKeyPublicAccount[] = "publicAccount";
66 const char kKeyLegacySupervisedUser[] = "legacySupervisedUser"; 66 const char kKeyLegacySupervisedUser[] = "legacySupervisedUser";
67 const char kKeyChildUser[] = "childUser"; 67 const char kKeyChildUser[] = "childUser";
68 const char kKeyCanRemove[] = "canRemove"; 68 const char kKeyCanRemove[] = "canRemove";
69 const char kKeyIsOwner[] = "isOwner"; 69 const char kKeyIsOwner[] = "isOwner";
70 const char kKeyIsDesktop[] = "isDesktopUser"; 70 const char kKeyIsDesktop[] = "isDesktopUser";
71 const char kKeyAvatarUrl[] = "userImage"; 71 const char kKeyAvatarUrl[] = "userImage";
72 const char kKeyNeedsSignin[] = "needsSignin"; 72 const char kKeyNeedsSignin[] = "needsSignin";
73 const char kKeyHasLocalCreds[] = "hasLocalCreds"; 73 const char kKeyHasLocalCreds[] = "hasLocalCreds";
74 const char kKeyIsProfileLoaded[] = "isProfileLoaded";
74 75
75 // JS API callback names. 76 // JS API callback names.
76 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; 77 const char kJsApiUserManagerInitialize[] = "userManagerInitialize";
77 const char kJsApiUserManagerAddUser[] = "addUser"; 78 const char kJsApiUserManagerAddUser[] = "addUser";
78 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; 79 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser";
79 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; 80 const char kJsApiUserManagerLaunchGuest[] = "launchGuest";
80 const char kJsApiUserManagerLaunchUser[] = "launchUser"; 81 const char kJsApiUserManagerLaunchUser[] = "launchUser";
81 const char kJsApiUserManagerRemoveUser[] = "removeUser"; 82 const char kJsApiUserManagerRemoveUser[] = "removeUser";
82 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; 83 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock";
83 const char kJsApiUserManagerLogRemoveUserWarningShown[] = 84 const char kJsApiUserManagerLogRemoveUserWarningShown[] =
84 "logRemoveUserWarningShown"; 85 "logRemoveUserWarningShown";
85 86 const char kJsApiUserManagerRemoveUserWarningLoadStats[] =
87 "removeUserWarningLoadStats";
88 const char kJsApiUserManagerGetRemoveWarningDialogMessage[] =
89 "getRemoveWarningDialogMessage";
86 const size_t kAvatarIconSize = 180; 90 const size_t kAvatarIconSize = 180;
87 const int kMaxOAuthRetries = 3; 91 const int kMaxOAuthRetries = 3;
88 92
89 void HandleAndDoNothing(const base::ListValue* args) { 93 void HandleAndDoNothing(const base::ListValue* args) {
90 } 94 }
91 95
92 // This callback is run if the only profile has been deleted, and a new 96 // This callback is run if the only profile has been deleted, and a new
93 // profile has been created to replace it. 97 // profile has been created to replace it.
94 void OpenNewWindowForProfile( 98 void OpenNewWindowForProfile(
95 chrome::HostDesktopType desktop_type, 99 chrome::HostDesktopType desktop_type,
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 const base::ListValue* args) { 552 const base::ListValue* args) {
549 std::string email; 553 std::string email;
550 CHECK(args->GetString(0, &email)); 554 CHECK(args->GetString(0, &email));
551 SetAuthType( 555 SetAuthType(
552 email, 556 email,
553 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, 557 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
554 base::string16()); 558 base::string16());
555 HideUserPodCustomIcon(email); 559 HideUserPodCustomIcon(email);
556 } 560 }
557 561
562 void UserManagerScreenHandler::HandleRemoveUserWarningLoadStats(
563 const base::ListValue* args) {
564 const base::Value* profile_path_value;
565
566 if (!args->Get(0, &profile_path_value))
567 return;
568
569 base::FilePath profile_path;
570
571 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path))
572 return;
573
574 base::StringValue return_profile_path(profile_path.value());
575 Profile* profile = g_browser_process->profile_manager()->
576 GetProfileByPath(profile_path);
577
578 if (!profile)
579 return;
580
581 profiles::GetProfileStatistics(
582 profile,
583 base::Bind(
584 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback,
585 weak_ptr_factory_.GetWeakPtr(), profile_path),
586 &tracker_);
587 }
588
589 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback(
590 base::FilePath profile_path,
591 profiles::ProfileCategoryStats result) {
592 // Copy result into return_value.
593 base::StringValue return_profile_path(profile_path.value());
594 base::DictionaryValue return_value;
595 for (const auto& item : result) {
596 base::DictionaryValue* stat = new base::DictionaryValue();
597 stat->SetIntegerWithoutPathExpansion("count", item.count);
598 stat->SetBooleanWithoutPathExpansion("success", item.success);
599 return_value.SetWithoutPathExpansion(item.category, stat);
600 }
601 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog",
602 return_profile_path, return_value);
603 }
604
605 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage(
606 const base::ListValue* args) {
607 const base::DictionaryValue* arg;
608 if (!args->GetDictionary(0, &arg))
609 return;
610
611 std::string profile_path("");
Mike Lerman 2015/09/14 16:28:48 nit: No need to specify empty-string initializatio
lwchkg 2015/09/15 15:01:40 Acknowledged.
612 bool is_synced_user = false, has_errors = false, has_count = false;
613
614 if (!arg->GetString("profilePath", &profile_path) ||
615 !arg->GetBoolean("isSyncedUser", &is_synced_user) ||
616 !arg->GetBoolean("hasErrors", &has_errors) ||
617 !arg->GetBoolean("hasCount", &has_count))
618 return;
619
620 int total_count = 1234; // number for plural formating if |has_count| is false
Mike Lerman 2015/09/14 16:28:48 Please don't initialize to a random number. If the
lwchkg 2015/09/15 15:01:40 Thanks for pointing out. Looks like I've missing s
621 if (has_count && !arg->GetInteger("totalCount", &total_count))
622 return;
623
624 int message_id;
625 base::StringValue message("");
626
627 message_id = is_synced_user ?
628 (has_errors?
Mike Lerman 2015/09/14 16:28:49 space before ?
lwchkg 2015/09/15 15:01:40 Acknowledged. And this is embarrassing.
629 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_WITH_ERRORS :
630 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC) :
631 (has_errors?
632 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_WITH_ERRORS :
633 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC);
634
635 message = base::StringValue(
Mike Lerman 2015/09/14 16:28:48 just define message as base::StringValue here, on
lwchkg 2015/09/15 15:01:40 Acknowledged.
636 l10n_util::GetPluralStringFUTF16(message_id, total_count));
637
638 if (has_count) {
639 web_ui()->CallJavascriptFunction("updateRemoveWarningDialogSetMessage",
640 base::StringValue(profile_path),
641 message,
642 base::FundamentalValue(total_count));
643 } else {
644 web_ui()->CallJavascriptFunction(
645 "updateRemoveWarningDialogSetMessage",
646 base::StringValue(profile_path),
647 message,
648 base::StringValue(l10n_util::GetStringUTF16(
649 IDS_LOGIN_POD_USER_REMOVE_WARNING_CALCULATING)));
650 }
651 }
652
558 void UserManagerScreenHandler::OnGetTokenInfoResponse( 653 void UserManagerScreenHandler::OnGetTokenInfoResponse(
559 scoped_ptr<base::DictionaryValue> token_info) { 654 scoped_ptr<base::DictionaryValue> token_info) {
560 // Password is unchanged so user just mistyped it. Ask again. 655 // Password is unchanged so user just mistyped it. Ask again.
561 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); 656 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED);
562 } 657 }
563 658
564 void UserManagerScreenHandler::OnOAuthError() { 659 void UserManagerScreenHandler::OnOAuthError() {
565 // Password has changed. Go through online signin flow. 660 // Password has changed. Go through online signin flow.
566 DCHECK(!email_address_.empty()); 661 DCHECK(!email_address_.empty());
567 oauth_client_.reset(); 662 oauth_client_.reset();
(...skipping 24 matching lines...) Expand all
592 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, 687 base::Bind(&UserManagerScreenHandler::HandleLaunchUser,
593 base::Unretained(this))); 688 base::Unretained(this)));
594 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, 689 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser,
595 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, 690 base::Bind(&UserManagerScreenHandler::HandleRemoveUser,
596 base::Unretained(this))); 691 base::Unretained(this)));
597 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, 692 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock,
598 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, 693 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock,
599 base::Unretained(this))); 694 base::Unretained(this)));
600 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, 695 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown,
601 base::Bind(&HandleLogRemoveUserWarningShown)); 696 base::Bind(&HandleLogRemoveUserWarningShown));
697 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUserWarningLoadStats,
698 base::Bind(&UserManagerScreenHandler::HandleRemoveUserWarningLoadStats,
699 base::Unretained(this)));
700 web_ui()->RegisterMessageCallback(
701 kJsApiUserManagerGetRemoveWarningDialogMessage,
702 base::Bind(&UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage,
703 base::Unretained(this)));
602 704
603 const content::WebUI::MessageCallback& kDoNothingCallback = 705 const content::WebUI::MessageCallback& kDoNothingCallback =
604 base::Bind(&HandleAndDoNothing); 706 base::Bind(&HandleAndDoNothing);
605 707
606 // Unused callbacks from screen_account_picker.js 708 // Unused callbacks from screen_account_picker.js
607 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); 709 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback);
608 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); 710 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback);
609 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); 711 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback);
610 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); 712 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback);
611 // Unused callbacks from display_manager.js 713 // Unused callbacks from display_manager.js
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); 750 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME));
649 localized_strings->SetString("removeUser", 751 localized_strings->SetString("removeUser",
650 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); 752 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON));
651 localized_strings->SetString("passwordFieldAccessibleName", 753 localized_strings->SetString("passwordFieldAccessibleName",
652 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); 754 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME));
653 localized_strings->SetString("bootIntoWallpaper", "off"); 755 localized_strings->SetString("bootIntoWallpaper", "off");
654 756
655 // For AccountPickerScreen, the remove user warning overlay. 757 // For AccountPickerScreen, the remove user warning overlay.
656 localized_strings->SetString("removeUserWarningButtonTitle", 758 localized_strings->SetString("removeUserWarningButtonTitle",
657 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); 759 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON));
658 localized_strings->SetString("removeUserWarningText", 760 localized_strings->SetString("removeUserWarningTextNonSyncNoStats",
659 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING)); 761 l10n_util::GetStringUTF16(
762 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_NOSTATS));
763 localized_strings->SetString("removeUserWarningTextHistory",
764 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_HISTORY));
765 localized_strings->SetString("removeUserWarningTextPasswords",
766 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_PASSWORDS));
767 localized_strings->SetString("removeUserWarningTextBookmarks",
768 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BOOKMARKS));
769 localized_strings->SetString("removeUserWarningTextSettings",
770 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SETTINGS));
771 localized_strings->SetString("removeUserWarningTextCalculating",
772 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_CALCULATING));
773 localized_strings->SetString("removeUserWarningTextSyncNoStats",
774 l10n_util::GetStringUTF16(
775 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_NOSTATS));
660 localized_strings->SetString("removeLegacySupervisedUserWarningText", 776 localized_strings->SetString("removeLegacySupervisedUserWarningText",
661 l10n_util::GetStringFUTF16( 777 l10n_util::GetStringFUTF16(
662 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, 778 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING,
663 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL))); 779 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL)));
664 780
665 // Strings needed for the User Manager tutorial slides. 781 // Strings needed for the User Manager tutorial slides.
666 localized_strings->SetString("tutorialNext", 782 localized_strings->SetString("tutorialNext",
667 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); 783 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT));
668 localized_strings->SetString("tutorialDone", 784 localized_strings->SetString("tutorialDone",
669 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_DONE)); 785 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_DONE));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); 867 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i));
752 profile_value->SetBoolean( 868 profile_value->SetBoolean(
753 kKeyHasLocalCreds, 869 kKeyHasLocalCreds,
754 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); 870 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty());
755 profile_value->SetBoolean(kKeyIsOwner, false); 871 profile_value->SetBoolean(kKeyIsOwner, false);
756 profile_value->SetBoolean(kKeyCanRemove, can_remove); 872 profile_value->SetBoolean(kKeyCanRemove, can_remove);
757 profile_value->SetBoolean(kKeyIsDesktop, true); 873 profile_value->SetBoolean(kKeyIsDesktop, true);
758 profile_value->SetString( 874 profile_value->SetString(
759 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); 875 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache));
760 876
877 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL
878 // otherwise.
879 Profile* profile =
880 g_browser_process->profile_manager()->GetProfileByPath(profile_path);
881 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr);
882
761 users_list.Append(profile_value); 883 users_list.Append(profile_value);
762 } 884 }
763 885
764 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", 886 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers",
765 users_list, base::FundamentalValue(IsGuestModeEnabled())); 887 users_list, base::FundamentalValue(IsGuestModeEnabled()));
766 888
767 // This is the latest C++ code we have in the flow to show the UserManager. 889 // This is the latest C++ code we have in the flow to show the UserManager.
768 // This may be invoked more than once per UserManager lifetime; the 890 // This may be invoked more than once per UserManager lifetime; the
769 // UserManager will ensure all relevant logging only happens once. 891 // UserManager will ensure all relevant logging only happens once.
770 UserManager::OnUserManagerShown(); 892 UserManager::OnUserManagerShown();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 Profile* profile, Profile::CreateStatus profile_create_status) { 970 Profile* profile, Profile::CreateStatus profile_create_status) {
849 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); 971 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_);
850 if (browser && browser->window()) { 972 if (browser && browser->window()) {
851 OnBrowserWindowReady(browser); 973 OnBrowserWindowReady(browser);
852 } else { 974 } else {
853 registrar_.Add(this, 975 registrar_.Add(this,
854 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 976 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
855 content::NotificationService::AllSources()); 977 content::NotificationService::AllSources());
856 } 978 }
857 } 979 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698