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

Unified Diff: ui/aura/window_id_registry.cc

Issue 100603002: Add aura::WindowIdRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | « ui/aura/window_id_registry.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/window_id_registry.cc
diff --git a/ui/aura/window_id_registry.cc b/ui/aura/window_id_registry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a666164ce02625521e17f948f46b8b8bd5271fda
--- /dev/null
+++ b/ui/aura/window_id_registry.cc
@@ -0,0 +1,49 @@
+// Copyright 2013 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 "ui/aura/window_id_registry.h"
+
+#include "ui/aura/window.h"
+
+namespace aura {
+
+// static
+WindowIdRegistry* WindowIdRegistry::GetInstance() {
+ return Singleton<WindowIdRegistry>::get();
+}
+
+int WindowIdRegistry::GetIdForWindow(Window* window) {
+ // First check if an Id is already assigned to the |window|.
+ std::map<Window*, int>::iterator it = window_to_id_map_.find(window);
+ if (it != window_to_id_map_.end()) {
+ return it->second;
+ }
+
+ // If the windows doesn't have an Id yet assign it.
+ int id = next_id_++;
+ window_to_id_map_[window] = id;
+ id_to_window_map_[id] = window;
+ window->AddObserver(this);
+ return id;
+}
+
+Window* WindowIdRegistry::GetWindowById(int id) {
+ std::map<int, Window*>::iterator it = id_to_window_map_.find(id);
+ return (it != id_to_window_map_.end()) ? it->second : NULL;
+}
+
+WindowIdRegistry::WindowIdRegistry()
+ : next_id_(0) {
+}
+
+WindowIdRegistry::~WindowIdRegistry() {}
+
+void WindowIdRegistry::OnWindowDestroying(Window* window) {
+ std::map<Window*, int>::iterator it = window_to_id_map_.find(window);
+ DCHECK(it != window_to_id_map_.end());
+ id_to_window_map_.erase(it->second);
+ window_to_id_map_.erase(it);
+}
+
+} // namespace aura
« no previous file with comments | « ui/aura/window_id_registry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698