| 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 "components/mus/ws/user_id_tracker.h" | 5 #include "components/mus/ws/user_id_tracker.h" |
| 6 | 6 |
| 7 #include "components/mus/ws/user_id_tracker_observer.h" | 7 #include "components/mus/ws/user_id_tracker_observer.h" |
| 8 #include "services/shell/public/interfaces/connector.mojom.h" | 8 #include "services/shell/public/interfaces/connector.mojom.h" |
| 9 | 9 |
| 10 namespace mus { | 10 namespace mus { |
| 11 namespace ws { | 11 namespace ws { |
| 12 | 12 |
| 13 UserIdTracker::UserIdTracker() : active_id_(shell::mojom::kRootUserID) { | 13 UserIdTracker::UserIdTracker() : active_id_(shell::mojom::kRootUserID) { |
| 14 ids_.insert(active_id_); | 14 ids_.insert(active_id_); |
| 15 } | 15 } |
| 16 |
| 16 UserIdTracker::~UserIdTracker() { | 17 UserIdTracker::~UserIdTracker() { |
| 17 } | 18 } |
| 18 | 19 |
| 19 bool UserIdTracker::IsValidUserId(const UserId& id) const { | 20 bool UserIdTracker::IsValidUserId(const UserId& id) const { |
| 20 return ids_.count(id) > 0; | 21 return ids_.count(id) > 0; |
| 21 } | 22 } |
| 22 | 23 |
| 23 void UserIdTracker::SetActiveUserId(const UserId& id) { | 24 void UserIdTracker::SetActiveUserId(const UserId& id) { |
| 25 DCHECK(IsValidUserId(id)); |
| 24 if (id == active_id_) | 26 if (id == active_id_) |
| 25 return; | 27 return; |
| 26 | 28 |
| 27 const UserId previously_active_id = active_id_; | 29 const UserId previously_active_id = active_id_; |
| 28 active_id_ = id; | 30 active_id_ = id; |
| 29 FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, | 31 FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, |
| 30 OnActiveUserIdChanged(previously_active_id, id)); | 32 OnActiveUserIdChanged(previously_active_id, id)); |
| 31 } | 33 } |
| 32 | 34 |
| 33 void UserIdTracker::AddUserId(const UserId& id) { | 35 void UserIdTracker::AddUserId(const UserId& id) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 } | 59 } |
| 58 | 60 |
| 59 void UserIdTracker::SetActiveUser(const mojo::String& user_id) { | 61 void UserIdTracker::SetActiveUser(const mojo::String& user_id) { |
| 60 if (!IsValidUserId(user_id)) | 62 if (!IsValidUserId(user_id)) |
| 61 AddUserId(user_id); | 63 AddUserId(user_id); |
| 62 SetActiveUserId(user_id); | 64 SetActiveUserId(user_id); |
| 63 } | 65 } |
| 64 | 66 |
| 65 } // namespace ws | 67 } // namespace ws |
| 66 } // namespace mus | 68 } // namespace mus |
| OLD | NEW |