OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 "components/view_manager/public/cpp/view_tracker.h" | |
6 | |
7 namespace mojo { | |
8 | |
9 ViewTracker::ViewTracker() { | |
10 } | |
11 | |
12 ViewTracker::~ViewTracker() { | |
13 for (Views::iterator i = views_.begin(); i != views_.end(); ++i) | |
14 (*i)->RemoveObserver(this); | |
15 } | |
16 | |
17 void ViewTracker::Add(View* view) { | |
18 if (views_.count(view)) | |
19 return; | |
20 | |
21 view->AddObserver(this); | |
22 views_.insert(view); | |
23 } | |
24 | |
25 void ViewTracker::Remove(View* view) { | |
26 if (views_.count(view)) { | |
27 views_.erase(view); | |
28 view->RemoveObserver(this); | |
29 } | |
30 } | |
31 | |
32 bool ViewTracker::Contains(View* view) { | |
33 return views_.count(view) > 0; | |
34 } | |
35 | |
36 void ViewTracker::OnViewDestroying(View* view) { | |
37 DCHECK_GT(views_.count(view), 0u); | |
38 Remove(view); | |
39 } | |
40 | |
41 } // namespace mojo | |
OLD | NEW |