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

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

Issue 1704623002: GetProfileFromAccountId() should not return a null point if a valid account id is provided. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment. Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ui/ash/multi_user/multi_user_window_manager.h" 19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
19 #include "components/user_manager/user_manager.h" 20 #include "components/user_manager/user_manager.h"
20 #endif 21 #endif
21 22
22 namespace multi_user_util { 23 namespace multi_user_util {
23 24
24 AccountId GetAccountIdFromProfile(Profile* profile) { 25 AccountId GetAccountIdFromProfile(Profile* profile) {
25 return GetAccountIdFromEmail( 26 return GetAccountIdFromEmail(
26 profile->GetOriginalProfile()->GetProfileUserName()); 27 profile->GetOriginalProfile()->GetProfileUserName());
27 } 28 }
28 29
29 AccountId GetAccountIdFromEmail(const std::string& email) { 30 AccountId GetAccountIdFromEmail(const std::string& email) {
30 // |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.
31 return email.empty() ? EmptyAccountId() 32 return email.empty() ? EmptyAccountId()
32 : AccountId::FromUserEmail(gaia::CanonicalizeEmail( 33 : AccountId::FromUserEmail(gaia::CanonicalizeEmail(
33 gaia::SanitizeEmail(email))); 34 gaia::SanitizeEmail(email)));
34 } 35 }
35 36
36 Profile* GetProfileFromAccountId(const AccountId& account_id) { 37 Profile* GetProfileFromAccountId(const AccountId& account_id) {
37 // Unit tests can end up here without a |g_browser_process|. 38 // Unit tests can end up here without a |g_browser_process|.
38 if (!g_browser_process || !g_browser_process->profile_manager()) 39 if (!g_browser_process || !g_browser_process->profile_manager())
39 return NULL; 40 return nullptr;
40 41
41 std::vector<Profile*> profiles = 42 std::vector<Profile*> profiles =
42 g_browser_process->profile_manager()->GetLoadedProfiles(); 43 g_browser_process->profile_manager()->GetLoadedProfiles();
43 44
44 std::vector<Profile*>::const_iterator profile_iterator = profiles.begin(); 45 std::vector<Profile*>::const_iterator profile_iterator = profiles.begin();
45 for (; profile_iterator != profiles.end(); ++profile_iterator) { 46 for (; profile_iterator != profiles.end(); ++profile_iterator) {
46 if (GetAccountIdFromProfile(*profile_iterator) == account_id) 47 if (GetAccountIdFromProfile(*profile_iterator) == account_id)
47 return *profile_iterator; 48 return *profile_iterator;
48 } 49 }
49 return NULL; 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;
50 } 65 }
51 66
52 Profile* GetProfileFromWindow(aura::Window* window) { 67 Profile* GetProfileFromWindow(aura::Window* window) {
53 #if defined(OS_CHROMEOS) 68 #if defined(OS_CHROMEOS)
54 chrome::MultiUserWindowManager* manager = 69 chrome::MultiUserWindowManager* manager =
55 chrome::MultiUserWindowManager::GetInstance(); 70 chrome::MultiUserWindowManager::GetInstance();
56 // 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.
57 if (!manager) 72 if (!manager)
58 return nullptr; 73 return nullptr;
59 const AccountId account_id = manager->GetUserPresentingWindow(window); 74 const AccountId account_id = manager->GetUserPresentingWindow(window);
(...skipping 30 matching lines...) Expand all
90 #if defined(OS_CHROMEOS) 105 #if defined(OS_CHROMEOS)
91 if (!chrome::MultiUserWindowManager::GetInstance()->IsWindowOnDesktopOfUser( 106 if (!chrome::MultiUserWindowManager::GetInstance()->IsWindowOnDesktopOfUser(
92 window, GetCurrentAccountId())) { 107 window, GetCurrentAccountId())) {
93 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( 108 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
94 window, GetCurrentAccountId()); 109 window, GetCurrentAccountId());
95 } 110 }
96 #endif 111 #endif
97 } 112 }
98 113
99 } // namespace multi_user_util 114 } // namespace multi_user_util
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698