OLD | NEW |
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 "ash/common/session/session_controller.h" | 5 #include "ash/common/session/session_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/common/session/session_state_observer.h" | 9 #include "ash/common/session/session_state_observer.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return user_sessions_; | 63 return user_sessions_; |
64 } | 64 } |
65 | 65 |
66 void SessionController::LockScreen() { | 66 void SessionController::LockScreen() { |
67 if (client_) | 67 if (client_) |
68 client_->RequestLockScreen(); | 68 client_->RequestLockScreen(); |
69 } | 69 } |
70 | 70 |
71 void SessionController::SwitchActiveUser(const AccountId& account_id) { | 71 void SessionController::SwitchActiveUser(const AccountId& account_id) { |
72 if (client_) | 72 if (client_) |
73 client_->SwitchActiveUser(account_id.Serialize()); | 73 client_->SwitchActiveUser(account_id); |
74 } | 74 } |
75 | 75 |
76 void SessionController::CycleActiveUser(bool next_user) { | 76 void SessionController::CycleActiveUser(bool next_user) { |
77 if (client_) | 77 if (client_) |
78 client_->CycleActiveUser(next_user); | 78 client_->CycleActiveUser(next_user); |
79 } | 79 } |
80 | 80 |
81 void SessionController::AddSessionStateObserver( | 81 void SessionController::AddSessionStateObserver( |
82 SessionStateObserver* observer) { | 82 SessionStateObserver* observer) { |
83 observers_.AddObserver(observer); | 83 observers_.AddObserver(observer); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 } | 134 } |
135 | 135 |
136 sessions.push_back(std::move(*it)); | 136 sessions.push_back(std::move(*it)); |
137 } | 137 } |
138 user_sessions_.swap(sessions); | 138 user_sessions_.swap(sessions); |
139 | 139 |
140 // Check active user change and notifies observers. | 140 // Check active user change and notifies observers. |
141 if (user_sessions_[0]->session_id != active_session_id_) { | 141 if (user_sessions_[0]->session_id != active_session_id_) { |
142 active_session_id_ = user_sessions_[0]->session_id; | 142 active_session_id_ = user_sessions_[0]->session_id; |
143 | 143 |
144 AccountId account_id(EmptyAccountId()); | 144 for (auto& observer : observers_) |
145 if (AccountId::Deserialize(user_sessions_[0]->serialized_account_id, | 145 observer.ActiveUserChanged(user_sessions_[0]->account_id); |
146 &account_id)) { | |
147 for (auto& observer : observers_) | |
148 observer.ActiveUserChanged(account_id); | |
149 } | |
150 } | 146 } |
151 } | 147 } |
152 | 148 |
153 void SessionController::SetSessionState(session_manager::SessionState state) { | 149 void SessionController::SetSessionState(session_manager::SessionState state) { |
154 if (state_ == state) | 150 if (state_ == state) |
155 return; | 151 return; |
156 | 152 |
157 state_ = state; | 153 state_ = state; |
158 for (auto& observer : observers_) | 154 for (auto& observer : observers_) |
159 observer.SessionStateChanged(state_); | 155 observer.SessionStateChanged(state_); |
160 } | 156 } |
161 | 157 |
162 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { | 158 void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { |
163 AccountId account_id(EmptyAccountId()); | 159 const AccountId account_id(user_session->account_id); |
164 if (!AccountId::Deserialize(user_session->serialized_account_id, | |
165 &account_id)) { | |
166 LOG(ERROR) << "Failed to deserialize account id."; | |
167 return; | |
168 } | |
169 | 160 |
170 user_sessions_.push_back(std::move(user_session)); | 161 user_sessions_.push_back(std::move(user_session)); |
171 | 162 |
172 for (auto& observer : observers_) | 163 for (auto& observer : observers_) |
173 observer.UserAddedToSession(account_id); | 164 observer.UserAddedToSession(account_id); |
174 } | 165 } |
175 | 166 |
176 } // namespace ash | 167 } // namespace ash |
OLD | NEW |