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

Side by Side Diff: components/mus/ws/user_id_tracker.cc

Issue 2119963002: Move mus to //services/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months 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
« no previous file with comments | « components/mus/ws/user_id_tracker.h ('k') | components/mus/ws/user_id_tracker_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/mus/ws/user_id_tracker.h"
6
7 #include "components/mus/ws/user_id_tracker_observer.h"
8 #include "services/shell/public/interfaces/connector.mojom.h"
9
10 namespace mus {
11 namespace ws {
12
13 UserIdTracker::UserIdTracker() : active_id_(shell::mojom::kRootUserID) {
14 ids_.insert(active_id_);
15 }
16
17 UserIdTracker::~UserIdTracker() {
18 }
19
20 bool UserIdTracker::IsValidUserId(const UserId& id) const {
21 return ids_.count(id) > 0;
22 }
23
24 void UserIdTracker::SetActiveUserId(const UserId& id) {
25 DCHECK(IsValidUserId(id));
26 if (id == active_id_)
27 return;
28
29 const UserId previously_active_id = active_id_;
30 active_id_ = id;
31 FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_,
32 OnActiveUserIdChanged(previously_active_id, id));
33 }
34
35 void UserIdTracker::AddUserId(const UserId& id) {
36 if (IsValidUserId(id))
37 return;
38
39 ids_.insert(id);
40 FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, OnUserIdAdded(id));
41 }
42
43 void UserIdTracker::RemoveUserId(const UserId& id) {
44 DCHECK(IsValidUserId(id));
45 ids_.erase(id);
46 FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, OnUserIdRemoved(id));
47 }
48
49 void UserIdTracker::AddObserver(UserIdTrackerObserver* observer) {
50 observers_.AddObserver(observer);
51 }
52
53 void UserIdTracker::RemoveObserver(UserIdTrackerObserver* observer) {
54 observers_.RemoveObserver(observer);
55 }
56
57 void UserIdTracker::Bind(mojom::UserAccessManagerRequest request) {
58 bindings_.AddBinding(this, std::move(request));
59 }
60
61 void UserIdTracker::SetActiveUser(const mojo::String& user_id) {
62 if (!IsValidUserId(user_id))
63 AddUserId(user_id);
64 SetActiveUserId(user_id);
65 }
66
67 } // namespace ws
68 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/user_id_tracker.h ('k') | components/mus/ws/user_id_tracker_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698