Chromium Code Reviews| 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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/value_conversions.h" | 10 #include "base/value_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" | 14 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache.h" | 17 #include "chrome/browser/profiles/profile_info_cache.h" |
| 18 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 18 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/profiles/profile_metrics.h" | 20 #include "chrome/browser/profiles/profile_metrics.h" |
| 21 #include "chrome/browser/profiles/profile_window.h" | 21 #include "chrome/browser/profiles/profile_window.h" |
| 22 #include "chrome/browser/profiles/profiles_state.h" | 22 #include "chrome/browser/profiles/profiles_state.h" |
| 23 #include "chrome/browser/signin/local_auth.h" | 23 #include "chrome/browser/signin/local_auth.h" |
| 24 #include "chrome/browser/ui/app_list/app_list_service.h" | |
| 24 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
| 25 #include "chrome/browser/ui/browser_dialogs.h" | 26 #include "chrome/browser/ui/browser_dialogs.h" |
| 26 #include "chrome/browser/ui/browser_finder.h" | 27 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
| 29 #include "chrome/browser/ui/browser_list_observer.h" | |
| 28 #include "chrome/browser/ui/chrome_pages.h" | 30 #include "chrome/browser/ui/chrome_pages.h" |
| 29 #include "chrome/browser/ui/singleton_tabs.h" | 31 #include "chrome/browser/ui/singleton_tabs.h" |
| 30 #include "chrome/browser/ui/user_manager.h" | 32 #include "chrome/browser/ui/user_manager.h" |
| 31 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/grit/chromium_strings.h" | 35 #include "chrome/grit/chromium_strings.h" |
| 34 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
| 35 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/browser/web_ui.h" | 39 #include "content/public/browser/web_ui.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 DCHECK(service); | 138 DCHECK(service); |
| 137 return service->GetBoolean(prefs::kBrowserGuestModeEnabled); | 139 return service->GetBoolean(prefs::kBrowserGuestModeEnabled); |
| 138 } | 140 } |
| 139 | 141 |
| 140 bool IsAddPersonEnabled() { | 142 bool IsAddPersonEnabled() { |
| 141 PrefService* service = g_browser_process->local_state(); | 143 PrefService* service = g_browser_process->local_state(); |
| 142 DCHECK(service); | 144 DCHECK(service); |
| 143 return service->GetBoolean(prefs::kBrowserAddPersonEnabled); | 145 return service->GetBoolean(prefs::kBrowserAddPersonEnabled); |
| 144 } | 146 } |
| 145 | 147 |
| 148 // Executes the action specified by the URL's Hash parameter, if any. Deletes | |
| 149 // itself after the action would be performed. | |
|
tapted
2015/01/27 22:40:26
nit: now that it's base::Owned, the Closure will d
Mike Lerman
2015/01/28 20:26:46
Done.
| |
| 150 class UrlHashHelper : public chrome::BrowserListObserver { | |
| 151 public: | |
| 152 UrlHashHelper(Browser* browser, const std::string& hash); | |
| 153 ~UrlHashHelper() override; | |
| 154 | |
| 155 void ExecuteUrlHash(); | |
| 156 | |
| 157 // chrome::BrowserListObserver overrides: | |
| 158 void OnBrowserRemoved(Browser* browser) override; | |
| 159 | |
| 160 private: | |
| 161 Browser* browser_; | |
| 162 Profile* profile_; | |
| 163 chrome::HostDesktopType desktop_type_; | |
| 164 const std::string& hash_; | |
|
tapted
2015/01/27 22:40:26
This can't be const-reference, just the constructo
Mike Lerman
2015/01/28 20:26:46
Ah that makes sense. Thanks!
| |
| 165 | |
| 166 DISALLOW_COPY_AND_ASSIGN(UrlHashHelper); | |
| 167 }; | |
| 168 | |
| 169 UrlHashHelper::UrlHashHelper(Browser* browser, const std::string& hash) | |
| 170 : browser_(browser), | |
| 171 profile_(browser->profile()), | |
| 172 desktop_type_(browser->host_desktop_type()), | |
| 173 hash_(hash) { | |
| 174 BrowserList::AddObserver(this); | |
| 175 } | |
| 176 | |
| 177 UrlHashHelper::~UrlHashHelper() { | |
| 178 BrowserList::RemoveObserver(this); | |
| 179 } | |
| 180 | |
| 181 void UrlHashHelper::OnBrowserRemoved(Browser* browser) { | |
| 182 if (browser == browser_) | |
| 183 browser_ = nullptr; | |
| 184 } | |
| 185 | |
| 186 // This UrlHashHelper will be deleted after the execution of this method. | |
| 187 void UrlHashHelper::ExecuteUrlHash() { | |
| 188 if (hash_ == profiles::kUserManagerSelectProfileAppLauncher) { | |
| 189 AppListService* app_list_service = AppListService::Get(desktop_type_); | |
| 190 app_list_service->ShowForProfile(profile_); | |
| 191 return; | |
| 192 } | |
| 193 | |
| 194 Browser* target_browser = browser_; | |
| 195 if (!target_browser) { | |
| 196 target_browser = chrome::FindLastActiveWithProfile(profile_, desktop_type_); | |
| 197 if (!target_browser) | |
| 198 return; | |
| 199 } | |
| 200 | |
| 201 if (hash_ == profiles::kUserManagerSelectProfileTaskManager) | |
| 202 chrome::OpenTaskManager(target_browser); | |
| 203 else if (hash_ == profiles::kUserManagerSelectProfileAboutChrome) | |
| 204 chrome::ShowAboutChrome(target_browser); | |
| 205 else if (hash_ == profiles::kUserManagerSelectProfileChromeSettings) | |
| 206 chrome::ShowSettings(target_browser); | |
| 207 else if (hash_ == profiles::kUserManagerSelectProfileChromeMemory) | |
| 208 chrome::ShowMemory(target_browser); | |
| 209 } | |
| 210 | |
| 146 } // namespace | 211 } // namespace |
| 147 | 212 |
| 148 // ProfileUpdateObserver ------------------------------------------------------ | 213 // ProfileUpdateObserver ------------------------------------------------------ |
| 149 | 214 |
| 150 class UserManagerScreenHandler::ProfileUpdateObserver | 215 class UserManagerScreenHandler::ProfileUpdateObserver |
| 151 : public ProfileInfoCacheObserver { | 216 : public ProfileInfoCacheObserver { |
| 152 public: | 217 public: |
| 153 ProfileUpdateObserver( | 218 ProfileUpdateObserver( |
| 154 ProfileManager* profile_manager, UserManagerScreenHandler* handler) | 219 ProfileManager* profile_manager, UserManagerScreenHandler* handler) |
| 155 : profile_manager_(profile_manager), | 220 : profile_manager_(profile_manager), |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 // Unlock the profile after browser opens so startup can read the lock bit. | 772 // Unlock the profile after browser opens so startup can read the lock bit. |
| 708 // Any necessary authentication must have been successful to reach this point. | 773 // Any necessary authentication must have been successful to reach this point. |
| 709 if (!browser->profile()->IsGuestSession()) { | 774 if (!browser->profile()->IsGuestSession()) { |
| 710 ProfileInfoCache& info_cache = | 775 ProfileInfoCache& info_cache = |
| 711 g_browser_process->profile_manager()->GetProfileInfoCache(); | 776 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 712 size_t index = info_cache.GetIndexOfProfileWithPath( | 777 size_t index = info_cache.GetIndexOfProfileWithPath( |
| 713 browser->profile()->GetPath()); | 778 browser->profile()->GetPath()); |
| 714 info_cache.SetProfileSigninRequiredAtIndex(index, false); | 779 info_cache.SetProfileSigninRequiredAtIndex(index, false); |
| 715 } | 780 } |
| 716 | 781 |
| 717 if (url_hash_ == profiles::kUserManagerSelectProfileTaskManager) { | 782 if (!url_hash_.empty()) { |
| 718 base::MessageLoop::current()->PostTask( | 783 base::MessageLoop::current()->PostTask( |
| 719 FROM_HERE, base::Bind(&chrome::OpenTaskManager, browser)); | 784 FROM_HERE, |
| 720 } else if (url_hash_ == profiles::kUserManagerSelectProfileAboutChrome) { | 785 base::Bind(&UrlHashHelper::ExecuteUrlHash, |
| 721 base::MessageLoop::current()->PostTask( | 786 base::Owned(new UrlHashHelper(browser, url_hash_)))); |
| 722 FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser)); | |
| 723 } else if (url_hash_ == profiles::kUserManagerSelectProfileChromeSettings) { | |
| 724 base::MessageLoop::current()->PostTask( | |
| 725 FROM_HERE, base::Bind(&chrome::ShowSettings, browser)); | |
| 726 } else if (url_hash_ == profiles::kUserManagerSelectProfileChromeMemory) { | |
| 727 base::MessageLoop::current()->PostTask( | |
| 728 FROM_HERE, base::Bind(&chrome::ShowMemory, browser)); | |
| 729 } | 787 } |
| 730 | 788 |
| 731 // This call is last as it deletes this object. | 789 // This call is last as it deletes this object. |
| 732 UserManager::Hide(); | 790 UserManager::Hide(); |
| 733 } | 791 } |
| 734 | 792 |
| 735 void UserManagerScreenHandler::Observe( | 793 void UserManagerScreenHandler::Observe( |
| 736 int type, | 794 int type, |
| 737 const content::NotificationSource& source, | 795 const content::NotificationSource& source, |
| 738 const content::NotificationDetails& details) { | 796 const content::NotificationDetails& details) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 758 Profile* profile, Profile::CreateStatus profile_create_status) { | 816 Profile* profile, Profile::CreateStatus profile_create_status) { |
| 759 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 817 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
| 760 if (browser && browser->window()) { | 818 if (browser && browser->window()) { |
| 761 OnBrowserWindowReady(browser); | 819 OnBrowserWindowReady(browser); |
| 762 } else { | 820 } else { |
| 763 registrar_.Add(this, | 821 registrar_.Add(this, |
| 764 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 822 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 765 content::NotificationService::AllSources()); | 823 content::NotificationService::AllSources()); |
| 766 } | 824 } |
| 767 } | 825 } |
| OLD | NEW |