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

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

Issue 856733004: Loading the Launcher with a Locked Profile launched UserManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 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 "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
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 class UrlHashHelper : public chrome::BrowserListObserver {
tapted 2015/01/27 02:52:55 add a brief comment, it should say something about
Mike Lerman 2015/01/27 14:59:49 Comment added. It's called a "hash" because that'
149 public:
150 UrlHashHelper(
151 Browser* browser, chrome::HostDesktopType desktop_type, std::string hash);
tapted 2015/01/27 02:52:55 const reference `hash`
Mike Lerman 2015/01/27 14:59:49 Done.
152 ~UrlHashHelper() override;
153
154 void ExecuteUrlHash();
155
156 // chrome::BrowserListObserver overrides:
157 void OnBrowserRemoved(Browser* browser) override;
158
159 private:
160 Browser* browser_;
161 Profile* profile_;
162 chrome::HostDesktopType desktop_type_;
163 std::string hash_;
164 };
tapted 2015/01/27 02:52:55 nit: DISALLOW_COPY_AND_ASSIGN
Mike Lerman 2015/01/27 14:59:49 Done.
165
166 UrlHashHelper::UrlHashHelper(
167 Browser* browser, chrome::HostDesktopType desktop_type, std::string hash)
168 : browser_(browser),
169 profile_(browser->profile()),
170 desktop_type_(desktop_type),
tapted 2015/01/27 02:52:55 Note there's also browser->host_desktop_type(), wh
Mike Lerman 2015/01/27 14:59:49 SGTM. Done.
171 hash_(hash) {
172 BrowserList::AddObserver(this);
173 }
174
175 UrlHashHelper::~UrlHashHelper() {
176 BrowserList::RemoveObserver(this);
177 }
178
179 void UrlHashHelper::OnBrowserRemoved(Browser* browser) {
180 if (browser == browser_)
181 browser_ = NULL;
tapted 2015/01/27 02:52:55 nit: NULL -> nullptr.
Mike Lerman 2015/01/27 14:59:49 Done.
182 }
183
184 void UrlHashHelper::ExecuteUrlHash() {
185 if (browser_ == NULL)
tapted 2015/01/27 02:52:55 NULL -> nullptr; or, I'd probably go just `if (!b
Mike Lerman 2015/01/27 14:59:49 Done. I like that better, too :)
186 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_);
187
188 if (browser_ != NULL) {
189 if (hash_ == profiles::kUserManagerSelectProfileTaskManager) {
190 chrome::OpenTaskManager(browser_);
191 } else if (hash_ == profiles::kUserManagerSelectProfileAboutChrome) {
192 chrome::ShowAboutChrome(browser_);
193 } else if (hash_ == profiles::kUserManagerSelectProfileChromeSettings) {
194 chrome::ShowSettings(browser_);
195 } else if (hash_ == profiles::kUserManagerSelectProfileChromeMemory) {
196 chrome::ShowMemory(browser_);
197 }
198 }
199
200 if (hash_ == profiles::kUserManagerSelectProfileAppLauncher) {
201 AppListService* app_list_service = AppListService::Get(desktop_type_);
tapted 2015/01/27 02:52:55 note this desktop_type_ can be different to |brows
tapted 2015/01/27 02:56:36 uh.. to the `top` that was going to say (but I tho
Mike Lerman 2015/01/27 14:59:49 Done.
Mike Lerman 2015/01/27 14:59:49 Done.
202 app_list_service->ShowForProfile(profile_);
203 }
204
205 delete this;
tapted 2015/01/27 02:52:55 Using base::Owned(..) rather than base::Unretained
Mike Lerman 2015/01/27 14:59:49 So base::Owned will take care of deleting the obje
tapted 2015/01/27 22:55:01 btw this is documented in base/bind_helpers.h but
206 }
207
146 } // namespace 208 } // namespace
147 209
148 // ProfileUpdateObserver ------------------------------------------------------ 210 // ProfileUpdateObserver ------------------------------------------------------
149 211
150 class UserManagerScreenHandler::ProfileUpdateObserver 212 class UserManagerScreenHandler::ProfileUpdateObserver
151 : public ProfileInfoCacheObserver { 213 : public ProfileInfoCacheObserver {
152 public: 214 public:
153 ProfileUpdateObserver( 215 ProfileUpdateObserver(
154 ProfileManager* profile_manager, UserManagerScreenHandler* handler) 216 ProfileManager* profile_manager, UserManagerScreenHandler* handler)
155 : profile_manager_(profile_manager), 217 : profile_manager_(profile_manager),
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 // Unlock the profile after browser opens so startup can read the lock bit. 769 // 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. 770 // Any necessary authentication must have been successful to reach this point.
709 if (!browser->profile()->IsGuestSession()) { 771 if (!browser->profile()->IsGuestSession()) {
710 ProfileInfoCache& info_cache = 772 ProfileInfoCache& info_cache =
711 g_browser_process->profile_manager()->GetProfileInfoCache(); 773 g_browser_process->profile_manager()->GetProfileInfoCache();
712 size_t index = info_cache.GetIndexOfProfileWithPath( 774 size_t index = info_cache.GetIndexOfProfileWithPath(
713 browser->profile()->GetPath()); 775 browser->profile()->GetPath());
714 info_cache.SetProfileSigninRequiredAtIndex(index, false); 776 info_cache.SetProfileSigninRequiredAtIndex(index, false);
715 } 777 }
716 778
717 if (url_hash_ == profiles::kUserManagerSelectProfileTaskManager) { 779 if (!url_hash_.empty()) {
718 base::MessageLoop::current()->PostTask( 780 base::MessageLoop::current()->PostTask(
719 FROM_HERE, base::Bind(&chrome::OpenTaskManager, browser)); 781 FROM_HERE,
720 } else if (url_hash_ == profiles::kUserManagerSelectProfileAboutChrome) { 782 base::Bind(&UrlHashHelper::ExecuteUrlHash,
721 base::MessageLoop::current()->PostTask( 783 base::Unretained(new UrlHashHelper(browser,
722 FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser)); 784 desktop_type_,
723 } else if (url_hash_ == profiles::kUserManagerSelectProfileChromeSettings) { 785 url_hash_))));
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 } 786 }
730 787
731 // This call is last as it deletes this object. 788 // This call is last as it deletes this object.
732 UserManager::Hide(); 789 UserManager::Hide();
733 } 790 }
734 791
735 void UserManagerScreenHandler::Observe( 792 void UserManagerScreenHandler::Observe(
736 int type, 793 int type,
737 const content::NotificationSource& source, 794 const content::NotificationSource& source,
738 const content::NotificationDetails& details) { 795 const content::NotificationDetails& details) {
(...skipping 19 matching lines...) Expand all
758 Profile* profile, Profile::CreateStatus profile_create_status) { 815 Profile* profile, Profile::CreateStatus profile_create_status) {
759 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); 816 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_);
760 if (browser && browser->window()) { 817 if (browser && browser->window()) {
761 OnBrowserWindowReady(browser); 818 OnBrowserWindowReady(browser);
762 } else { 819 } else {
763 registrar_.Add(this, 820 registrar_.Add(this,
764 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 821 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
765 content::NotificationService::AllSources()); 822 content::NotificationService::AllSources());
766 } 823 }
767 } 824 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698