• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "ui/aura/window_tracker.h"
6 
7 #include "ui/aura/window.h"
8 
9 namespace aura {
10 
WindowTracker()11 WindowTracker::WindowTracker() {
12 }
13 
~WindowTracker()14 WindowTracker::~WindowTracker() {
15   for (Windows::iterator i = windows_.begin(); i != windows_.end(); ++i)
16     (*i)->RemoveObserver(this);
17 }
18 
Add(Window * window)19 void WindowTracker::Add(Window* window) {
20   if (windows_.count(window))
21     return;
22 
23   window->AddObserver(this);
24   windows_.insert(window);
25 }
26 
Remove(Window * window)27 void WindowTracker::Remove(Window* window) {
28   if (windows_.count(window)) {
29     windows_.erase(window);
30     window->RemoveObserver(this);
31   }
32 }
33 
Contains(Window * window)34 bool WindowTracker::Contains(Window* window) {
35   return windows_.count(window) > 0;
36 }
37 
OnWindowDestroying(Window * window)38 void WindowTracker::OnWindowDestroying(Window* window) {
39   DCHECK_GT(windows_.count(window), 0u);
40   Remove(window);
41 }
42 
43 }  // namespace aura
44