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

Unified Diff: mojo/services/view_manager/cpp/view_tracker.cc

Issue 1536713004: Revert "Delete the ViewManager and WindowManager services." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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 | « mojo/services/view_manager/cpp/view_tracker.h ('k') | mojo/services/view_manager/interfaces/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/view_manager/cpp/view_tracker.cc
diff --git a/mojo/services/view_manager/cpp/view_tracker.cc b/mojo/services/view_manager/cpp/view_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..35ab3d47670a5ce6ce19d80bad998bfbdc07ffc7
--- /dev/null
+++ b/mojo/services/view_manager/cpp/view_tracker.cc
@@ -0,0 +1,40 @@
+// Copyright 2014 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 "view_manager/cpp/view_tracker.h"
+
+namespace mojo {
+
+ViewTracker::ViewTracker() {}
+
+ViewTracker::~ViewTracker() {
+ for (Views::iterator i = views_.begin(); i != views_.end(); ++i)
+ (*i)->RemoveObserver(this);
+}
+
+void ViewTracker::Add(View* view) {
+ if (views_.count(view))
+ return;
+
+ view->AddObserver(this);
+ views_.insert(view);
+}
+
+void ViewTracker::Remove(View* view) {
+ if (views_.count(view)) {
+ views_.erase(view);
+ view->RemoveObserver(this);
+ }
+}
+
+bool ViewTracker::Contains(View* view) {
+ return views_.count(view) > 0;
+}
+
+void ViewTracker::OnViewDestroying(View* view) {
+ DCHECK_GT(views_.count(view), 0u);
+ Remove(view);
+}
+
+} // namespace mojo
« no previous file with comments | « mojo/services/view_manager/cpp/view_tracker.h ('k') | mojo/services/view_manager/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698