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

Unified Diff: ash/common/wm_window_user_data.h

Issue 2736573002: chromeos: Move files in //ash/common to //ash, part 2 (Closed)
Patch Set: Created 3 years, 9 months 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 | « ash/common/wm_window_unittest.cc ('k') | ash/common/wm_window_user_data_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/wm_window_user_data.h
diff --git a/ash/common/wm_window_user_data.h b/ash/common/wm_window_user_data.h
deleted file mode 100644
index 2a6abd23378aa5a11cc97d7affc4b137bbe6b442..0000000000000000000000000000000000000000
--- a/ash/common/wm_window_user_data.h
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2016 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 ASH_COMMON_WM_WINDOW_USER_DATA_H_
-#define ASH_COMMON_WM_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
-// is destroyed (from aura::WindowObserver::OnWindowDestroying()).
-template <typename UserData>
-class WmWindowUserData : public aura::WindowObserver {
- public:
- WmWindowUserData() {}
-
- ~WmWindowUserData() override { clear(); }
-
- void clear() {
- for (auto& pair : window_to_data_)
- pair.first->aura_window()->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) {
- if (!data) {
- if (window_to_data_.erase(window))
- window->aura_window()->RemoveObserver(this);
- return;
- }
- if (window_to_data_.count(window) == 0u)
- window->aura_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) {
- 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;
- for (auto& pair : window_to_data_)
- windows.insert(pair.first);
- return windows;
- }
-
- private:
- // aura::WindowObserver:
- void OnWindowDestroying(aura::Window* window) override {
- window->RemoveObserver(this);
- window_to_data_.erase(WmWindow::Get(window));
- }
-
- std::map<WmWindow*, std::unique_ptr<UserData>> window_to_data_;
-
- DISALLOW_COPY_AND_ASSIGN(WmWindowUserData);
-};
-
-} // namespace ash
-
-#endif // ASH_COMMON_WM_WINDOW_USER_DATA_H_
« no previous file with comments | « ash/common/wm_window_unittest.cc ('k') | ash/common/wm_window_user_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698