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

Unified Diff: chrome/browser/ui/webui/signin/user_manager_screen_handler.cc

Issue 564453003: Access to Chrome via the System Tray should go through the User Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase continued Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/signin/user_manager_screen_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 34c1fe76a9b5796dcdd5b5fad0008f23eed247ec..03f29f6fd8429aaee839f4c35aa980b3db9f01c1 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(
@@ -684,9 +686,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",
@@ -699,3 +705,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());
+ }
+}
« no previous file with comments | « chrome/browser/ui/webui/signin/user_manager_screen_handler.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698