Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. | |
|
Mr4D (OOO till 08-26)
2016/02/17 04:05:07
Please add also a comment that in case the refresh
| |
| 55 const user_manager::User* user = | |
| 56 user_manager::UserManager::Get()->FindUser(account_id); | |
| 57 if (user) | |
| 58 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); | |
| 59 #endif | |
| 60 | |
| 61 return nullptr; | |
| 50 } | 62 } |
| 51 | 63 |
| 52 Profile* GetProfileFromWindow(aura::Window* window) { | 64 Profile* GetProfileFromWindow(aura::Window* window) { |
| 53 #if defined(OS_CHROMEOS) | 65 #if defined(OS_CHROMEOS) |
| 54 chrome::MultiUserWindowManager* manager = | 66 chrome::MultiUserWindowManager* manager = |
| 55 chrome::MultiUserWindowManager::GetInstance(); | 67 chrome::MultiUserWindowManager::GetInstance(); |
| 56 // We might come here before the manager got created - or in a unit test. | 68 // We might come here before the manager got created - or in a unit test. |
| 57 if (!manager) | 69 if (!manager) |
| 58 return nullptr; | 70 return nullptr; |
| 59 const AccountId account_id = manager->GetUserPresentingWindow(window); | 71 const AccountId account_id = manager->GetUserPresentingWindow(window); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 90 #if defined(OS_CHROMEOS) | 102 #if defined(OS_CHROMEOS) |
| 91 if (!chrome::MultiUserWindowManager::GetInstance()->IsWindowOnDesktopOfUser( | 103 if (!chrome::MultiUserWindowManager::GetInstance()->IsWindowOnDesktopOfUser( |
| 92 window, GetCurrentAccountId())) { | 104 window, GetCurrentAccountId())) { |
| 93 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( | 105 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( |
| 94 window, GetCurrentAccountId()); | 106 window, GetCurrentAccountId()); |
| 95 } | 107 } |
| 96 #endif | 108 #endif |
| 97 } | 109 } |
| 98 | 110 |
| 99 } // namespace multi_user_util | 111 } // namespace multi_user_util |
| OLD | NEW |