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