[M73 Dev][Tizen] Fix compilation errors for TV profile
[platform/framework/web/chromium-efl.git] / base / observer_list_types.h
1 // Copyright 2018 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 #ifndef BASE_OBSERVER_LIST_TYPES_H_
6 #define BASE_OBSERVER_LIST_TYPES_H_
7
8 #include "base/base_export.h"
9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h"
11
12 namespace base {
13 namespace internal {
14 class CheckedObserverAdapter;
15 }
16
17 // A CheckedObserver serves as a base class for an observer interface designed
18 // to be used with base::ObserverList. It helps detect potential use-after-free
19 // issues that can occur when observers fail to remove themselves from an
20 // observer list upon destruction.
21 //
22 // A CheckedObserver will CHECK() if an ObserverList iteration is attempted over
23 // a destroyed Observer.
24 //
25 // Note that a CheckedObserver subclass must be deleted on the same thread as
26 // the ObserverList(s) it is added to. This is DCHECK()ed via WeakPtr.
27 class BASE_EXPORT CheckedObserver {
28  public:
29   CheckedObserver();
30
31  protected:
32   virtual ~CheckedObserver();
33
34   // Returns whether |this| is in any ObserverList. Subclasses can CHECK() this
35   // in their destructor to obtain a nicer stacktrace.
36   bool IsInObserverList() const;
37
38  private:
39   friend class internal::CheckedObserverAdapter;
40
41   // Must be mutable to allow ObserverList<const Foo>.
42   mutable WeakPtrFactory<CheckedObserver> factory_;
43
44   DISALLOW_COPY_AND_ASSIGN(CheckedObserver);
45 };
46
47 }  // namespace base
48
49 #endif  // BASE_OBSERVER_LIST_TYPES_H_