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

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

Issue 1428973003: Utilize ProfileInfoCache to support data type counts in profile deletion flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments Created 5 years 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"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/value_conversions.h" 14 #include "base/value_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" 18 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 20 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
21 #include "chrome/browser/profiles/profile_info_cache.h" 21 #include "chrome/browser/profiles/profile_info_cache.h"
22 #include "chrome/browser/profiles/profile_info_cache_observer.h" 22 #include "chrome/browser/profiles/profile_info_cache_observer.h"
23 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/profiles/profile_metrics.h" 24 #include "chrome/browser/profiles/profile_metrics.h"
25 #include "chrome/browser/profiles/profile_statistics.h"
25 #include "chrome/browser/profiles/profile_window.h" 26 #include "chrome/browser/profiles/profile_window.h"
26 #include "chrome/browser/profiles/profiles_state.h" 27 #include "chrome/browser/profiles/profiles_state.h"
27 #include "chrome/browser/signin/local_auth.h" 28 #include "chrome/browser/signin/local_auth.h"
28 #include "chrome/browser/ui/app_list/app_list_service.h" 29 #include "chrome/browser/ui/app_list/app_list_service.h"
29 #include "chrome/browser/ui/browser_commands.h" 30 #include "chrome/browser/ui/browser_commands.h"
30 #include "chrome/browser/ui/browser_dialogs.h" 31 #include "chrome/browser/ui/browser_dialogs.h"
31 #include "chrome/browser/ui/browser_finder.h" 32 #include "chrome/browser/ui/browser_finder.h"
32 #include "chrome/browser/ui/browser_list.h" 33 #include "chrome/browser/ui/browser_list.h"
33 #include "chrome/browser/ui/browser_list_observer.h" 34 #include "chrome/browser/ui/browser_list_observer.h"
34 #include "chrome/browser/ui/chrome_pages.h" 35 #include "chrome/browser/ui/chrome_pages.h"
(...skipping 29 matching lines...) Expand all
64 const char kKeyProfilePath[] = "profilePath"; 65 const char kKeyProfilePath[] = "profilePath";
65 const char kKeyPublicAccount[] = "publicAccount"; 66 const char kKeyPublicAccount[] = "publicAccount";
66 const char kKeyLegacySupervisedUser[] = "legacySupervisedUser"; 67 const char kKeyLegacySupervisedUser[] = "legacySupervisedUser";
67 const char kKeyChildUser[] = "childUser"; 68 const char kKeyChildUser[] = "childUser";
68 const char kKeyCanRemove[] = "canRemove"; 69 const char kKeyCanRemove[] = "canRemove";
69 const char kKeyIsOwner[] = "isOwner"; 70 const char kKeyIsOwner[] = "isOwner";
70 const char kKeyIsDesktop[] = "isDesktopUser"; 71 const char kKeyIsDesktop[] = "isDesktopUser";
71 const char kKeyAvatarUrl[] = "userImage"; 72 const char kKeyAvatarUrl[] = "userImage";
72 const char kKeyNeedsSignin[] = "needsSignin"; 73 const char kKeyNeedsSignin[] = "needsSignin";
73 const char kKeyHasLocalCreds[] = "hasLocalCreds"; 74 const char kKeyHasLocalCreds[] = "hasLocalCreds";
75 const char kKeyStatistics[] = "statistics";
74 const char kKeyIsProfileLoaded[] = "isProfileLoaded"; 76 const char kKeyIsProfileLoaded[] = "isProfileLoaded";
75 77
76 // JS API callback names. 78 // JS API callback names.
77 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; 79 const char kJsApiUserManagerInitialize[] = "userManagerInitialize";
78 const char kJsApiUserManagerAddUser[] = "addUser"; 80 const char kJsApiUserManagerAddUser[] = "addUser";
79 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; 81 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser";
80 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; 82 const char kJsApiUserManagerLaunchGuest[] = "launchGuest";
81 const char kJsApiUserManagerLaunchUser[] = "launchUser"; 83 const char kJsApiUserManagerLaunchUser[] = "launchUser";
82 const char kJsApiUserManagerRemoveUser[] = "removeUser"; 84 const char kJsApiUserManagerRemoveUser[] = "removeUser";
83 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; 85 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock";
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) 578 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path))
577 return; 579 return;
578 580
579 base::StringValue return_profile_path(profile_path.value()); 581 base::StringValue return_profile_path(profile_path.value());
580 Profile* profile = g_browser_process->profile_manager()-> 582 Profile* profile = g_browser_process->profile_manager()->
581 GetProfileByPath(profile_path); 583 GetProfileByPath(profile_path);
582 584
583 if (!profile) 585 if (!profile)
584 return; 586 return;
585 587
588 if (!chrome::FindBrowserWithProfile(profile, desktop_type_)) {
589 // If no windows are open for that profile, the statistics in
590 // ProfileInfoCache are up to date. The statistics in ProfileInfoCache are
591 // returned because the copy in user_pod_row.js may be outdated. However, if
592 // some statistics are missing in ProfileInfoCache (i.e. |item.success| is
593 // false), then the actual statistics are queried instead.
594 base::DictionaryValue return_value;
595 profiles::ProfileCategoryStats stats =
596 profiles::GetProfileStatisticsFromCache(profile_path);
597 bool stats_success = true;
598 for (const auto& item : stats) {
599 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
600 stat->SetIntegerWithoutPathExpansion("count", item.count);
601 stat->SetBooleanWithoutPathExpansion("success", item.success);
602 return_value.SetWithoutPathExpansion(item.category, stat.Pass());
603 stats_success &= item.success;
604 }
605 if (stats_success) {
606 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog",
607 base::StringValue(profile_path.value()),
608 return_value);
609 return;
610 }
611 }
612
586 profiles::GetProfileStatistics( 613 profiles::GetProfileStatistics(
587 profile, 614 profile,
588 base::Bind( 615 base::Bind(
589 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, 616 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback,
590 weak_ptr_factory_.GetWeakPtr(), profile_path), 617 weak_ptr_factory_.GetWeakPtr(), profile_path),
591 &tracker_); 618 &tracker_);
592 } 619 }
593 620
594 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( 621 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback(
595 base::FilePath profile_path, 622 base::FilePath profile_path,
596 profiles::ProfileCategoryStats result) { 623 profiles::ProfileCategoryStats result) {
597 // Copy result into return_value. 624 // Copy result into return_value.
598 base::StringValue return_profile_path(profile_path.value());
599 base::DictionaryValue return_value; 625 base::DictionaryValue return_value;
600 for (const auto& item : result) { 626 for (const auto& item : result) {
601 base::DictionaryValue* stat = new base::DictionaryValue(); 627 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
602 stat->SetIntegerWithoutPathExpansion("count", item.count); 628 stat->SetIntegerWithoutPathExpansion("count", item.count);
603 stat->SetBooleanWithoutPathExpansion("success", item.success); 629 stat->SetBooleanWithoutPathExpansion("success", item.success);
604 return_value.SetWithoutPathExpansion(item.category, stat); 630 return_value.SetWithoutPathExpansion(item.category, stat.Pass());
605 } 631 }
606 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", 632 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog",
607 return_profile_path, return_value); 633 base::StringValue(profile_path.value()),
634 return_value);
608 } 635 }
609 636
610 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage( 637 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage(
611 const base::ListValue* args) { 638 const base::ListValue* args) {
612 const base::DictionaryValue* arg; 639 const base::DictionaryValue* arg;
613 if (!args->GetDictionary(0, &arg)) 640 if (!args->GetDictionary(0, &arg))
614 return; 641 return;
615 642
616 std::string profile_path(""); 643 std::string profile_path("");
617 bool is_synced_user = false; 644 bool is_synced_user = false;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); 897 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i));
871 profile_value->SetBoolean( 898 profile_value->SetBoolean(
872 kKeyHasLocalCreds, 899 kKeyHasLocalCreds,
873 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); 900 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty());
874 profile_value->SetBoolean(kKeyIsOwner, false); 901 profile_value->SetBoolean(kKeyIsOwner, false);
875 profile_value->SetBoolean(kKeyCanRemove, can_remove); 902 profile_value->SetBoolean(kKeyCanRemove, can_remove);
876 profile_value->SetBoolean(kKeyIsDesktop, true); 903 profile_value->SetBoolean(kKeyIsDesktop, true);
877 profile_value->SetString( 904 profile_value->SetString(
878 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); 905 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache));
879 906
907 profiles::ProfileCategoryStats stats =
908 profiles::GetProfileStatisticsFromCache(profile_path);
909 scoped_ptr<base::DictionaryValue> stats_dict(new base::DictionaryValue);
910 for (const auto& item : stats) {
911 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
912 stat->SetIntegerWithoutPathExpansion("count", item.count);
913 stat->SetBooleanWithoutPathExpansion("success", item.success);
914 stats_dict->SetWithoutPathExpansion(item.category, stat.Pass());
915 }
916 profile_value->SetWithoutPathExpansion(kKeyStatistics, stats_dict.Pass());
917
880 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL 918 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL
881 // otherwise. 919 // otherwise.
882 Profile* profile = 920 Profile* profile =
883 g_browser_process->profile_manager()->GetProfileByPath(profile_path); 921 g_browser_process->profile_manager()->GetProfileByPath(profile_path);
884 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr); 922 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr);
885 923
886 users_list.Append(profile_value); 924 users_list.Append(profile_value);
887 } 925 }
888 926
889 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", 927 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers",
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 Profile* profile, Profile::CreateStatus profile_create_status) { 1011 Profile* profile, Profile::CreateStatus profile_create_status) {
974 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); 1012 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_);
975 if (browser && browser->window()) { 1013 if (browser && browser->window()) {
976 OnBrowserWindowReady(browser); 1014 OnBrowserWindowReady(browser);
977 } else { 1015 } else {
978 registrar_.Add(this, 1016 registrar_.Add(this,
979 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 1017 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
980 content::NotificationService::AllSources()); 1018 content::NotificationService::AllSources());
981 } 1019 }
982 } 1020 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698