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

Side by Side Diff: chrome/browser/ui/ash/multi_user/multi_user_util.cc

Issue 1962463002: Revert of GetAccountIdFromProfile() should not return an empty account id if a valid profile is provided. (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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 5 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "components/signin/core/account_id/account_id.h" 14 #include "components/signin/core/account_id/account_id.h"
15 #include "google_apis/gaia/gaia_auth_util.h" 15 #include "google_apis/gaia/gaia_auth_util.h"
16 16
17 #if defined(OS_CHROMEOS) 17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
20 #include "components/user_manager/user_manager.h" 20 #include "components/user_manager/user_manager.h"
21 #endif 21 #endif
22 22
23 namespace multi_user_util { 23 namespace multi_user_util {
24 24
25 AccountId GetAccountIdFromProfile(Profile* profile) { 25 AccountId GetAccountIdFromProfile(Profile* profile) {
26 #if defined(OS_CHROMEOS)
27 // If in a session the refresh token is revoked, GetProfileUserName() might
28 // returns an empty user email which will cause GetAccountIdFromProfile()
29 // returns an empty account id, which might cause weird behaviors or crash.
30 // Note: If the refresh token is revoked because the user changes his GAIA
31 // password, we will force log out the user within 120 seconds. See crbug.com/
32 // 587318 for more detail.
33 const user_manager::User* user =
34 chromeos::ProfileHelper::Get()->GetUserByProfile(
35 profile->GetOriginalProfile());
36 return user ? user->GetAccountId() : EmptyAccountId();
37 #else
38 return GetAccountIdFromEmail( 26 return GetAccountIdFromEmail(
39 profile->GetOriginalProfile()->GetProfileUserName()); 27 profile->GetOriginalProfile()->GetProfileUserName());
40 #endif
41 } 28 }
42 29
43 AccountId GetAccountIdFromEmail(const std::string& email) { 30 AccountId GetAccountIdFromEmail(const std::string& email) {
44 // |email| and profile name could be empty if not yet logged in or guest mode. 31 // |email| and profile name could be empty if not yet logged in or guest mode.
45 return email.empty() ? EmptyAccountId() 32 return email.empty() ? EmptyAccountId()
46 : AccountId::FromUserEmail(gaia::CanonicalizeEmail( 33 : AccountId::FromUserEmail(gaia::CanonicalizeEmail(
47 gaia::SanitizeEmail(email))); 34 gaia::SanitizeEmail(email)));
48 } 35 }
49 36
50 Profile* GetProfileFromAccountId(const AccountId& account_id) { 37 Profile* GetProfileFromAccountId(const AccountId& account_id) {
51 // Unit tests can end up here without a |g_browser_process|. 38 // Unit tests can end up here without a |g_browser_process|.
52 if (!g_browser_process || !g_browser_process->profile_manager()) 39 if (!g_browser_process || !g_browser_process->profile_manager())
53 return nullptr; 40 return nullptr;
54 41
55 std::vector<Profile*> profiles = 42 std::vector<Profile*> profiles =
56 g_browser_process->profile_manager()->GetLoadedProfiles(); 43 g_browser_process->profile_manager()->GetLoadedProfiles();
57 44
58 std::vector<Profile*>::const_iterator profile_iterator = profiles.begin(); 45 std::vector<Profile*>::const_iterator profile_iterator = profiles.begin();
59 for (; profile_iterator != profiles.end(); ++profile_iterator) { 46 for (; profile_iterator != profiles.end(); ++profile_iterator) {
60 if (GetAccountIdFromProfile(*profile_iterator) == account_id) 47 if (GetAccountIdFromProfile(*profile_iterator) == account_id)
61 return *profile_iterator; 48 return *profile_iterator;
62 } 49 }
63 50
51 #if defined(OS_CHROMEOS)
52 // If in a session the refresh token is revoked, GetAccountIdFromProfile()
53 // returns an empty account id which will cause the profile not being fetched
54 // properly. In this case we fall back to use GetProfileByUser() function.
55 // Note: If the refresh token is revoked because the user changes his GAIA
56 // password, we will force log out the user within 120 seconds. See crbug.com/
57 // 587318 for more detail.
58 const user_manager::User* user =
59 user_manager::UserManager::Get()->FindUser(account_id);
60 if (user)
61 return chromeos::ProfileHelper::Get()->GetProfileByUser(user);
62 #endif
63
64 return nullptr; 64 return nullptr;
65 } 65 }
66 66
67 Profile* GetProfileFromWindow(aura::Window* window) { 67 Profile* GetProfileFromWindow(aura::Window* window) {
68 #if defined(OS_CHROMEOS) 68 #if defined(OS_CHROMEOS)
69 chrome::MultiUserWindowManager* manager = 69 chrome::MultiUserWindowManager* manager =
70 chrome::MultiUserWindowManager::GetInstance(); 70 chrome::MultiUserWindowManager::GetInstance();
71 // We might come here before the manager got created - or in a unit test. 71 // We might come here before the manager got created - or in a unit test.
72 if (!manager) 72 if (!manager)
73 return nullptr; 73 return nullptr;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 #if defined(OS_CHROMEOS) 105 #if defined(OS_CHROMEOS)
106 if (!chrome::MultiUserWindowManager::GetInstance()->IsWindowOnDesktopOfUser( 106 if (!chrome::MultiUserWindowManager::GetInstance()->IsWindowOnDesktopOfUser(
107 window, GetCurrentAccountId())) { 107 window, GetCurrentAccountId())) {
108 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( 108 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
109 window, GetCurrentAccountId()); 109 window, GetCurrentAccountId());
110 } 110 }
111 #endif 111 #endif
112 } 112 }
113 113
114 } // namespace multi_user_util 114 } // namespace multi_user_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698