OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 #ifndef UI_AURA_WINDOW_ID_REGISTRY_H_ |
| 6 #define UI_AURA_WINDOW_ID_REGISTRY_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/singleton.h" |
| 13 #include "ui/aura/aura_export.h" |
| 14 #include "ui/aura/window_observer.h" |
| 15 |
| 16 namespace aura { |
| 17 |
| 18 // WindowIdRegistry assigns unique identifiers to Aura windows. |
| 19 class AURA_EXPORT WindowIdRegistry : public WindowObserver { |
| 20 public: |
| 21 static WindowIdRegistry* GetInstance(); |
| 22 |
| 23 // Returns unique Id for |window|. New Id is allocated when this method is |
| 24 // called for the |window| for the first time. |
| 25 int GetIdForWindow(Window* window); |
| 26 |
| 27 // Returns window with the specified |id|. NULL is returned if the |id| is |
| 28 // invalid or the window it refers to was destroyed. |
| 29 Window* GetWindowById(int id); |
| 30 |
| 31 private: |
| 32 friend struct DefaultSingletonTraits<WindowIdRegistry>; |
| 33 WindowIdRegistry(); |
| 34 virtual ~WindowIdRegistry(); |
| 35 |
| 36 // WindowObserver overrides. |
| 37 virtual void OnWindowDestroying(Window* window) OVERRIDE; |
| 38 |
| 39 int next_id_; |
| 40 std::map<Window*, int> window_to_id_map_; |
| 41 std::map<int, Window*> id_to_window_map_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(WindowIdRegistry); |
| 44 }; |
| 45 |
| 46 } // namespace aura |
| 47 |
| 48 #endif // UI_AURA_WINDOW_ID_REGISTRY_H_ |
OLD | NEW |