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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const char kKeyProfilePath[] = "profilePath"; | 64 const char kKeyProfilePath[] = "profilePath"; |
65 const char kKeyPublicAccount[] = "publicAccount"; | 65 const char kKeyPublicAccount[] = "publicAccount"; |
66 const char kKeyLegacySupervisedUser[] = "legacySupervisedUser"; | 66 const char kKeyLegacySupervisedUser[] = "legacySupervisedUser"; |
67 const char kKeyChildUser[] = "childUser"; | 67 const char kKeyChildUser[] = "childUser"; |
68 const char kKeyCanRemove[] = "canRemove"; | 68 const char kKeyCanRemove[] = "canRemove"; |
69 const char kKeyIsOwner[] = "isOwner"; | 69 const char kKeyIsOwner[] = "isOwner"; |
70 const char kKeyIsDesktop[] = "isDesktopUser"; | 70 const char kKeyIsDesktop[] = "isDesktopUser"; |
71 const char kKeyAvatarUrl[] = "userImage"; | 71 const char kKeyAvatarUrl[] = "userImage"; |
72 const char kKeyNeedsSignin[] = "needsSignin"; | 72 const char kKeyNeedsSignin[] = "needsSignin"; |
73 const char kKeyHasLocalCreds[] = "hasLocalCreds"; | 73 const char kKeyHasLocalCreds[] = "hasLocalCreds"; |
| 74 const char kKeyStatistics[] = "statistics"; |
74 const char kKeyIsProfileLoaded[] = "isProfileLoaded"; | 75 const char kKeyIsProfileLoaded[] = "isProfileLoaded"; |
75 | 76 |
76 // JS API callback names. | 77 // JS API callback names. |
77 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; | 78 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; |
78 const char kJsApiUserManagerAddUser[] = "addUser"; | 79 const char kJsApiUserManagerAddUser[] = "addUser"; |
79 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; | 80 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; |
80 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; | 81 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; |
81 const char kJsApiUserManagerLaunchUser[] = "launchUser"; | 82 const char kJsApiUserManagerLaunchUser[] = "launchUser"; |
82 const char kJsApiUserManagerRemoveUser[] = "removeUser"; | 83 const char kJsApiUserManagerRemoveUser[] = "removeUser"; |
83 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; | 84 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | 577 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
577 return; | 578 return; |
578 | 579 |
579 base::StringValue return_profile_path(profile_path.value()); | 580 base::StringValue return_profile_path(profile_path.value()); |
580 Profile* profile = g_browser_process->profile_manager()-> | 581 Profile* profile = g_browser_process->profile_manager()-> |
581 GetProfileByPath(profile_path); | 582 GetProfileByPath(profile_path); |
582 | 583 |
583 if (!profile) | 584 if (!profile) |
584 return; | 585 return; |
585 | 586 |
586 profiles::GetProfileStatistics( | 587 if (chrome::FindBrowserWithProfile(profile, desktop_type_)) { |
587 profile, | 588 profiles::GetProfileStatistics( |
588 base::Bind( | 589 profile, |
589 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, | 590 base::Bind( |
590 weak_ptr_factory_.GetWeakPtr(), profile_path), | 591 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, |
591 &tracker_); | 592 weak_ptr_factory_.GetWeakPtr(), profile_path), |
| 593 &tracker_); |
| 594 } else { |
| 595 // If no windows are open for that profile, the statistics in |
| 596 // ProfileInfoCache are update. The statistics in ProfileInfoCache are |
| 597 // returned because the copy in user_pod_row.js may be outdated. |
| 598 ProfileInfoCache& profile_info_cache = |
| 599 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 600 ProfileAttributesEntry* entry = nullptr; |
| 601 const base::FilePath profile_path = profile->GetPath(); |
| 602 if (profile_info_cache.GetProfileAttributesWithPath(profile_path, &entry)) { |
| 603 std::map<std::string, int> stats = entry->GetAllStatistics(); |
| 604 base::DictionaryValue return_value; |
| 605 for (const auto& item : stats) { |
| 606 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue); |
| 607 stat->SetIntegerWithoutPathExpansion("count", item.second); |
| 608 stat->SetBooleanWithoutPathExpansion("success", true); |
| 609 return_value.SetWithoutPathExpansion(item.first, stat.Pass()); |
| 610 } |
| 611 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", |
| 612 base::StringValue(profile_path.value()), |
| 613 return_value); |
| 614 } |
| 615 } |
592 } | 616 } |
593 | 617 |
594 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( | 618 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( |
595 base::FilePath profile_path, | 619 base::FilePath profile_path, |
596 profiles::ProfileCategoryStats result) { | 620 profiles::ProfileCategoryStats result) { |
597 // Copy result into return_value. | 621 // Copy result into return_value. |
598 base::StringValue return_profile_path(profile_path.value()); | |
599 base::DictionaryValue return_value; | 622 base::DictionaryValue return_value; |
600 for (const auto& item : result) { | 623 for (const auto& item : result) { |
601 base::DictionaryValue* stat = new base::DictionaryValue(); | 624 scoped_ptr<base::DictionaryValue> stat(new base::DictionaryValue); |
602 stat->SetIntegerWithoutPathExpansion("count", item.count); | 625 stat->SetIntegerWithoutPathExpansion("count", item.count); |
603 stat->SetBooleanWithoutPathExpansion("success", item.success); | 626 stat->SetBooleanWithoutPathExpansion("success", item.success); |
604 return_value.SetWithoutPathExpansion(item.category, stat); | 627 return_value.SetWithoutPathExpansion(item.category, stat.Pass()); |
605 } | 628 } |
606 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", | 629 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", |
607 return_profile_path, return_value); | 630 base::StringValue(profile_path.value()), |
| 631 return_value); |
608 } | 632 } |
609 | 633 |
610 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage( | 634 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage( |
611 const base::ListValue* args) { | 635 const base::ListValue* args) { |
612 const base::DictionaryValue* arg; | 636 const base::DictionaryValue* arg; |
613 if (!args->GetDictionary(0, &arg)) | 637 if (!args->GetDictionary(0, &arg)) |
614 return; | 638 return; |
615 | 639 |
616 std::string profile_path(""); | 640 std::string profile_path(""); |
617 bool is_synced_user = false; | 641 bool is_synced_user = false; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); | 894 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); |
871 profile_value->SetBoolean( | 895 profile_value->SetBoolean( |
872 kKeyHasLocalCreds, | 896 kKeyHasLocalCreds, |
873 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); | 897 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); |
874 profile_value->SetBoolean(kKeyIsOwner, false); | 898 profile_value->SetBoolean(kKeyIsOwner, false); |
875 profile_value->SetBoolean(kKeyCanRemove, can_remove); | 899 profile_value->SetBoolean(kKeyCanRemove, can_remove); |
876 profile_value->SetBoolean(kKeyIsDesktop, true); | 900 profile_value->SetBoolean(kKeyIsDesktop, true); |
877 profile_value->SetString( | 901 profile_value->SetString( |
878 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 902 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); |
879 | 903 |
| 904 std::map<std::string, int> stats = |
| 905 info_cache->GetAllStatisticsOfProfileAtIndex(i); |
| 906 scoped_ptr<base::DictionaryValue> stats_dict(new base::DictionaryValue); |
| 907 for (const auto& stat : stats) |
| 908 stats_dict->SetIntegerWithoutPathExpansion(stat.first, stat.second); |
| 909 profile_value->SetWithoutPathExpansion(kKeyStatistics, stats_dict.Pass()); |
| 910 |
880 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL | 911 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL |
881 // otherwise. | 912 // otherwise. |
882 Profile* profile = | 913 Profile* profile = |
883 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | 914 g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
884 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr); | 915 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr); |
885 | 916 |
886 users_list.Append(profile_value); | 917 users_list.Append(profile_value); |
887 } | 918 } |
888 | 919 |
889 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 920 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 Profile* profile, Profile::CreateStatus profile_create_status) { | 1004 Profile* profile, Profile::CreateStatus profile_create_status) { |
974 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 1005 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
975 if (browser && browser->window()) { | 1006 if (browser && browser->window()) { |
976 OnBrowserWindowReady(browser); | 1007 OnBrowserWindowReady(browser); |
977 } else { | 1008 } else { |
978 registrar_.Add(this, | 1009 registrar_.Add(this, |
979 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 1010 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
980 content::NotificationService::AllSources()); | 1011 content::NotificationService::AllSources()); |
981 } | 1012 } |
982 } | 1013 } |
OLD | NEW |