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 #ifndef BASE_SCOPED_OBSERVER_H_ | 5 #ifndef BASE_SCOPED_OBSERVER_H_ |
6 #define BASE_SCOPED_OBSERVER_H_ | 6 #define BASE_SCOPED_OBSERVER_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 for (size_t i = 0; i < sources_.size(); ++i) | 41 for (size_t i = 0; i < sources_.size(); ++i) |
42 sources_[i]->RemoveObserver(observer_); | 42 sources_[i]->RemoveObserver(observer_); |
43 sources_.clear(); | 43 sources_.clear(); |
44 } | 44 } |
45 | 45 |
46 bool IsObserving(Source* source) const { | 46 bool IsObserving(Source* source) const { |
47 return std::find(sources_.begin(), sources_.end(), source) != | 47 return std::find(sources_.begin(), sources_.end(), source) != |
48 sources_.end(); | 48 sources_.end(); |
49 } | 49 } |
50 | 50 |
| 51 bool IsObservingSources() const { return !sources_.empty(); } |
| 52 |
51 private: | 53 private: |
52 Observer* observer_; | 54 Observer* observer_; |
53 | 55 |
54 std::vector<Source*> sources_; | 56 std::vector<Source*> sources_; |
55 | 57 |
56 DISALLOW_COPY_AND_ASSIGN(ScopedObserver); | 58 DISALLOW_COPY_AND_ASSIGN(ScopedObserver); |
57 }; | 59 }; |
58 | 60 |
59 #endif // BASE_SCOPED_OBSERVER_H_ | 61 #endif // BASE_SCOPED_OBSERVER_H_ |
OLD | NEW |