| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ | 5 #ifndef UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ |
| 6 #define UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ | 6 #define UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 ~WindowTrackerTemplate() override { | 33 ~WindowTrackerTemplate() override { |
| 34 for (T* window : windows_) | 34 for (T* window : windows_) |
| 35 window->RemoveObserver(this); | 35 window->RemoveObserver(this); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Returns the set of windows being observed. | 38 // Returns the set of windows being observed. |
| 39 const WindowList& windows() const { return windows_; } | 39 const WindowList& windows() const { return windows_; } |
| 40 | 40 |
| 41 // Adds |window| to the set of Windows being tracked. | 41 // Adds |window| to the set of Windows being tracked. |
| 42 void Add(T* window) { | 42 void Add(T* window) { |
| 43 if (ContainsValue(windows_, window)) | 43 if (base::ContainsValue(windows_, window)) |
| 44 return; | 44 return; |
| 45 | 45 |
| 46 window->AddObserver(this); | 46 window->AddObserver(this); |
| 47 windows_.push_back(window); | 47 windows_.push_back(window); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Removes |window| from the set of windows being tracked. | 50 // Removes |window| from the set of windows being tracked. |
| 51 void Remove(T* window) { | 51 void Remove(T* window) { |
| 52 auto iter = std::find(windows_.begin(), windows_.end(), window); | 52 auto iter = std::find(windows_.begin(), windows_.end(), window); |
| 53 if (iter != windows_.end()) { | 53 if (iter != windows_.end()) { |
| 54 window->RemoveObserver(this); | 54 window->RemoveObserver(this); |
| 55 windows_.erase(iter); | 55 windows_.erase(iter); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 T* Pop() { | 59 T* Pop() { |
| 60 DCHECK(!windows_.empty()); | 60 DCHECK(!windows_.empty()); |
| 61 T* result = windows_[0]; | 61 T* result = windows_[0]; |
| 62 Remove(result); | 62 Remove(result); |
| 63 return result; | 63 return result; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Returns true if |window| was previously added and has not been removed or | 66 // Returns true if |window| was previously added and has not been removed or |
| 67 // deleted. | 67 // deleted. |
| 68 bool Contains(T* window) const { return ContainsValue(windows_, window); } | 68 bool Contains(T* window) const { |
| 69 return base::ContainsValue(windows_, window); |
| 70 } |
| 69 | 71 |
| 70 // Observer overrides: | 72 // Observer overrides: |
| 71 void OnWindowDestroying(T* window) override { | 73 void OnWindowDestroying(T* window) override { |
| 72 DCHECK(Contains(window)); | 74 DCHECK(Contains(window)); |
| 73 Remove(window); | 75 Remove(window); |
| 74 } | 76 } |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 WindowList windows_; | 79 WindowList windows_; |
| 78 | 80 |
| 79 DISALLOW_COPY_AND_ASSIGN(WindowTrackerTemplate); | 81 DISALLOW_COPY_AND_ASSIGN(WindowTrackerTemplate); |
| 80 }; | 82 }; |
| 81 | 83 |
| 82 } // namespace ui | 84 } // namespace ui |
| 83 | 85 |
| 84 #endif // UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ | 86 #endif // UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ |
| OLD | NEW |