| 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 <stddef.h> |
| 9 |
| 8 #include <algorithm> | 10 #include <algorithm> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" |
| 13 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 14 | 16 |
| 15 // ScopedObserver is used to keep track of the set of sources an object has | 17 // ScopedObserver is used to keep track of the set of sources an object has |
| 16 // attached itself to as an observer. When ScopedObserver is destroyed it | 18 // attached itself to as an observer. When ScopedObserver is destroyed it |
| 17 // removes the object as an observer from all sources it has been added to. | 19 // removes the object as an observer from all sources it has been added to. |
| 18 template <class Source, class Observer> | 20 template <class Source, class Observer> |
| 19 class ScopedObserver { | 21 class ScopedObserver { |
| 20 public: | 22 public: |
| 21 explicit ScopedObserver(Observer* observer) : observer_(observer) {} | 23 explicit ScopedObserver(Observer* observer) : observer_(observer) {} |
| 22 | 24 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 | 54 |
| 53 private: | 55 private: |
| 54 Observer* observer_; | 56 Observer* observer_; |
| 55 | 57 |
| 56 std::vector<Source*> sources_; | 58 std::vector<Source*> sources_; |
| 57 | 59 |
| 58 DISALLOW_COPY_AND_ASSIGN(ScopedObserver); | 60 DISALLOW_COPY_AND_ASSIGN(ScopedObserver); |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 #endif // BASE_SCOPED_OBSERVER_H_ | 63 #endif // BASE_SCOPED_OBSERVER_H_ |
| OLD | NEW |