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

Unified Diff: components/mus/ws/user_id_tracker.cc

Issue 1757403002: More user id tracking for mus: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweaks Created 4 years, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/ws/user_id_tracker.cc
diff --git a/components/mus/ws/user_id_tracker.cc b/components/mus/ws/user_id_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..912de1e9476a47e2fb05686136d0e1255b486a04
--- /dev/null
+++ b/components/mus/ws/user_id_tracker.cc
@@ -0,0 +1,53 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/mus/ws/user_id_tracker.h"
+
+#include "components/mus/ws/user_id_tracker_observer.h"
+#include "mojo/shell/public/interfaces/shell.mojom.h"
+
+namespace mus {
+namespace ws {
+
+UserIdTracker::UserIdTracker()
+ : active_id_(mojo::shell::mojom::Connector::kInvalidApplicationID) {}
+UserIdTracker::~UserIdTracker() {
+ DCHECK(ids_.empty());
+}
+
+bool UserIdTracker::IsValidUserId(UserId id) const {
+ return ids_.count(id) > 0;
+}
+
+void UserIdTracker::SetActiveUserId(UserId id) {
+ if (id == active_id_)
+ return;
+
+ active_id_ = id;
+ FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_,
+ OnActiveUserIdChanged(id));
+}
+
+void UserIdTracker::AddUserId(UserId id) {
+ DCHECK(!IsValidUserId(id));
+ ids_.insert(id);
+ FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, OnUserIdAdded(id));
+}
+
+void UserIdTracker::RemoveUserId(UserId id) {
+ DCHECK(IsValidUserId(id));
+ ids_.erase(id);
+ FOR_EACH_OBSERVER(UserIdTrackerObserver, observers_, OnUserIdRemoved(id));
+}
+
+void UserIdTracker::AddObserver(UserIdTrackerObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void UserIdTracker::RemoveObserver(UserIdTrackerObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+} // namespace ws
+} // namespace mus
« 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