| 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
|
|
|