Index: ash/common/window_user_data.h |
diff --git a/ash/common/wm_window_user_data.h b/ash/common/window_user_data.h |
similarity index 54% |
rename from ash/common/wm_window_user_data.h |
rename to ash/common/window_user_data.h |
index 2a6abd23378aa5a11cc97d7affc4b137bbe6b442..7ee31310b14dd43626d16698144c8a4979ec298b 100644 |
--- a/ash/common/wm_window_user_data.h |
+++ b/ash/common/window_user_data.h |
@@ -2,60 +2,62 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef ASH_COMMON_WM_WINDOW_USER_DATA_H_ |
-#define ASH_COMMON_WM_WINDOW_USER_DATA_H_ |
+#ifndef ASH_COMMON_WINDOW_USER_DATA_H_ |
+#define ASH_COMMON_WINDOW_USER_DATA_H_ |
#include <map> |
#include <memory> |
#include <utility> |
-#include "ash/common/wm_window.h" |
#include "base/macros.h" |
#include "ui/aura/window.h" |
#include "ui/aura/window_observer.h" |
namespace ash { |
-// WmWindowUserData provides a way to associate arbitrary objects with a |
-// WmWindow. WmWindowUserData owns the data, deleting it either when |
-// WmWindowUserData is deleted, or when the window the data is associated with |
+// WindowUserData provides a way to associate an object with a Window and have |
+// that object destroyed when the window is destroyed, or when WindowUserData |
// is destroyed (from aura::WindowObserver::OnWindowDestroying()). |
+// |
+// NOTE: WindowUserData does not make use of the Set/GetProperty API offered |
+// on aura::Window. This is done to avoid collisions in the case of multiple |
+// WindowUserDatas operating on the same Window. |
template <typename UserData> |
-class WmWindowUserData : public aura::WindowObserver { |
+class WindowUserData : public aura::WindowObserver { |
public: |
- WmWindowUserData() {} |
+ WindowUserData() {} |
- ~WmWindowUserData() override { clear(); } |
+ ~WindowUserData() override { clear(); } |
void clear() { |
for (auto& pair : window_to_data_) |
- pair.first->aura_window()->RemoveObserver(this); |
+ pair.first->RemoveObserver(this); |
window_to_data_.clear(); |
} |
// Sets the data associated with window. This destroys any existing data. |
// |data| may be null. |
- void Set(WmWindow* window, std::unique_ptr<UserData> data) { |
+ void Set(aura::Window* window, std::unique_ptr<UserData> data) { |
if (!data) { |
if (window_to_data_.erase(window)) |
- window->aura_window()->RemoveObserver(this); |
+ window->RemoveObserver(this); |
return; |
} |
if (window_to_data_.count(window) == 0u) |
- window->aura_window()->AddObserver(this); |
+ window->AddObserver(this); |
window_to_data_[window] = std::move(data); |
} |
// Returns the data associated with the window, or null if none set. The |
- // returned object is owned by WmWindowUserData. |
- UserData* Get(WmWindow* window) { |
+ // returned object is owned by WindowUserData. |
+ UserData* Get(aura::Window* window) { |
auto it = window_to_data_.find(window); |
return it == window_to_data_.end() ? nullptr : it->second.get(); |
} |
// Returns the set of windows with data associated with them. |
- std::set<WmWindow*> GetWindows() { |
- std::set<WmWindow*> windows; |
+ std::set<aura::Window*> GetWindows() { |
+ std::set<aura::Window*> windows; |
for (auto& pair : window_to_data_) |
windows.insert(pair.first); |
return windows; |
@@ -65,14 +67,14 @@ class WmWindowUserData : public aura::WindowObserver { |
// aura::WindowObserver: |
void OnWindowDestroying(aura::Window* window) override { |
window->RemoveObserver(this); |
- window_to_data_.erase(WmWindow::Get(window)); |
+ window_to_data_.erase(window); |
} |
- std::map<WmWindow*, std::unique_ptr<UserData>> window_to_data_; |
+ std::map<aura::Window*, std::unique_ptr<UserData>> window_to_data_; |
- DISALLOW_COPY_AND_ASSIGN(WmWindowUserData); |
+ DISALLOW_COPY_AND_ASSIGN(WindowUserData); |
}; |
} // namespace ash |
-#endif // ASH_COMMON_WM_WINDOW_USER_DATA_H_ |
+#endif // ASH_COMMON_WINDOW_USER_DATA_H_ |