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

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

Issue 1960293003: Remove OS_CHROMEOS from ui/ash code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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/chromeos/profiles/profile_helper.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
14 #include "components/signin/core/account_id/account_id.h" 16 #include "components/signin/core/account_id/account_id.h"
17 #include "components/user_manager/user_manager.h"
15 #include "google_apis/gaia/gaia_auth_util.h" 18 #include "google_apis/gaia/gaia_auth_util.h"
16 19
17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
20 #include "components/user_manager/user_manager.h"
21 #endif
22
23 namespace multi_user_util { 20 namespace multi_user_util {
24 21
25 AccountId GetAccountIdFromProfile(Profile* profile) { 22 AccountId GetAccountIdFromProfile(Profile* profile) {
26 return GetAccountIdFromEmail( 23 return GetAccountIdFromEmail(
27 profile->GetOriginalProfile()->GetProfileUserName()); 24 profile->GetOriginalProfile()->GetProfileUserName());
28 } 25 }
29 26
30 AccountId GetAccountIdFromEmail(const std::string& email) { 27 AccountId GetAccountIdFromEmail(const std::string& email) {
31 // |email| and profile name could be empty if not yet logged in or guest mode. 28 // |email| and profile name could be empty if not yet logged in or guest mode.
32 return email.empty() ? EmptyAccountId() 29 return email.empty() ? EmptyAccountId()
33 : AccountId::FromUserEmail(gaia::CanonicalizeEmail( 30 : AccountId::FromUserEmail(gaia::CanonicalizeEmail(
34 gaia::SanitizeEmail(email))); 31 gaia::SanitizeEmail(email)));
35 } 32 }
36 33
37 Profile* GetProfileFromAccountId(const AccountId& account_id) { 34 Profile* GetProfileFromAccountId(const AccountId& account_id) {
38 // Unit tests can end up here without a |g_browser_process|. 35 // Unit tests can end up here without a |g_browser_process|.
39 if (!g_browser_process || !g_browser_process->profile_manager()) 36 if (!g_browser_process || !g_browser_process->profile_manager())
40 return nullptr; 37 return nullptr;
41 38
42 std::vector<Profile*> profiles = 39 std::vector<Profile*> profiles =
43 g_browser_process->profile_manager()->GetLoadedProfiles(); 40 g_browser_process->profile_manager()->GetLoadedProfiles();
44 41
45 std::vector<Profile*>::const_iterator profile_iterator = profiles.begin(); 42 std::vector<Profile*>::const_iterator profile_iterator = profiles.begin();
46 for (; profile_iterator != profiles.end(); ++profile_iterator) { 43 for (; profile_iterator != profiles.end(); ++profile_iterator) {
47 if (GetAccountIdFromProfile(*profile_iterator) == account_id) 44 if (GetAccountIdFromProfile(*profile_iterator) == account_id)
48 return *profile_iterator; 45 return *profile_iterator;
49 } 46 }
50 47
51 #if defined(OS_CHROMEOS)
52 // If in a session the refresh token is revoked, GetAccountIdFromProfile() 48 // If in a session the refresh token is revoked, GetAccountIdFromProfile()
53 // returns an empty account id which will cause the profile not being fetched 49 // 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. 50 // 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 51 // 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/ 52 // password, we will force log out the user within 120 seconds. See crbug.com/
57 // 587318 for more detail. 53 // 587318 for more detail.
58 const user_manager::User* user = 54 const user_manager::User* user =
59 user_manager::UserManager::Get()->FindUser(account_id); 55 user_manager::UserManager::Get()->FindUser(account_id);
60 if (user) 56 if (user)
61 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); 57 return chromeos::ProfileHelper::Get()->GetProfileByUser(user);
62 #endif
63 58
64 return nullptr; 59 return nullptr;
65 } 60 }
66 61
67 Profile* GetProfileFromWindow(aura::Window* window) { 62 Profile* GetProfileFromWindow(aura::Window* window) {
68 #if defined(OS_CHROMEOS)
69 chrome::MultiUserWindowManager* manager = 63 chrome::MultiUserWindowManager* manager =
70 chrome::MultiUserWindowManager::GetInstance(); 64 chrome::MultiUserWindowManager::GetInstance();
71 // We might come here before the manager got created - or in a unit test. 65 // We might come here before the manager got created - or in a unit test.
72 if (!manager) 66 if (!manager)
73 return nullptr; 67 return nullptr;
74 const AccountId account_id = manager->GetUserPresentingWindow(window); 68 const AccountId account_id = manager->GetUserPresentingWindow(window);
75 return account_id.is_valid() ? GetProfileFromAccountId(account_id) : nullptr; 69 return account_id.is_valid() ? GetProfileFromAccountId(account_id) : nullptr;
76 #else
77 return nullptr;
78 #endif
79 } 70 }
80 71
81 bool IsProfileFromActiveUser(Profile* profile) { 72 bool IsProfileFromActiveUser(Profile* profile) {
82 #if defined(OS_CHROMEOS)
83 return GetAccountIdFromProfile(profile) == 73 return GetAccountIdFromProfile(profile) ==
84 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); 74 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId();
85 #else
86 // In non Chrome OS configurations this will be always true since this only
87 // makes sense in separate desktop mode.
88 return true;
89 #endif
90 } 75 }
91 76
92 const AccountId GetCurrentAccountId() { 77 const AccountId GetCurrentAccountId() {
93 #if defined(OS_CHROMEOS)
94 const user_manager::User* user = 78 const user_manager::User* user =
95 user_manager::UserManager::Get()->GetActiveUser(); 79 user_manager::UserManager::Get()->GetActiveUser();
96 // In unit tests user login phase is usually skipped. 80 // In unit tests user login phase is usually skipped.
97 if (user) 81 return user ? user->GetAccountId() : EmptyAccountId();
98 return user->GetAccountId();
99 #endif
100 return EmptyAccountId();
101 } 82 }
102 83
103 // Move the window to the current user's desktop. 84 // Move the window to the current user's desktop.
104 void MoveWindowToCurrentDesktop(aura::Window* window) { 85 void MoveWindowToCurrentDesktop(aura::Window* window) {
105 #if defined(OS_CHROMEOS)
106 if (!chrome::MultiUserWindowManager::GetInstance()->IsWindowOnDesktopOfUser( 86 if (!chrome::MultiUserWindowManager::GetInstance()->IsWindowOnDesktopOfUser(
107 window, GetCurrentAccountId())) { 87 window, GetCurrentAccountId())) {
108 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( 88 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
109 window, GetCurrentAccountId()); 89 window, GetCurrentAccountId());
110 } 90 }
111 #endif
112 } 91 }
113 92
114 } // namespace multi_user_util 93 } // namespace multi_user_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698