| 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 6347f05dc41078d21ac56f8edab65619afbb23ef..44838fb71a0327474d1ce305baae15fc0a7d91a6 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,15 @@
|
| #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/browser/ui/user_manager.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 +89,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 =
|
| @@ -217,7 +210,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));
|
| @@ -293,6 +287,9 @@ 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.
|
| + args->GetString(0, &url_hash_);
|
| +
|
| SendUserList();
|
| web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen",
|
| base::FundamentalValue(IsGuestModeEnabled()),
|
| @@ -311,7 +308,8 @@ void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) {
|
| }
|
| profiles::CreateAndSwitchToNewProfile(
|
| desktop_type_,
|
| - base::Bind(&OnSwitchToProfileComplete),
|
| + base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete,
|
| + weak_ptr_factory_.GetWeakPtr()),
|
| ProfileMetrics::ADD_NEW_USER_MANAGER);
|
| }
|
|
|
| @@ -391,9 +389,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.
|
| @@ -431,11 +431,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(
|
| @@ -679,9 +681,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",
|
| @@ -692,3 +698,52 @@ void UserManagerScreenHandler::ReportAuthenticationResult(
|
| base::FundamentalValue(0));
|
| }
|
| }
|
| +
|
| +void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) {
|
| + DCHECK(browser);
|
| + DCHECK(browser->window());
|
| + if (url_hash_ == profiles::kUserManagerSelectProfileTaskManager) {
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE, base::Bind(&chrome::ShowTaskManager, browser));
|
| + } else if (url_hash_ == profiles::kUserManagerSelectProfileAboutChrome) {
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser));
|
| + }
|
| +
|
| + // This call is last as it deletes this object.
|
| + UserManager::Hide();
|
| +}
|
| +
|
| +void UserManagerScreenHandler::Observe(
|
| + int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + switch (type) {
|
| + case chrome::NOTIFICATION_BROWSER_WINDOW_READY:
|
| + // Only respond to one Browser Window Ready event.
|
| + registrar_.Remove(this,
|
| + chrome::NOTIFICATION_BROWSER_WINDOW_READY,
|
| + content::NotificationService::AllSources());
|
| + OnBrowserWindowReady(content::Source<Browser>(source).ptr());
|
| + 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());
|
| + }
|
| +}
|
|
|