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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/signin/user_manager_screen_handler.cc
diff --git a/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc b/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc
index 3fc1e82f4e9ae1b60b5cd7acb28bee5ce0b96a10..cdf2a1ae6c7e166c935535e88a8d9d21b0955f55 100644
--- a/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc
+++ b/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h"
+#include <utility>
+
#include "base/bind.h"
#include "base/location.h"
#include "base/prefs/pref_service.h"
@@ -22,6 +24,7 @@
#include "chrome/browser/profiles/profile_info_cache_observer.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
+#include "chrome/browser/profiles/profile_statistics.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/local_auth.h"
@@ -71,6 +74,7 @@ const char kKeyIsDesktop[] = "isDesktopUser";
const char kKeyAvatarUrl[] = "userImage";
const char kKeyNeedsSignin[] = "needsSignin";
const char kKeyHasLocalCreds[] = "hasLocalCreds";
+const char kKeyStatistics[] = "statistics";
const char kKeyIsProfileLoaded[] = "isProfileLoaded";
// JS API callback names.
@@ -583,7 +587,32 @@ void UserManagerScreenHandler::HandleRemoveUserWarningLoadStats(
if (!profile)
return;
- profiles::GetProfileStatistics(
+ if (!chrome::FindBrowserWithProfile(profile, desktop_type_)) {
+ // If no windows are open for that profile, the statistics in
+ // ProfileInfoCache are up to date. The statistics in ProfileInfoCache are
+ // returned because the copy in user_pod_row.js may be outdated. However, if
+ // some statistics are missing in ProfileInfoCache (i.e. |item.success| is
+ // false), then the actual statistics are queried instead.
+ base::DictionaryValue return_value;
+ profiles::ProfileCategoryStats stats =
+ profiles::GetProfileStatisticsFromCache(profile_path);
+ bool stats_success = true;
+ for (const auto& item : stats) {
+ scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
+ stat->SetIntegerWithoutPathExpansion("count", item.count);
+ stat->SetBooleanWithoutPathExpansion("success", item.success);
+ return_value.SetWithoutPathExpansion(item.category, std::move(stat));
+ stats_success &= item.success;
+ }
+ if (stats_success) {
+ web_ui()->CallJavascriptFunction("updateRemoveWarningDialog",
+ base::StringValue(profile_path.value()),
+ return_value);
+ return;
+ }
+ }
+
+ profiles::GatherProfileStatistics(
profile,
base::Bind(
&UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback,
@@ -595,16 +624,16 @@ void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback(
base::FilePath profile_path,
profiles::ProfileCategoryStats result) {
// Copy result into return_value.
- base::StringValue return_profile_path(profile_path.value());
base::DictionaryValue return_value;
for (const auto& item : result) {
- base::DictionaryValue* stat = new base::DictionaryValue();
+ scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
stat->SetIntegerWithoutPathExpansion("count", item.count);
stat->SetBooleanWithoutPathExpansion("success", item.success);
- return_value.SetWithoutPathExpansion(item.category, stat);
+ return_value.SetWithoutPathExpansion(item.category, std::move(stat));
}
web_ui()->CallJavascriptFunction("updateRemoveWarningDialog",
- return_profile_path, return_value);
+ base::StringValue(profile_path.value()),
+ return_value);
}
void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage(
@@ -877,6 +906,18 @@ void UserManagerScreenHandler::SendUserList() {
profile_value->SetString(
kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache));
+ profiles::ProfileCategoryStats stats =
+ profiles::GetProfileStatisticsFromCache(profile_path);
+ scoped_ptr<base::DictionaryValue> stats_dict(new base::DictionaryValue);
+ for (const auto& item : stats) {
+ scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
+ stat->SetIntegerWithoutPathExpansion("count", item.count);
+ stat->SetBooleanWithoutPathExpansion("success", item.success);
+ stats_dict->SetWithoutPathExpansion(item.category, std::move(stat));
+ }
+ profile_value->SetWithoutPathExpansion(kKeyStatistics,
+ std::move(stats_dict));
+
// GetProfileByPath returns a pointer if the profile is fully loaded, NULL
// otherwise.
Profile* profile =

Powered by Google App Engine
This is Rietveld 408576698