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

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: Respond to achuithb's comment Created 5 years, 2 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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 const base::ListValue* args) { 557 const base::ListValue* args) {
554 std::string email; 558 std::string email;
555 CHECK(args->GetString(0, &email)); 559 CHECK(args->GetString(0, &email));
556 SetAuthType( 560 SetAuthType(
557 email, 561 email,
558 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, 562 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD,
559 base::string16()); 563 base::string16());
560 HideUserPodCustomIcon(email); 564 HideUserPodCustomIcon(email);
561 } 565 }
562 566
567 void UserManagerScreenHandler::HandleRemoveUserWarningLoadStats(
568 const base::ListValue* args) {
569 const base::Value* profile_path_value;
570
571 if (!args->Get(0, &profile_path_value))
572 return;
573
574 base::FilePath profile_path;
575
576 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path))
577 return;
578
579 base::StringValue return_profile_path(profile_path.value());
580 Profile* profile = g_browser_process->profile_manager()->
581 GetProfileByPath(profile_path);
582
583 if (!profile)
584 return;
585
586 profiles::GetProfileStatistics(
587 profile,
588 base::Bind(
589 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback,
590 weak_ptr_factory_.GetWeakPtr(), profile_path),
591 &tracker_);
592 }
593
594 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback(
595 base::FilePath profile_path,
596 profiles::ProfileCategoryStats result) {
597 // Copy result into return_value.
598 base::StringValue return_profile_path(profile_path.value());
599 base::DictionaryValue return_value;
600 for (const auto& item : result) {
601 base::DictionaryValue* stat = new base::DictionaryValue();
602 stat->SetIntegerWithoutPathExpansion("count", item.count);
603 stat->SetBooleanWithoutPathExpansion("success", item.success);
604 return_value.SetWithoutPathExpansion(item.category, stat);
605 }
606 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog",
607 return_profile_path, return_value);
608 }
609
610 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage(
611 const base::ListValue* args) {
612 const base::DictionaryValue* arg;
613 if (!args->GetDictionary(0, &arg))
614 return;
615
616 std::string profile_path("");
617 bool is_synced_user = false;
618 bool has_errors = false;
619
620 if (!arg->GetString("profilePath", &profile_path) ||
621 !arg->GetBoolean("isSyncedUser", &is_synced_user) ||
622 !arg->GetBoolean("hasErrors", &has_errors))
623 return;
624
625 int total_count = 0;
626 if (!arg->GetInteger("totalCount", &total_count))
627 return;
628
629 int message_id = is_synced_user ?
630 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_WITH_ERRORS :
631 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC) :
632 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_WITH_ERRORS :
633 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC);
634
635 base::StringValue message = base::StringValue(
636 l10n_util::GetPluralStringFUTF16(message_id, total_count));
637
638 web_ui()->CallJavascriptFunction("updateRemoveWarningDialogSetMessage",
639 base::StringValue(profile_path),
640 message,
641 base::FundamentalValue(total_count));
642 }
643
563 void UserManagerScreenHandler::OnGetTokenInfoResponse( 644 void UserManagerScreenHandler::OnGetTokenInfoResponse(
564 scoped_ptr<base::DictionaryValue> token_info) { 645 scoped_ptr<base::DictionaryValue> token_info) {
565 // Password is unchanged so user just mistyped it. Ask again. 646 // Password is unchanged so user just mistyped it. Ask again.
566 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); 647 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED);
567 } 648 }
568 649
569 void UserManagerScreenHandler::OnOAuthError() { 650 void UserManagerScreenHandler::OnOAuthError() {
570 // Password has changed. Go through online signin flow. 651 // Password has changed. Go through online signin flow.
571 DCHECK(!email_address_.empty()); 652 DCHECK(!email_address_.empty());
572 oauth_client_.reset(); 653 oauth_client_.reset();
(...skipping 24 matching lines...) Expand all
597 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, 678 base::Bind(&UserManagerScreenHandler::HandleLaunchUser,
598 base::Unretained(this))); 679 base::Unretained(this)));
599 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, 680 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser,
600 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, 681 base::Bind(&UserManagerScreenHandler::HandleRemoveUser,
601 base::Unretained(this))); 682 base::Unretained(this)));
602 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, 683 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock,
603 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, 684 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock,
604 base::Unretained(this))); 685 base::Unretained(this)));
605 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, 686 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown,
606 base::Bind(&HandleLogRemoveUserWarningShown)); 687 base::Bind(&HandleLogRemoveUserWarningShown));
688 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUserWarningLoadStats,
689 base::Bind(&UserManagerScreenHandler::HandleRemoveUserWarningLoadStats,
690 base::Unretained(this)));
691 web_ui()->RegisterMessageCallback(
692 kJsApiUserManagerGetRemoveWarningDialogMessage,
693 base::Bind(&UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage,
694 base::Unretained(this)));
607 695
608 const content::WebUI::MessageCallback& kDoNothingCallback = 696 const content::WebUI::MessageCallback& kDoNothingCallback =
609 base::Bind(&HandleAndDoNothing); 697 base::Bind(&HandleAndDoNothing);
610 698
611 // Unused callbacks from screen_account_picker.js 699 // Unused callbacks from screen_account_picker.js
612 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); 700 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback);
613 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); 701 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback);
614 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); 702 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback);
615 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); 703 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback);
616 // Unused callbacks from display_manager.js 704 // Unused callbacks from display_manager.js
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); 741 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME));
654 localized_strings->SetString("removeUser", 742 localized_strings->SetString("removeUser",
655 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); 743 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON));
656 localized_strings->SetString("passwordFieldAccessibleName", 744 localized_strings->SetString("passwordFieldAccessibleName",
657 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); 745 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME));
658 localized_strings->SetString("bootIntoWallpaper", "off"); 746 localized_strings->SetString("bootIntoWallpaper", "off");
659 747
660 // For AccountPickerScreen, the remove user warning overlay. 748 // For AccountPickerScreen, the remove user warning overlay.
661 localized_strings->SetString("removeUserWarningButtonTitle", 749 localized_strings->SetString("removeUserWarningButtonTitle",
662 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); 750 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON));
663 localized_strings->SetString("removeUserWarningText", 751 localized_strings->SetString("removeUserWarningTextNonSyncNoStats",
664 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING)); 752 l10n_util::GetStringUTF16(
753 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_NOSTATS));
754 localized_strings->SetString("removeUserWarningTextNonSyncCalculating",
755 l10n_util::GetStringUTF16(
756 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_CALCULATING));
757 localized_strings->SetString("removeUserWarningTextHistory",
758 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_HISTORY));
759 localized_strings->SetString("removeUserWarningTextPasswords",
760 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_PASSWORDS));
761 localized_strings->SetString("removeUserWarningTextBookmarks",
762 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BOOKMARKS));
763 localized_strings->SetString("removeUserWarningTextSettings",
764 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SETTINGS));
765 localized_strings->SetString("removeUserWarningTextCalculating",
766 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_CALCULATING));
767 localized_strings->SetString("removeUserWarningTextSyncNoStats",
768 l10n_util::GetStringUTF16(
769 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_NOSTATS));
770 localized_strings->SetString("removeUserWarningTextSyncCalculating",
771 l10n_util::GetStringUTF16(
772 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_CALCULATING));
665 localized_strings->SetString("removeLegacySupervisedUserWarningText", 773 localized_strings->SetString("removeLegacySupervisedUserWarningText",
666 l10n_util::GetStringFUTF16( 774 l10n_util::GetStringFUTF16(
667 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, 775 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING,
668 base::UTF8ToUTF16( 776 base::UTF8ToUTF16(
669 chrome::kLegacySupervisedUserManagementDisplayURL))); 777 chrome::kLegacySupervisedUserManagementDisplayURL)));
670 778
671 // Strings needed for the User Manager tutorial slides. 779 // Strings needed for the User Manager tutorial slides.
672 localized_strings->SetString("tutorialNext", 780 localized_strings->SetString("tutorialNext",
673 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); 781 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT));
674 localized_strings->SetString("tutorialDone", 782 localized_strings->SetString("tutorialDone",
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); 870 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i));
763 profile_value->SetBoolean( 871 profile_value->SetBoolean(
764 kKeyHasLocalCreds, 872 kKeyHasLocalCreds,
765 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); 873 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty());
766 profile_value->SetBoolean(kKeyIsOwner, false); 874 profile_value->SetBoolean(kKeyIsOwner, false);
767 profile_value->SetBoolean(kKeyCanRemove, can_remove); 875 profile_value->SetBoolean(kKeyCanRemove, can_remove);
768 profile_value->SetBoolean(kKeyIsDesktop, true); 876 profile_value->SetBoolean(kKeyIsDesktop, true);
769 profile_value->SetString( 877 profile_value->SetString(
770 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); 878 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache));
771 879
880 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL
881 // otherwise.
882 Profile* profile =
883 g_browser_process->profile_manager()->GetProfileByPath(profile_path);
884 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr);
885
772 users_list.Append(profile_value); 886 users_list.Append(profile_value);
773 } 887 }
774 888
775 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", 889 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers",
776 users_list, base::FundamentalValue(IsGuestModeEnabled())); 890 users_list, base::FundamentalValue(IsGuestModeEnabled()));
777 891
778 // This is the latest C++ code we have in the flow to show the UserManager. 892 // This is the latest C++ code we have in the flow to show the UserManager.
779 // This may be invoked more than once per UserManager lifetime; the 893 // This may be invoked more than once per UserManager lifetime; the
780 // UserManager will ensure all relevant logging only happens once. 894 // UserManager will ensure all relevant logging only happens once.
781 UserManager::OnUserManagerShown(); 895 UserManager::OnUserManagerShown();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 Profile* profile, Profile::CreateStatus profile_create_status) { 973 Profile* profile, Profile::CreateStatus profile_create_status) {
860 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); 974 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_);
861 if (browser && browser->window()) { 975 if (browser && browser->window()) {
862 OnBrowserWindowReady(browser); 976 OnBrowserWindowReady(browser);
863 } else { 977 } else {
864 registrar_.Add(this, 978 registrar_.Add(this,
865 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 979 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
866 content::NotificationService::AllSources()); 980 content::NotificationService::AllSources());
867 } 981 }
868 } 982 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/user_manager_screen_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698