Index: ui/aura/window_id_registry.h |
diff --git a/ui/aura/window_id_registry.h b/ui/aura/window_id_registry.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..595bc865eec1e91aff198a1dbab67b9cfbbea791 |
--- /dev/null |
+++ b/ui/aura/window_id_registry.h |
@@ -0,0 +1,48 @@ |
+// 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. |
+ |
+#ifndef UI_AURA_WINDOW_ID_REGISTRY_H_ |
+#define UI_AURA_WINDOW_ID_REGISTRY_H_ |
+ |
+#include <map> |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "base/memory/singleton.h" |
+#include "ui/aura/aura_export.h" |
+#include "ui/aura/window_observer.h" |
+ |
+namespace aura { |
+ |
+// WindowIdRegistry assigns unique identifiers to Aura windows. |
+class AURA_EXPORT WindowIdRegistry : public WindowObserver { |
+ public: |
+ static WindowIdRegistry* GetInstance(); |
+ |
+ // Returns unique Id for |window|. New Id is allocated when this method is |
+ // called for the |window| for the first time. |
+ int GetIdForWindow(Window* window); |
+ |
+ // Returns window with the specified |id|. NULL is returned if the |id| is |
+ // invalid or the window it refers to was destroyed. |
+ Window* GetWindowById(int id); |
+ |
+ private: |
+ friend struct DefaultSingletonTraits<WindowIdRegistry>; |
+ WindowIdRegistry(); |
+ virtual ~WindowIdRegistry(); |
+ |
+ // WindowObserver overrides. |
+ virtual void OnWindowDestroying(Window* window) OVERRIDE; |
+ |
+ int next_id_; |
+ std::map<Window*, int> window_to_id_map_; |
+ std::map<int, Window*> id_to_window_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WindowIdRegistry); |
+}; |
+ |
+} // namespace aura |
+ |
+#endif // UI_AURA_WINDOW_ID_REGISTRY_H_ |