Index: chrome/browser/ui/webui/signin/user_manager_screen_handler.cc |
diff --git a/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc b/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc |
index 5bd6b062699552bc62f748a4a5d665ae35c0d1e4..ff28d250c316d8b52315a6a46aaaaf46cefae06b 100644 |
--- a/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc |
+++ b/chrome/browser/ui/webui/signin/user_manager_screen_handler.cc |
@@ -10,6 +10,7 @@ |
#include "base/value_conversions.h" |
#include "base/values.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_avatar_icon_util.h" |
@@ -22,11 +23,14 @@ |
#include "chrome/browser/signin/local_auth.h" |
#include "chrome/browser/ui/browser_dialogs.h" |
#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/chrome_pages.h" |
#include "chrome/browser/ui/singleton_tabs.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/url_constants.h" |
#include "chrome/grit/chromium_strings.h" |
#include "chrome/grit/generated_resources.h" |
+#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_ui.h" |
#include "google_apis/gaia/gaia_auth_fetcher.h" |
@@ -84,18 +88,6 @@ void OpenNewWindowForProfile( |
false); |
} |
-// This callback is run after switching to a new profile has finished. This |
-// means either a new browser window has been opened, or an existing one |
-// has been found, which means we can safely close the User Manager without |
-// accidentally terminating the browser process. The task needs to be posted, |
-// as HideUserManager will end up destroying its WebContents, which will |
-// destruct the UserManagerScreenHandler as well. |
-void OnSwitchToProfileComplete() { |
- base::MessageLoop::current()->PostTask( |
- FROM_HERE, |
- base::Bind(&chrome::HideUserManager)); |
-} |
- |
std::string GetAvatarImageAtIndex( |
size_t index, const ProfileInfoCache& info_cache) { |
bool is_gaia_picture = |
@@ -211,7 +203,8 @@ class UserManagerScreenHandler::ProfileUpdateObserver |
// UserManagerScreenHandler --------------------------------------------------- |
UserManagerScreenHandler::UserManagerScreenHandler() |
- : desktop_type_(chrome::GetActiveDesktop()) { |
+ : desktop_type_(chrome::GetActiveDesktop()), |
+ weak_ptr_factory_(this) { |
profileInfoCacheObserver_.reset( |
new UserManagerScreenHandler::ProfileUpdateObserver( |
g_browser_process->profile_manager(), this)); |
@@ -287,6 +280,11 @@ void UserManagerScreenHandler::Unlock(const std::string& user_email) { |
} |
void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
+ // If the URL has a hash parameter, store it for later. |
+ base::string16 url_hash; |
+ if (args->GetString(0, &url_hash)) |
+ url_hash_ = url_hash; |
+ |
SendUserList(); |
web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", |
base::FundamentalValue(IsGuestModeEnabled())); |
@@ -297,9 +295,11 @@ void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
} |
void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
- profiles::CreateAndSwitchToNewProfile(desktop_type_, |
- base::Bind(&OnSwitchToProfileComplete), |
- ProfileMetrics::ADD_NEW_USER_MANAGER); |
+ profiles::CreateAndSwitchToNewProfile( |
+ desktop_type_, |
+ base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ ProfileMetrics::ADD_NEW_USER_MANAGER); |
} |
void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
@@ -378,9 +378,11 @@ void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { |
void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
if (IsGuestModeEnabled()) { |
- profiles::SwitchToGuestProfile(desktop_type_, |
- base::Bind(&OnSwitchToProfileComplete)); |
ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); |
+ profiles::SwitchToGuestProfile( |
+ desktop_type_, |
+ base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
+ weak_ptr_factory_.GetWeakPtr())); |
} else { |
// The UI should have prevented the user from allowing the selection of |
// guest mode. |
@@ -418,11 +420,13 @@ void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
- profiles::SwitchToProfile(path, |
- desktop_type_, |
- false, /* reuse any existing windows */ |
- base::Bind(&OnSwitchToProfileComplete), |
- ProfileMetrics::SWITCH_PROFILE_MANAGER); |
+ profiles::SwitchToProfile( |
+ path, |
+ desktop_type_, |
+ false, /* reuse any existing windows */ |
+ base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ ProfileMetrics::SWITCH_PROFILE_MANAGER); |
} |
void UserManagerScreenHandler::HandleAttemptUnlock( |
@@ -666,9 +670,13 @@ void UserManagerScreenHandler::ReportAuthenticationResult( |
authenticating_profile_index_, false); |
base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
authenticating_profile_index_); |
- profiles::SwitchToProfile(path, desktop_type_, true, |
- base::Bind(&OnSwitchToProfileComplete), |
- ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
+ profiles::SwitchToProfile( |
+ path, |
+ desktop_type_, |
+ true, |
+ base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
} else { |
web_ui()->CallJavascriptFunction( |
"cr.ui.Oobe.showSignInError", |
@@ -679,3 +687,54 @@ void UserManagerScreenHandler::ReportAuthenticationResult( |
base::FundamentalValue(0)); |
} |
} |
+ |
+void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { |
+ chrome::HideUserManager(); |
+ if (url_hash_ == |
noms (inactive)
2014/09/12 14:44:16
Why don't you just save the hash as an std::string
Mike Lerman
2014/09/15 13:44:04
Because that's too easy!
Done.
|
+ base::UTF8ToUTF16(profiles::kUserManagerSelectProfileTaskManager)) { |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, base::Bind(&chrome::ShowTaskManager, browser)); |
+ } else if (url_hash_ == |
+ base::UTF8ToUTF16(profiles::kUserManagerSelectProfileAboutChrome)) { |
+ if (browser) { |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser)); |
+ } else { |
+ NOTREACHED(); |
+ } |
+ } |
+} |
+ |
+void UserManagerScreenHandler::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ switch (type) { |
+ case chrome::NOTIFICATION_BROWSER_WINDOW_READY: |
+ OnBrowserWindowReady(content::Source<Browser>(source).ptr()); |
+ // Only respond to one Browser Window Ready event. |
+ registrar_.Remove(this, |
+ chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
+ content::NotificationService::AllSources()); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
+} |
+ |
+// This callback is run after switching to a new profile has finished. This |
+// means either a new browser has been created (but not the window), or an |
+// existing one has been found. The HideUserManager task needs to be posted |
+// since closing the User Manager before the window is created can flakily |
+// cause Chrome to close. |
+void UserManagerScreenHandler::OnSwitchToProfileComplete( |
+ Profile* profile, Profile::CreateStatus profile_create_status) { |
+ Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
+ if (browser && browser->window()) { |
+ OnBrowserWindowReady(browser); |
+ } else { |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
+ content::NotificationService::AllSources()); |
+ } |
+} |