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

Side by Side Diff: chrome/browser/ui/ash/session_controller_client.cc

Issue 2573703003: chromeos: Fix shelf appearing at login screen under mash (Closed)
Patch Set: msw comments Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_controller_client.h" 5 #include "chrome/browser/ui/ash/session_controller_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/public/cpp/session_types.h" 10 #include "ash/public/cpp/session_types.h"
(...skipping 18 matching lines...) Expand all
29 29
30 using user_manager::UserManager; 30 using user_manager::UserManager;
31 using user_manager::User; 31 using user_manager::User;
32 using user_manager::UserList; 32 using user_manager::UserList;
33 33
34 namespace { 34 namespace {
35 35
36 // Limits the number of logged in users to 10 due to memory constraints. 36 // Limits the number of logged in users to 10 due to memory constraints.
37 constexpr uint32_t kMaxUsers = 10; 37 constexpr uint32_t kMaxUsers = 10;
38 38
39 SessionControllerClient* g_instance = nullptr;
40
39 uint32_t GetSessionId(const User* user) { 41 uint32_t GetSessionId(const User* user) {
40 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers(); 42 const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers();
41 // TODO(xiyuan): Update with real session id when user session tracking 43 // TODO(xiyuan): Update with real session id when user session tracking
42 // code is moved from UserManager to SessionManager. 44 // code is moved from UserManager to SessionManager.
43 for (size_t i = 0; i < logged_in_users.size(); ++i) { 45 for (size_t i = 0; i < logged_in_users.size(); ++i) {
44 if (logged_in_users[i] == user) 46 if (logged_in_users[i] == user)
45 return i + 1; 47 return i + 1;
46 } 48 }
47 49
48 NOTREACHED(); 50 NOTREACHED();
(...skipping 29 matching lines...) Expand all
78 } // namespace 80 } // namespace
79 81
80 SessionControllerClient::SessionControllerClient() : binding_(this) { 82 SessionControllerClient::SessionControllerClient() : binding_(this) {
81 session_manager::SessionManager::Get()->AddObserver(this); 83 session_manager::SessionManager::Get()->AddObserver(this);
82 UserManager::Get()->AddSessionStateObserver(this); 84 UserManager::Get()->AddSessionStateObserver(this);
83 85
84 ConnectToSessionControllerAndSetClient(); 86 ConnectToSessionControllerAndSetClient();
85 SendSessionInfoIfChanged(); 87 SendSessionInfoIfChanged();
86 // User sessions and their order will be sent via UserSessionStateObserver 88 // User sessions and their order will be sent via UserSessionStateObserver
87 // even for crash-n-restart. 89 // even for crash-n-restart.
90
91 DCHECK(!g_instance);
92 g_instance = this;
88 } 93 }
89 94
90 SessionControllerClient::~SessionControllerClient() { 95 SessionControllerClient::~SessionControllerClient() {
96 DCHECK_EQ(this, g_instance);
97 g_instance = nullptr;
98
91 session_manager::SessionManager::Get()->RemoveObserver(this); 99 session_manager::SessionManager::Get()->RemoveObserver(this);
92 UserManager::Get()->RemoveSessionStateObserver(this); 100 UserManager::Get()->RemoveSessionStateObserver(this);
93 } 101 }
94 102
95 void SessionControllerClient::RequestLockScreen() { 103 void SessionControllerClient::RequestLockScreen() {
96 DoLockScreen(); 104 DoLockScreen();
97 } 105 }
98 106
99 void SessionControllerClient::SwitchActiveUser( 107 void SessionControllerClient::SwitchActiveUser(
100 const std::string& serialized_account_id) { 108 const std::string& serialized_account_id) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 account_id = (*it)->GetAccountId(); 227 account_id = (*it)->GetAccountId();
220 } else { 228 } else {
221 if (it == logged_in_users.begin()) 229 if (it == logged_in_users.begin())
222 it = logged_in_users.end(); 230 it = logged_in_users.end();
223 account_id = (*(--it))->GetAccountId(); 231 account_id = (*(--it))->GetAccountId();
224 } 232 }
225 233
226 DoSwitchActiveUser(account_id); 234 DoSwitchActiveUser(account_id);
227 } 235 }
228 236
237 // static
238 void SessionControllerClient::FlushForTesting() {
239 g_instance->session_controller_.FlushForTesting();
240 }
241
229 void SessionControllerClient::OnSessionStateChanged() { 242 void SessionControllerClient::OnSessionStateChanged() {
230 SendSessionInfoIfChanged(); 243 SendSessionInfoIfChanged();
231 } 244 }
232 245
233 void SessionControllerClient::ConnectToSessionControllerAndSetClient() { 246 void SessionControllerClient::ConnectToSessionControllerAndSetClient() {
234 content::ServiceManagerConnection::GetForProcess() 247 content::ServiceManagerConnection::GetForProcess()
235 ->GetConnector() 248 ->GetConnector()
236 ->ConnectToInterface(ash_util::GetAshServiceName(), &session_controller_); 249 ->ConnectToInterface(ash_util::GetAshServiceName(), &session_controller_);
237 250
238 // Set as |session_controller_|'s client. 251 // Set as |session_controller_|'s client.
(...skipping 21 matching lines...) Expand all
260 void SessionControllerClient::SendUserSessionOrder() { 273 void SessionControllerClient::SendUserSessionOrder() {
261 UserManager* const user_manager = UserManager::Get(); 274 UserManager* const user_manager = UserManager::Get();
262 275
263 const UserList logged_in_users = user_manager->GetLoggedInUsers(); 276 const UserList logged_in_users = user_manager->GetLoggedInUsers();
264 std::vector<uint32_t> user_session_ids; 277 std::vector<uint32_t> user_session_ids;
265 for (auto* user : user_manager->GetLRULoggedInUsers()) 278 for (auto* user : user_manager->GetLRULoggedInUsers())
266 user_session_ids.push_back(GetSessionId(user)); 279 user_session_ids.push_back(GetSessionId(user));
267 280
268 session_controller_->SetUserSessionOrder(user_session_ids); 281 session_controller_->SetUserSessionOrder(user_session_ids);
269 } 282 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/session_controller_client.h ('k') | chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698