| 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 "services/ui/ws/user_id_tracker.h" | 5 #include "services/ui/ws/user_id_tracker.h" |
| 6 | 6 |
| 7 #include "services/shell/public/interfaces/connector.mojom.h" | 7 #include "services/shell/public/interfaces/connector.mojom.h" |
| 8 #include "services/ui/ws/user_id_tracker_observer.h" | 8 #include "services/ui/ws/user_id_tracker_observer.h" |
| 9 | 9 |
| 10 namespace ui { | 10 namespace ui { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 return ids_.count(id) > 0; | 21 return ids_.count(id) > 0; |
| 22 } | 22 } |
| 23 | 23 |
| 24 void UserIdTracker::SetActiveUserId(const UserId& id) { | 24 void UserIdTracker::SetActiveUserId(const UserId& id) { |
| 25 DCHECK(IsValidUserId(id)); | 25 DCHECK(IsValidUserId(id)); |
| 26 if (id == active_id_) | 26 if (id == active_id_) |
| 27 return; | 27 return; |
| 28 | 28 |
| 29 const UserId previously_active_id = active_id_; | 29 const UserId previously_active_id = active_id_; |
| 30 active_id_ = id; | 30 active_id_ = id; |
| 31 FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, | 31 for (auto& observer : observers_) |
| 32 OnActiveUserIdChanged(previously_active_id, id)); | 32 observer.OnActiveUserIdChanged(previously_active_id, id); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void UserIdTracker::AddUserId(const UserId& id) { | 35 void UserIdTracker::AddUserId(const UserId& id) { |
| 36 if (IsValidUserId(id)) | 36 if (IsValidUserId(id)) |
| 37 return; | 37 return; |
| 38 | 38 |
| 39 ids_.insert(id); | 39 ids_.insert(id); |
| 40 FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, OnUserIdAdded(id)); | 40 for (auto& observer : observers_) |
| 41 observer.OnUserIdAdded(id); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void UserIdTracker::RemoveUserId(const UserId& id) { | 44 void UserIdTracker::RemoveUserId(const UserId& id) { |
| 44 DCHECK(IsValidUserId(id)); | 45 DCHECK(IsValidUserId(id)); |
| 45 ids_.erase(id); | 46 ids_.erase(id); |
| 46 FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, OnUserIdRemoved(id)); | 47 for (auto& observer : observers_) |
| 48 observer.OnUserIdRemoved(id); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void UserIdTracker::AddObserver(UserIdTrackerObserver* observer) { | 51 void UserIdTracker::AddObserver(UserIdTrackerObserver* observer) { |
| 50 observers_.AddObserver(observer); | 52 observers_.AddObserver(observer); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void UserIdTracker::RemoveObserver(UserIdTrackerObserver* observer) { | 55 void UserIdTracker::RemoveObserver(UserIdTrackerObserver* observer) { |
| 54 observers_.RemoveObserver(observer); | 56 observers_.RemoveObserver(observer); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void UserIdTracker::Bind(mojom::UserAccessManagerRequest request) { | 59 void UserIdTracker::Bind(mojom::UserAccessManagerRequest request) { |
| 58 bindings_.AddBinding(this, std::move(request)); | 60 bindings_.AddBinding(this, std::move(request)); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void UserIdTracker::SetActiveUser(const mojo::String& user_id) { | 63 void UserIdTracker::SetActiveUser(const mojo::String& user_id) { |
| 62 if (!IsValidUserId(user_id)) | 64 if (!IsValidUserId(user_id)) |
| 63 AddUserId(user_id); | 65 AddUserId(user_id); |
| 64 SetActiveUserId(user_id); | 66 SetActiveUserId(user_id); |
| 65 } | 67 } |
| 66 | 68 |
| 67 } // namespace ws | 69 } // namespace ws |
| 68 } // namespace ui | 70 } // namespace ui |
| OLD | NEW |