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

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

Powered by Google App Engine
This is Rietveld 408576698