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

Unified Diff: ui/aura/window_tracker.cc

Issue 1484383003: Use WindowTracker when resizing root window as it may delete other window in unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « ui/aura/window_tracker.h ('k') | ui/wm/core/transient_window_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/window_tracker.cc
diff --git a/ui/aura/window_tracker.cc b/ui/aura/window_tracker.cc
index 9653e5fcf9ea57dc2b147e0e2f34b6d041cdef9b..522a1fc863f7d03a55bf1195a36b887420b6750b 100644
--- a/ui/aura/window_tracker.cc
+++ b/ui/aura/window_tracker.cc
@@ -11,32 +11,46 @@ namespace aura {
WindowTracker::WindowTracker() {
}
+WindowTracker::WindowTracker(const WindowList& windows) {
+ // |windows| may contain dups, so call Add() instead of insert().
+ for (auto iter = windows.begin(); iter != windows.end(); iter++)
+ Add(*iter);
+}
+
WindowTracker::~WindowTracker() {
- for (Windows::iterator i = windows_.begin(); i != windows_.end(); ++i)
- (*i)->RemoveObserver(this);
+ while (has_windows())
+ Pop()->RemoveObserver(this);
}
void WindowTracker::Add(Window* window) {
- if (windows_.count(window))
+ if (Contains(window))
return;
window->AddObserver(this);
- windows_.insert(window);
+ windows_.push_back(window);
}
void WindowTracker::Remove(Window* window) {
- if (windows_.count(window)) {
- windows_.erase(window);
+ auto iter = std::find(windows_.begin(), windows_.end(), window);
+ if (iter != windows_.end()) {
+ windows_.erase(iter);
window->RemoveObserver(this);
}
}
bool WindowTracker::Contains(Window* window) {
- return windows_.count(window) > 0;
+ return std::find(windows_.begin(), windows_.end(), window) != windows_.end();
+}
+
+aura::Window* WindowTracker::Pop() {
+ DCHECK(!windows_.empty());
+ aura::Window* window = *windows_.begin();
+ Remove(window);
+ return window;
}
void WindowTracker::OnWindowDestroying(Window* window) {
- DCHECK_GT(windows_.count(window), 0u);
+ DCHECK(Contains(window));
Remove(window);
}
« no previous file with comments | « ui/aura/window_tracker.h ('k') | ui/wm/core/transient_window_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698