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

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: Changed gyp/gn files, also a few small changes 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
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::GetProfileStatisticsFromCache(profile_path);
570 bool stats_success = true; 571 bool stats_success = true;
571 for (const auto& item : stats) { 572 for (const auto& item : stats) {
572 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue); 573 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
573 stat->SetIntegerWithoutPathExpansion("count", item.count); 574 stat->SetIntegerWithoutPathExpansion("count", item.count);
574 stat->SetBooleanWithoutPathExpansion("success", item.success); 575 stat->SetBooleanWithoutPathExpansion("success", item.success);
575 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); 576 return_value.SetWithoutPathExpansion(item.category, std::move(stat));
576 stats_success &= item.success; 577 stats_success &= item.success;
577 } 578 }
578 if (stats_success) { 579 if (stats_success) {
579 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", 580 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog",
580 base::StringValue(profile_path.value()), 581 base::StringValue(profile_path.value()),
581 return_value); 582 return_value);
582 return; 583 return;
583 } 584 }
584 } 585 }
585 586
586 profiles::GatherProfileStatistics( 587 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics(
587 profile,
588 base::Bind( 588 base::Bind(
589 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, 589 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback,
590 weak_ptr_factory_.GetWeakPtr(), profile_path), 590 weak_ptr_factory_.GetWeakPtr(), profile_path));
591 &tracker_);
592 } 591 }
593 592
594 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( 593 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback(
595 base::FilePath profile_path, 594 base::FilePath profile_path,
596 profiles::ProfileCategoryStats result) { 595 profiles::ProfileCategoryStats result) {
597 // Copy result into return_value. 596 // Copy result into return_value.
598 base::DictionaryValue return_value; 597 base::DictionaryValue return_value;
599 for (const auto& item : result) { 598 for (const auto& item : result) {
600 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue); 599 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
601 stat->SetIntegerWithoutPathExpansion("count", item.count); 600 stat->SetIntegerWithoutPathExpansion("count", item.count);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 profile_value->SetBoolean(kKeyChildUser, entry->IsChild()); 864 profile_value->SetBoolean(kKeyChildUser, entry->IsChild());
866 profile_value->SetBoolean(kKeyNeedsSignin, entry->IsSigninRequired()); 865 profile_value->SetBoolean(kKeyNeedsSignin, entry->IsSigninRequired());
867 profile_value->SetBoolean(kKeyHasLocalCreds, 866 profile_value->SetBoolean(kKeyHasLocalCreds,
868 !entry->GetLocalAuthCredentials().empty()); 867 !entry->GetLocalAuthCredentials().empty());
869 profile_value->SetBoolean(kKeyIsOwner, false); 868 profile_value->SetBoolean(kKeyIsOwner, false);
870 profile_value->SetBoolean(kKeyCanRemove, can_remove); 869 profile_value->SetBoolean(kKeyCanRemove, can_remove);
871 profile_value->SetBoolean(kKeyIsDesktop, true); 870 profile_value->SetBoolean(kKeyIsDesktop, true);
872 profile_value->SetString(kKeyAvatarUrl, GetAvatarImage(entry)); 871 profile_value->SetString(kKeyAvatarUrl, GetAvatarImage(entry));
873 872
874 profiles::ProfileCategoryStats stats = 873 profiles::ProfileCategoryStats stats =
875 profiles::GetProfileStatisticsFromCache(profile_path); 874 ProfileStatistics::GetProfileStatisticsFromCache(profile_path);
876 scoped_ptr<base::DictionaryValue> stats_dict(new base::DictionaryValue); 875 scoped_ptr<base::DictionaryValue> stats_dict(new base::DictionaryValue);
877 for (const auto& item : stats) { 876 for (const auto& item : stats) {
878 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue); 877 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue);
879 stat->SetIntegerWithoutPathExpansion("count", item.count); 878 stat->SetIntegerWithoutPathExpansion("count", item.count);
880 stat->SetBooleanWithoutPathExpansion("success", item.success); 879 stat->SetBooleanWithoutPathExpansion("success", item.success);
881 stats_dict->SetWithoutPathExpansion(item.category, std::move(stat)); 880 stats_dict->SetWithoutPathExpansion(item.category, std::move(stat));
882 } 881 }
883 profile_value->SetWithoutPathExpansion(kKeyStatistics, 882 profile_value->SetWithoutPathExpansion(kKeyStatistics,
884 std::move(stats_dict)); 883 std::move(stats_dict));
885 884
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 Profile* profile, Profile::CreateStatus profile_create_status) { 977 Profile* profile, Profile::CreateStatus profile_create_status) {
979 Browser* browser = chrome::FindAnyBrowser(profile, false); 978 Browser* browser = chrome::FindAnyBrowser(profile, false);
980 if (browser && browser->window()) { 979 if (browser && browser->window()) {
981 OnBrowserWindowReady(browser); 980 OnBrowserWindowReady(browser);
982 } else { 981 } else {
983 registrar_.Add(this, 982 registrar_.Add(this,
984 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 983 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
985 content::NotificationService::AllSources()); 984 content::NotificationService::AllSources());
986 } 985 }
987 } 986 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698