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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/window_tracker.h" 5 #include "ui/aura/window_tracker.h"
6 6
7 #include "ui/aura/window.h" 7 #include "ui/aura/window.h"
8 8
9 namespace aura { 9 namespace aura {
10 10
11 WindowTracker::WindowTracker() { 11 WindowTracker::WindowTracker() {
12 } 12 }
13 13
14 WindowTracker::WindowTracker(const WindowList& windows) {
15 // |windows| may contain dups, so call Add() instead of insert().
16 for (auto iter = windows.begin(); iter != windows.end(); iter++)
17 Add(*iter);
18 }
19
14 WindowTracker::~WindowTracker() { 20 WindowTracker::~WindowTracker() {
15 for (Windows::iterator i = windows_.begin(); i != windows_.end(); ++i) 21 while (has_windows())
16 (*i)->RemoveObserver(this); 22 Pop()->RemoveObserver(this);
17 } 23 }
18 24
19 void WindowTracker::Add(Window* window) { 25 void WindowTracker::Add(Window* window) {
20 if (windows_.count(window)) 26 if (Contains(window))
21 return; 27 return;
22 28
23 window->AddObserver(this); 29 window->AddObserver(this);
24 windows_.insert(window); 30 windows_.push_back(window);
25 } 31 }
26 32
27 void WindowTracker::Remove(Window* window) { 33 void WindowTracker::Remove(Window* window) {
28 if (windows_.count(window)) { 34 auto iter = std::find(windows_.begin(), windows_.end(), window);
29 windows_.erase(window); 35 if (iter != windows_.end()) {
36 windows_.erase(iter);
30 window->RemoveObserver(this); 37 window->RemoveObserver(this);
31 } 38 }
32 } 39 }
33 40
34 bool WindowTracker::Contains(Window* window) { 41 bool WindowTracker::Contains(Window* window) {
35 return windows_.count(window) > 0; 42 return std::find(windows_.begin(), windows_.end(), window) != windows_.end();
43 }
44
45 aura::Window* WindowTracker::Pop() {
46 DCHECK(!windows_.empty());
47 aura::Window* window = *windows_.begin();
48 Remove(window);
49 return window;
36 } 50 }
37 51
38 void WindowTracker::OnWindowDestroying(Window* window) { 52 void WindowTracker::OnWindowDestroying(Window* window) {
39 DCHECK_GT(windows_.count(window), 0u); 53 DCHECK(Contains(window));
40 Remove(window); 54 Remove(window);
41 } 55 }
42 56
43 } // namespace aura 57 } // namespace aura
OLDNEW
« 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