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

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

Issue 1579433002: Make profile statistics tasks inspectable by tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed ProfileAttributesStorage related functions in profile_statistics.* Created 4 years, 9 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
« no previous file with comments | « chrome/browser/profiles/profile_statistics_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/profiler/scoped_tracker.h" 14 #include "base/profiler/scoped_tracker.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "base/value_conversions.h" 18 #include "base/value_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" 22 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_attributes_entry.h" 24 #include "chrome/browser/profiles/profile_attributes_entry.h"
25 #include "chrome/browser/profiles/profile_attributes_storage.h" 25 #include "chrome/browser/profiles/profile_attributes_storage.h"
26 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 26 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
27 #include "chrome/browser/profiles/profile_manager.h" 27 #include "chrome/browser/profiles/profile_manager.h"
28 #include "chrome/browser/profiles/profile_metrics.h" 28 #include "chrome/browser/profiles/profile_metrics.h"
29 #include "chrome/browser/profiles/profile_statistics.h" 29 #include "chrome/browser/profiles/profile_statistics.h"
30 #include "chrome/browser/profiles/profile_statistics_factory.h"
30 #include "chrome/browser/profiles/profile_window.h" 31 #include "chrome/browser/profiles/profile_window.h"
31 #include "chrome/browser/profiles/profiles_state.h" 32 #include "chrome/browser/profiles/profiles_state.h"
32 #include "chrome/browser/signin/local_auth.h" 33 #include "chrome/browser/signin/local_auth.h"
33 #include "chrome/browser/ui/app_list/app_list_service.h" 34 #include "chrome/browser/ui/app_list/app_list_service.h"
34 #include "chrome/browser/ui/browser_commands.h" 35 #include "chrome/browser/ui/browser_commands.h"
35 #include "chrome/browser/ui/browser_dialogs.h" 36 #include "chrome/browser/ui/browser_dialogs.h"
36 #include "chrome/browser/ui/browser_finder.h" 37 #include "chrome/browser/ui/browser_finder.h"
37 #include "chrome/browser/ui/browser_list.h" 38 #include "chrome/browser/ui/browser_list.h"
38 #include "chrome/browser/ui/browser_list_observer.h" 39 #include "chrome/browser/ui/browser_list_observer.h"
39 #include "chrome/browser/ui/chrome_pages.h" 40 #include "chrome/browser/ui/chrome_pages.h"
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 560
560 if (!chrome::FindAnyBrowser(profile, true)) { 561 if (!chrome::FindAnyBrowser(profile, true)) {
561 // If no windows are open for that profile, the statistics in 562 // If no windows are open for that profile, the statistics in
562 // ProfileAttributesStorage are up to date. The statistics in 563 // ProfileAttributesStorage are up to date. The statistics in
563 // ProfileAttributesStorage are returned because the copy in user_pod_row.js 564 // ProfileAttributesStorage are returned because the copy in user_pod_row.js
564 // may be outdated. However, if some statistics are missing in 565 // may be outdated. However, if some statistics are missing in
565 // ProfileAttributesStorage (i.e. |item.success| is false), then the actual 566 // ProfileAttributesStorage (i.e. |item.success| is false), then the actual
566 // statistics are queried instead. 567 // statistics are queried instead.
567 base::DictionaryValue return_value; 568 base::DictionaryValue return_value;
568 profiles::ProfileCategoryStats stats = 569 profiles::ProfileCategoryStats stats =
569 profiles::GetProfileStatisticsFromCache(profile_path); 570 ProfileStatistics::GetProfileStatisticsFromAttributesStorage(
571 profile_path);
570 bool stats_success = true; 572 bool stats_success = true;
571 for (const auto& item : stats) { 573 for (const auto& item : stats) {
572 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue); 574 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
573 stat->SetIntegerWithoutPathExpansion("count", item.count); 575 stat->SetIntegerWithoutPathExpansion("count", item.count);
574 stat->SetBooleanWithoutPathExpansion("success", item.success); 576 stat->SetBooleanWithoutPathExpansion("success", item.success);
575 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); 577 return_value.SetWithoutPathExpansion(item.category, std::move(stat));
576 stats_success &= item.success; 578 stats_success &= item.success;
577 } 579 }
578 if (stats_success) { 580 if (stats_success) {
579 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", 581 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog",
580 base::StringValue(profile_path.value()), 582 base::StringValue(profile_path.value()),
581 return_value); 583 return_value);
582 return; 584 return;
583 } 585 }
584 } 586 }
585 587
586 profiles::GatherProfileStatistics( 588 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics(
587 profile,
588 base::Bind( 589 base::Bind(
589 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, 590 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback,
590 weak_ptr_factory_.GetWeakPtr(), profile_path), 591 weak_ptr_factory_.GetWeakPtr(), profile_path));
591 &tracker_);
592 } 592 }
593 593
594 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( 594 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback(
595 base::FilePath profile_path, 595 base::FilePath profile_path,
596 profiles::ProfileCategoryStats result) { 596 profiles::ProfileCategoryStats result) {
597 // Copy result into return_value. 597 // Copy result into return_value.
598 base::DictionaryValue return_value; 598 base::DictionaryValue return_value;
599 for (const auto& item : result) { 599 for (const auto& item : result) {
600 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue); 600 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
601 stat->SetIntegerWithoutPathExpansion("count", item.count); 601 stat->SetIntegerWithoutPathExpansion("count", item.count);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 profile_value->SetBoolean(kKeyChildUser, entry->IsChild()); 865 profile_value->SetBoolean(kKeyChildUser, entry->IsChild());
866 profile_value->SetBoolean(kKeyNeedsSignin, entry->IsSigninRequired()); 866 profile_value->SetBoolean(kKeyNeedsSignin, entry->IsSigninRequired());
867 profile_value->SetBoolean(kKeyHasLocalCreds, 867 profile_value->SetBoolean(kKeyHasLocalCreds,
868 !entry->GetLocalAuthCredentials().empty()); 868 !entry->GetLocalAuthCredentials().empty());
869 profile_value->SetBoolean(kKeyIsOwner, false); 869 profile_value->SetBoolean(kKeyIsOwner, false);
870 profile_value->SetBoolean(kKeyCanRemove, can_remove); 870 profile_value->SetBoolean(kKeyCanRemove, can_remove);
871 profile_value->SetBoolean(kKeyIsDesktop, true); 871 profile_value->SetBoolean(kKeyIsDesktop, true);
872 profile_value->SetString(kKeyAvatarUrl, GetAvatarImage(entry)); 872 profile_value->SetString(kKeyAvatarUrl, GetAvatarImage(entry));
873 873
874 profiles::ProfileCategoryStats stats = 874 profiles::ProfileCategoryStats stats =
875 profiles::GetProfileStatisticsFromCache(profile_path); 875 ProfileStatistics::GetProfileStatisticsFromAttributesStorage(
876 profile_path);
876 scoped_ptr<base::DictionaryValue> stats_dict(new base::DictionaryValue); 877 scoped_ptr<base::DictionaryValue> stats_dict(new base::DictionaryValue);
877 for (const auto& item : stats) { 878 for (const auto& item : stats) {
878 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue); 879 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
879 stat->SetIntegerWithoutPathExpansion("count", item.count); 880 stat->SetIntegerWithoutPathExpansion("count", item.count);
880 stat->SetBooleanWithoutPathExpansion("success", item.success); 881 stat->SetBooleanWithoutPathExpansion("success", item.success);
881 stats_dict->SetWithoutPathExpansion(item.category, std::move(stat)); 882 stats_dict->SetWithoutPathExpansion(item.category, std::move(stat));
882 } 883 }
883 profile_value->SetWithoutPathExpansion(kKeyStatistics, 884 profile_value->SetWithoutPathExpansion(kKeyStatistics,
884 std::move(stats_dict)); 885 std::move(stats_dict));
885 886
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 Profile* profile, Profile::CreateStatus profile_create_status) { 979 Profile* profile, Profile::CreateStatus profile_create_status) {
979 Browser* browser = chrome::FindAnyBrowser(profile, false); 980 Browser* browser = chrome::FindAnyBrowser(profile, false);
980 if (browser && browser->window()) { 981 if (browser && browser->window()) {
981 OnBrowserWindowReady(browser); 982 OnBrowserWindowReady(browser);
982 } else { 983 } else {
983 registrar_.Add(this, 984 registrar_.Add(this,
984 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 985 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
985 content::NotificationService::AllSources()); 986 content::NotificationService::AllSources());
986 } 987 }
987 } 988 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_statistics_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698