0

The User Manager needs to use profile paths not display names for profile switching

Since profiles can have duplicate names now, the profile path is the only thing that
distinguishes profiles.

Also did some cleanup of const refs.

BUG=448347
TEST=Start Chrome with --enable-new-avatar-menu. Create two profiles with the same
name. You should have no problems switching between the two in the "Switch Person"
overlay.

Review URL: https://codereview.chromium.org/840673004

Cr-Commit-Position: refs/heads/master@{#312139}
This commit is contained in:
noms
2015-01-19 12:26:11 -08:00
committed by Commit bot
parent fba86e9cdb
commit e06afd04e8
4 changed files with 49 additions and 51 deletions
chrome/browser
ui/login/account_picker

@@ -58,11 +58,10 @@ cr.define('cr.ui', function() {
/** /**
* Open a new browser for the given profile. * Open a new browser for the given profile.
* @param {string} email The user's email, if signed in. * @param {string} profilePath The profile's path.
* @param {string} displayName The user's display name.
*/ */
Oobe.launchUser = function(email, displayName) { Oobe.launchUser = function(profilePath) {
chrome.send('launchUser', [email, displayName]); chrome.send('launchUser', [profilePath]);
}; };
/** /**

@@ -110,26 +110,21 @@ std::string GetAvatarImageAtIndex(
return webui::GetBitmapDataUrl(resized_image.AsBitmap()); return webui::GetBitmapDataUrl(resized_image.AsBitmap());
} }
size_t GetIndexOfProfileWithEmailAndName(const ProfileInfoCache& info_cache, size_t GetIndexOfProfileWithEmail(const ProfileInfoCache& info_cache,
const base::string16& email, const std::string& email) {
const base::string16& name) { const base::string16& profile_email = base::UTF8ToUTF16(email);
for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) {
if (info_cache.GetUserNameOfProfileAtIndex(i) == email && if (info_cache.GetUserNameOfProfileAtIndex(i) == profile_email)
(name.empty() ||
profiles::GetAvatarNameForProfile(
info_cache.GetPathOfProfileAtIndex(i)) == name)) {
return i; return i;
}
} }
return std::string::npos; return std::string::npos;
} }
extensions::ScreenlockPrivateEventRouter* GetScreenlockRouter( extensions::ScreenlockPrivateEventRouter* GetScreenlockRouter(
const std::string& email) { const std::string& email) {
ProfileInfoCache& info_cache = const ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache(); g_browser_process->profile_manager()->GetProfileInfoCache();
const size_t profile_index = GetIndexOfProfileWithEmailAndName( const size_t profile_index = GetIndexOfProfileWithEmail(info_cache, email);
info_cache, base::UTF8ToUTF16(email), base::string16());
Profile* profile = g_browser_process->profile_manager() Profile* profile = g_browser_process->profile_manager()
->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index));
return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get(
@@ -274,10 +269,10 @@ ScreenlockBridge::LockHandler::AuthType UserManagerScreenHandler::GetAuthType(
} }
void UserManagerScreenHandler::Unlock(const std::string& user_email) { void UserManagerScreenHandler::Unlock(const std::string& user_email) {
ProfileInfoCache& info_cache = const ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache(); g_browser_process->profile_manager()->GetProfileInfoCache();
const size_t profile_index = GetIndexOfProfileWithEmailAndName( const size_t profile_index =
info_cache, base::UTF8ToUTF16(user_email), base::string16()); GetIndexOfProfileWithEmail(info_cache, user_email);
DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles());
authenticating_profile_index_ = profile_index; authenticating_profile_index_ = profile_index;
@@ -320,23 +315,27 @@ void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) {
void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
const base::ListValue* args) { const base::ListValue* args) {
base::string16 email_address; const base::Value* profile_path_value;
if (!args->GetString(0, &email_address)) if (!args->Get(0, &profile_path_value))
return; return;
base::string16 display_name; base::FilePath profile_path;
if (!args->GetString(1, &display_name)) if (!base::GetValueAsFilePath(*profile_path_value, &profile_path))
return;
base::string16 email_address;
if (!args->GetString(1, &email_address))
return; return;
std::string password; std::string password;
if (!args->GetString(2, &password)) if (!args->GetString(2, &password))
return; return;
ProfileInfoCache& info_cache = const ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache(); g_browser_process->profile_manager()->GetProfileInfoCache();
size_t profile_index = GetIndexOfProfileWithEmailAndName( size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path);
info_cache, email_address, display_name);
if (profile_index >= info_cache.GetNumberOfProfiles()) { if (profile_index == std::string::npos) {
NOTREACHED(); NOTREACHED();
return; return;
} }
@@ -350,10 +349,9 @@ void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
this, this,
GaiaConstants::kChromeSource, GaiaConstants::kChromeSource,
web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext()));
std::string email_string;
args->GetString(0, &email_string);
client_login_->StartClientLogin( client_login_->StartClientLogin(
email_string, base::UTF16ToUTF8(email_address),
password, password,
GaiaConstants::kSyncService, GaiaConstants::kSyncService,
std::string(), std::string(),
@@ -401,21 +399,19 @@ void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
} }
void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) {
base::string16 email_address; const base::Value* profile_path_value = NULL;
base::string16 display_name; if (!args->Get(0, &profile_path_value))
if (!args->GetString(0, &email_address) ||
!args->GetString(1, &display_name)) {
NOTREACHED();
return; return;
}
ProfileInfoCache& info_cache = base::FilePath profile_path;
if (!base::GetValueAsFilePath(*profile_path_value, &profile_path))
return;
const ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache(); g_browser_process->profile_manager()->GetProfileInfoCache();
size_t profile_index = GetIndexOfProfileWithEmailAndName( size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path);
info_cache, email_address, display_name);
if (profile_index >= info_cache.GetNumberOfProfiles()) { if (profile_index == std::string::npos) {
NOTREACHED(); NOTREACHED();
return; return;
} }
@@ -429,9 +425,8 @@ void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) {
return; return;
ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY);
base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index);
profiles::SwitchToProfile( profiles::SwitchToProfile(
path, profile_path,
desktop_type_, desktop_type_,
false, /* reuse any existing windows */ false, /* reuse any existing windows */
base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete,
@@ -652,7 +647,8 @@ void UserManagerScreenHandler::SendUserList() {
profile_value->SetString( profile_value->SetString(
kKeyDisplayName, kKeyDisplayName,
profiles::GetAvatarNameForProfile(profile_path)); profiles::GetAvatarNameForProfile(profile_path));
profile_value->SetString(kKeyProfilePath, profile_path.MaybeAsASCII()); profile_value->Set(
kKeyProfilePath, base::CreateFilePathValue(profile_path));
profile_value->SetBoolean(kKeyPublicAccount, false); profile_value->SetBoolean(kKeyPublicAccount, false);
profile_value->SetBoolean( profile_value->SetBoolean(
kKeySupervisedUser, info_cache.ProfileIsSupervisedAtIndex(i)); kKeySupervisedUser, info_cache.ProfileIsSupervisedAtIndex(i));
@@ -680,7 +676,7 @@ void UserManagerScreenHandler::ReportAuthenticationResult(
password_attempt_.clear(); password_attempt_.clear();
if (success) { if (success) {
ProfileInfoCache& info_cache = const ProfileInfoCache& info_cache =
g_browser_process->profile_manager()->GetProfileInfoCache(); g_browser_process->profile_manager()->GetProfileInfoCache();
base::FilePath path = info_cache.GetPathOfProfileAtIndex( base::FilePath path = info_cache.GetPathOfProfileAtIndex(
authenticating_profile_index_); authenticating_profile_index_);

@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/command_line.h" #include "base/command_line.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
@@ -75,12 +76,14 @@ IN_PROC_BROWSER_TEST_F(UserManagerUIBrowserTest, PageRedirectsToAboutChrome) {
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
base::string16 profile_name = // If this is a Windows style path, escape all the slashes.
profiles::GetAvatarNameForProfile(browser()->profile()->GetPath()); std::string profile_path;
base::ReplaceChars(browser()->profile()->GetPath().MaybeAsASCII(),
"\\", "\\\\", &profile_path);
std::string launch_js = std::string launch_js =
base::StringPrintf("Oobe.launchUser('', '%s')", base::StringPrintf("Oobe.launchUser('%s')", profile_path.c_str());
base::UTF16ToUTF8(profile_name).c_str());
bool result = content::ExecuteScript(web_contents, launch_js); bool result = content::ExecuteScript(web_contents, launch_js);
EXPECT_TRUE(result); EXPECT_TRUE(result);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();

@@ -1961,13 +1961,13 @@ cr.define('login', function() {
/** @override */ /** @override */
activate: function(e) { activate: function(e) {
if (!this.user.needsSignin) { if (!this.user.needsSignin) {
Oobe.launchUser(this.user.emailAddress, this.user.displayName); Oobe.launchUser(this.user.profilePath);
} else if (!this.passwordElement.value) { } else if (!this.passwordElement.value) {
return false; return false;
} else { } else {
chrome.send('authenticatedLaunchUser', chrome.send('authenticatedLaunchUser',
[this.user.emailAddress, [this.user.profilePath,
this.user.displayName, this.user.emailAddress,
this.passwordElement.value]); this.passwordElement.value]);
} }
this.passwordElement.value = ''; this.passwordElement.value = '';