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

Unified Diff: chrome/browser/ui/ash/multi_user/multi_user_util.cc

Issue 1984733002: [Reland] GetAccountIdFromProfile() should not return an empty account id if a valid profile is prov… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
Index: chrome/browser/ui/ash/multi_user/multi_user_util.cc
diff --git a/chrome/browser/ui/ash/multi_user/multi_user_util.cc b/chrome/browser/ui/ash/multi_user/multi_user_util.cc
index ef2e7cd29a88a8eae74fe71ff9bd7183a89c488e..b00fb431f9193e349d4059bf40cb5674e91524f2 100644
--- a/chrome/browser/ui/ash/multi_user/multi_user_util.cc
+++ b/chrome/browser/ui/ash/multi_user/multi_user_util.cc
@@ -4,24 +4,21 @@
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
-#include <vector>
-
-#include "base/strings/string_util.h"
-#include "build/build_config.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "components/signin/core/account_id/account_id.h"
#include "components/user_manager/user_manager.h"
-#include "google_apis/gaia/gaia_auth_util.h"
namespace multi_user_util {
AccountId GetAccountIdFromProfile(Profile* profile) {
- return GetAccountIdFromEmail(
- profile->GetOriginalProfile()->GetProfileUserName());
+ // This will guarantee an nonempty AccountId be returned if a valid profile is
+ // provided.
+ const user_manager::User* user =
+ chromeos::ProfileHelper::Get()->GetUserByProfile(
+ profile->GetOriginalProfile());
+ return user ? user->GetAccountId() : EmptyAccountId();
}
AccountId GetAccountIdFromEmail(const std::string& email) {
@@ -32,31 +29,10 @@ AccountId GetAccountIdFromEmail(const std::string& email) {
}
Profile* GetProfileFromAccountId(const AccountId& account_id) {
- // Unit tests can end up here without a |g_browser_process|.
- if (!g_browser_process || !g_browser_process->profile_manager())
- return nullptr;
-
- std::vector<Profile*> profiles =
- g_browser_process->profile_manager()->GetLoadedProfiles();
-
- std::vector<Profile*>::const_iterator profile_iterator = profiles.begin();
- for (; profile_iterator != profiles.end(); ++profile_iterator) {
- if (GetAccountIdFromProfile(*profile_iterator) == account_id)
- return *profile_iterator;
- }
-
- // If in a session the refresh token is revoked, GetAccountIdFromProfile()
- // returns an empty account id which will cause the profile not being fetched
- // properly. In this case we fall back to use GetProfileByUser() function.
- // Note: If the refresh token is revoked because the user changes his GAIA
- // password, we will force log out the user within 120 seconds. See crbug.com/
- // 587318 for more detail.
const user_manager::User* user =
user_manager::UserManager::Get()->FindUser(account_id);
- if (user)
- return chromeos::ProfileHelper::Get()->GetProfileByUser(user);
-
- return nullptr;
+ return user ? chromeos::ProfileHelper::Get()->GetProfileByUser(user)
+ : nullptr;
}
Profile* GetProfileFromWindow(aura::Window* window) {

Powered by Google App Engine
This is Rietveld 408576698