OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/session_state_delegate_chromeos.h" | 5 #include "chrome/browser/ui/ash/session_state_delegate_chromeos.h" |
6 | 6 |
7 #include "ash/multi_profile_uma.h" | 7 #include "ash/multi_profile_uma.h" |
8 #include "ash/session_state_observer.h" | 8 #include "ash/session_state_observer.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/chromeos/login/screen_locker.h" | 12 #include "chrome/browser/chromeos/login/screen_locker.h" |
13 #include "chrome/browser/chromeos/login/user.h" | 13 #include "chrome/browser/chromeos/login/user.h" |
14 #include "chrome/browser/chromeos/login/user_adding_screen.h" | 14 #include "chrome/browser/chromeos/login/user_adding_screen.h" |
15 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
20 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
21 #include "chromeos/dbus/session_manager_client.h" | 22 #include "chromeos/dbus/session_manager_client.h" |
22 #include "google_apis/gaia/gaia_auth_util.h" | 23 #include "google_apis/gaia/gaia_auth_util.h" |
23 | 24 |
24 SessionStateDelegateChromeos::SessionStateDelegateChromeos() { | 25 SessionStateDelegateChromeos::SessionStateDelegateChromeos() { |
25 chromeos::UserManager::Get()->AddSessionStateObserver(this); | 26 chromeos::UserManager::Get()->AddSessionStateObserver(this); |
26 } | 27 } |
27 | 28 |
28 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { | 29 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { |
29 } | 30 } |
30 | 31 |
| 32 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( |
| 33 ash::MultiProfileIndex index) { |
| 34 DCHECK_LT(index, NumberOfLoggedInUsers()); |
| 35 chromeos::User* user = |
| 36 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; |
| 37 DCHECK(user); |
| 38 return chromeos::UserManager::Get()->GetProfileByUser(user); |
| 39 } |
| 40 |
31 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { | 41 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { |
32 // We limit list of logged in users to 10 due to memory constraints. | 42 // We limit list of logged in users to 10 due to memory constraints. |
33 // Note that 10 seems excessive, but we want to test how many users are | 43 // Note that 10 seems excessive, but we want to test how many users are |
34 // actually added to a session. | 44 // actually added to a session. |
35 // TODO(nkostylev): Adjust this limitation based on device capabilites. | 45 // TODO(nkostylev): Adjust this limitation based on device capabilites. |
36 // http://crbug.com/230865 | 46 // http://crbug.com/230865 |
37 return 10; | 47 return 10; |
38 } | 48 } |
39 | 49 |
40 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { | 50 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 117 |
108 const std::string SessionStateDelegateChromeos::GetUserID( | 118 const std::string SessionStateDelegateChromeos::GetUserID( |
109 ash::MultiProfileIndex index) const { | 119 ash::MultiProfileIndex index) const { |
110 DCHECK_LT(index, NumberOfLoggedInUsers()); | 120 DCHECK_LT(index, NumberOfLoggedInUsers()); |
111 return gaia::CanonicalizeEmail(gaia::SanitizeEmail( | 121 return gaia::CanonicalizeEmail(gaia::SanitizeEmail( |
112 chromeos::UserManager::Get()-> | 122 chromeos::UserManager::Get()-> |
113 GetLRULoggedInUsers()[index]->email())); | 123 GetLRULoggedInUsers()[index]->email())); |
114 } | 124 } |
115 | 125 |
116 const gfx::ImageSkia& SessionStateDelegateChromeos::GetUserImage( | 126 const gfx::ImageSkia& SessionStateDelegateChromeos::GetUserImage( |
117 ash::MultiProfileIndex index) const { | 127 content::BrowserContext* context) const { |
118 DCHECK_LT(index, NumberOfLoggedInUsers()); | 128 DCHECK(context); |
119 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]->image(); | 129 return chromeos::UserManager::Get()->GetUserByProfile( |
| 130 Profile::FromBrowserContext(context))->image(); |
120 } | 131 } |
121 | 132 |
122 void SessionStateDelegateChromeos::GetLoggedInUsers(ash::UserIdList* users) { | 133 bool SessionStateDelegateChromeos::ShouldShowAvatar(aura::Window* window) { |
123 const chromeos::UserList& logged_in_users = | 134 return chrome::MultiUserWindowManager::GetInstance()-> |
124 chromeos::UserManager::Get()->GetLoggedInUsers(); | 135 ShouldShowAvatar(window); |
125 for (chromeos::UserList::const_iterator it = logged_in_users.begin(); | |
126 it != logged_in_users.end(); ++it) { | |
127 const chromeos::User* user = (*it); | |
128 users->push_back(user->email()); | |
129 } | |
130 } | 136 } |
131 | 137 |
132 void SessionStateDelegateChromeos::SwitchActiveUser( | 138 void SessionStateDelegateChromeos::SwitchActiveUser( |
133 const std::string& user_id) { | 139 const std::string& user_id) { |
134 // Disallow switching to an already active user since that might crash. | 140 // Disallow switching to an already active user since that might crash. |
135 // Also check that we got a user id and not an email address. | 141 // Also check that we got a user id and not an email address. |
136 DCHECK_EQ(user_id, | 142 DCHECK_EQ(user_id, |
137 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); | 143 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); |
138 if (user_id == chromeos::UserManager::Get()->GetActiveUser()->email()) | 144 if (user_id == chromeos::UserManager::Get()->GetActiveUser()->email()) |
139 return; | 145 return; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 session_state_observer_list_, | 204 session_state_observer_list_, |
199 ActiveUserChanged(active_user->email())); | 205 ActiveUserChanged(active_user->email())); |
200 } | 206 } |
201 | 207 |
202 void SessionStateDelegateChromeos::UserAddedToSession( | 208 void SessionStateDelegateChromeos::UserAddedToSession( |
203 const chromeos::User* added_user) { | 209 const chromeos::User* added_user) { |
204 FOR_EACH_OBSERVER(ash::SessionStateObserver, | 210 FOR_EACH_OBSERVER(ash::SessionStateObserver, |
205 session_state_observer_list_, | 211 session_state_observer_list_, |
206 UserAddedToSession(added_user->email())); | 212 UserAddedToSession(added_user->email())); |
207 } | 213 } |
OLD | NEW |