| OLD | NEW |
| 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 (windows_.count(window)) |
| 21 return; | 27 return; |
| 22 | 28 |
| 23 window->AddObserver(this); | 29 window->AddObserver(this); |
| 24 windows_.insert(window); | 30 windows_.insert(window); |
| 25 } | 31 } |
| 26 | 32 |
| 27 void WindowTracker::Remove(Window* window) { | 33 void WindowTracker::Remove(Window* window) { |
| 28 if (windows_.count(window)) { | 34 if (windows_.count(window)) { |
| 29 windows_.erase(window); | 35 windows_.erase(window); |
| 30 window->RemoveObserver(this); | 36 window->RemoveObserver(this); |
| 31 } | 37 } |
| 32 } | 38 } |
| 33 | 39 |
| 34 bool WindowTracker::Contains(Window* window) { | 40 bool WindowTracker::Contains(Window* window) { |
| 35 return windows_.count(window) > 0; | 41 return windows_.count(window) > 0; |
| 36 } | 42 } |
| 37 | 43 |
| 44 aura::Window* WindowTracker::Pop() { |
| 45 DCHECK(!windows_.empty()); |
| 46 aura::Window* window = *windows_.begin(); |
| 47 Remove(window); |
| 48 return window; |
| 49 } |
| 50 |
| 38 void WindowTracker::OnWindowDestroying(Window* window) { | 51 void WindowTracker::OnWindowDestroying(Window* window) { |
| 39 DCHECK_GT(windows_.count(window), 0u); | 52 DCHECK_GT(windows_.count(window), 0u); |
| 40 Remove(window); | 53 Remove(window); |
| 41 } | 54 } |
| 42 | 55 |
| 43 } // namespace aura | 56 } // namespace aura |
| OLD | NEW |