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:
chrome/browser
resources
user_manager
ui
ui/login/account_picker
@ -58,11 +58,10 @@ cr.define('cr.ui', function() {
|
||||
|
||||
/**
|
||||
* Open a new browser for the given profile.
|
||||
* @param {string} email The user's email, if signed in.
|
||||
* @param {string} displayName The user's display name.
|
||||
* @param {string} profilePath The profile's path.
|
||||
*/
|
||||
Oobe.launchUser = function(email, displayName) {
|
||||
chrome.send('launchUser', [email, displayName]);
|
||||
Oobe.launchUser = function(profilePath) {
|
||||
chrome.send('launchUser', [profilePath]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -110,26 +110,21 @@ std::string GetAvatarImageAtIndex(
|
||||
return webui::GetBitmapDataUrl(resized_image.AsBitmap());
|
||||
}
|
||||
|
||||
size_t GetIndexOfProfileWithEmailAndName(const ProfileInfoCache& info_cache,
|
||||
const base::string16& email,
|
||||
const base::string16& name) {
|
||||
size_t GetIndexOfProfileWithEmail(const ProfileInfoCache& info_cache,
|
||||
const std::string& email) {
|
||||
const base::string16& profile_email = base::UTF8ToUTF16(email);
|
||||
for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) {
|
||||
if (info_cache.GetUserNameOfProfileAtIndex(i) == email &&
|
||||
(name.empty() ||
|
||||
profiles::GetAvatarNameForProfile(
|
||||
info_cache.GetPathOfProfileAtIndex(i)) == name)) {
|
||||
if (info_cache.GetUserNameOfProfileAtIndex(i) == profile_email)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return std::string::npos;
|
||||
}
|
||||
|
||||
extensions::ScreenlockPrivateEventRouter* GetScreenlockRouter(
|
||||
const std::string& email) {
|
||||
ProfileInfoCache& info_cache =
|
||||
const ProfileInfoCache& info_cache =
|
||||
g_browser_process->profile_manager()->GetProfileInfoCache();
|
||||
const size_t profile_index = GetIndexOfProfileWithEmailAndName(
|
||||
info_cache, base::UTF8ToUTF16(email), base::string16());
|
||||
const size_t profile_index = GetIndexOfProfileWithEmail(info_cache, email);
|
||||
Profile* profile = g_browser_process->profile_manager()
|
||||
->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index));
|
||||
return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get(
|
||||
@ -274,10 +269,10 @@ ScreenlockBridge::LockHandler::AuthType UserManagerScreenHandler::GetAuthType(
|
||||
}
|
||||
|
||||
void UserManagerScreenHandler::Unlock(const std::string& user_email) {
|
||||
ProfileInfoCache& info_cache =
|
||||
const ProfileInfoCache& info_cache =
|
||||
g_browser_process->profile_manager()->GetProfileInfoCache();
|
||||
const size_t profile_index = GetIndexOfProfileWithEmailAndName(
|
||||
info_cache, base::UTF8ToUTF16(user_email), base::string16());
|
||||
const size_t profile_index =
|
||||
GetIndexOfProfileWithEmail(info_cache, user_email);
|
||||
DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles());
|
||||
|
||||
authenticating_profile_index_ = profile_index;
|
||||
@ -320,23 +315,27 @@ void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) {
|
||||
|
||||
void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
|
||||
const base::ListValue* args) {
|
||||
base::string16 email_address;
|
||||
if (!args->GetString(0, &email_address))
|
||||
const base::Value* profile_path_value;
|
||||
if (!args->Get(0, &profile_path_value))
|
||||
return;
|
||||
|
||||
base::string16 display_name;
|
||||
if (!args->GetString(1, &display_name))
|
||||
base::FilePath profile_path;
|
||||
if (!base::GetValueAsFilePath(*profile_path_value, &profile_path))
|
||||
return;
|
||||
|
||||
base::string16 email_address;
|
||||
if (!args->GetString(1, &email_address))
|
||||
return;
|
||||
|
||||
std::string password;
|
||||
if (!args->GetString(2, &password))
|
||||
return;
|
||||
|
||||
ProfileInfoCache& info_cache =
|
||||
const ProfileInfoCache& info_cache =
|
||||
g_browser_process->profile_manager()->GetProfileInfoCache();
|
||||
size_t profile_index = GetIndexOfProfileWithEmailAndName(
|
||||
info_cache, email_address, display_name);
|
||||
if (profile_index >= info_cache.GetNumberOfProfiles()) {
|
||||
size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path);
|
||||
|
||||
if (profile_index == std::string::npos) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
@ -350,10 +349,9 @@ void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
|
||||
this,
|
||||
GaiaConstants::kChromeSource,
|
||||
web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext()));
|
||||
std::string email_string;
|
||||
args->GetString(0, &email_string);
|
||||
|
||||
client_login_->StartClientLogin(
|
||||
email_string,
|
||||
base::UTF16ToUTF8(email_address),
|
||||
password,
|
||||
GaiaConstants::kSyncService,
|
||||
std::string(),
|
||||
@ -401,21 +399,19 @@ void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
|
||||
}
|
||||
|
||||
void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) {
|
||||
base::string16 email_address;
|
||||
base::string16 display_name;
|
||||
|
||||
if (!args->GetString(0, &email_address) ||
|
||||
!args->GetString(1, &display_name)) {
|
||||
NOTREACHED();
|
||||
const base::Value* profile_path_value = NULL;
|
||||
if (!args->Get(0, &profile_path_value))
|
||||
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();
|
||||
size_t profile_index = GetIndexOfProfileWithEmailAndName(
|
||||
info_cache, email_address, display_name);
|
||||
size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path);
|
||||
|
||||
if (profile_index >= info_cache.GetNumberOfProfiles()) {
|
||||
if (profile_index == std::string::npos) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
@ -429,9 +425,8 @@ void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) {
|
||||
return;
|
||||
ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY);
|
||||
|
||||
base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index);
|
||||
profiles::SwitchToProfile(
|
||||
path,
|
||||
profile_path,
|
||||
desktop_type_,
|
||||
false, /* reuse any existing windows */
|
||||
base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete,
|
||||
@ -652,7 +647,8 @@ void UserManagerScreenHandler::SendUserList() {
|
||||
profile_value->SetString(
|
||||
kKeyDisplayName,
|
||||
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(
|
||||
kKeySupervisedUser, info_cache.ProfileIsSupervisedAtIndex(i));
|
||||
@ -680,7 +676,7 @@ void UserManagerScreenHandler::ReportAuthenticationResult(
|
||||
password_attempt_.clear();
|
||||
|
||||
if (success) {
|
||||
ProfileInfoCache& info_cache =
|
||||
const ProfileInfoCache& info_cache =
|
||||
g_browser_process->profile_manager()->GetProfileInfoCache();
|
||||
base::FilePath path = info_cache.GetPathOfProfileAtIndex(
|
||||
authenticating_profile_index_);
|
||||
|
@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "chrome/browser/profiles/profile_manager.h"
|
||||
@ -75,12 +76,14 @@ IN_PROC_BROWSER_TEST_F(UserManagerUIBrowserTest, PageRedirectsToAboutChrome) {
|
||||
content::WebContents* web_contents =
|
||||
browser()->tab_strip_model()->GetActiveWebContents();
|
||||
|
||||
base::string16 profile_name =
|
||||
profiles::GetAvatarNameForProfile(browser()->profile()->GetPath());
|
||||
// If this is a Windows style path, escape all the slashes.
|
||||
std::string profile_path;
|
||||
base::ReplaceChars(browser()->profile()->GetPath().MaybeAsASCII(),
|
||||
"\\", "\\\\", &profile_path);
|
||||
|
||||
std::string launch_js =
|
||||
base::StringPrintf("Oobe.launchUser('', '%s')",
|
||||
base::UTF16ToUTF8(profile_name).c_str());
|
||||
base::StringPrintf("Oobe.launchUser('%s')", profile_path.c_str());
|
||||
|
||||
bool result = content::ExecuteScript(web_contents, launch_js);
|
||||
EXPECT_TRUE(result);
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
@ -1961,13 +1961,13 @@ cr.define('login', function() {
|
||||
/** @override */
|
||||
activate: function(e) {
|
||||
if (!this.user.needsSignin) {
|
||||
Oobe.launchUser(this.user.emailAddress, this.user.displayName);
|
||||
Oobe.launchUser(this.user.profilePath);
|
||||
} else if (!this.passwordElement.value) {
|
||||
return false;
|
||||
} else {
|
||||
chrome.send('authenticatedLaunchUser',
|
||||
[this.user.emailAddress,
|
||||
this.user.displayName,
|
||||
[this.user.profilePath,
|
||||
this.user.emailAddress,
|
||||
this.passwordElement.value]);
|
||||
}
|
||||
this.passwordElement.value = '';
|
||||
|
Reference in New Issue
Block a user