summaryrefslogtreecommitdiffstats
path: root/base/memory/weak_ptr.h
diff options
context:
space:
mode:
Diffstat (limited to 'base/memory/weak_ptr.h')
-rw-r--r--base/memory/weak_ptr.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h
index edb9d93..0c6b4a7 100644
--- a/base/memory/weak_ptr.h
+++ b/base/memory/weak_ptr.h
@@ -55,7 +55,7 @@
#include "base/base_api.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
-#include "base/threading/non_thread_safe.h"
+#include "base/threading/thread_checker.h"
namespace base {
@@ -65,19 +65,23 @@ namespace internal {
class BASE_API WeakReference {
public:
- class Flag : public RefCounted<Flag>, public base::NonThreadSafe {
+ // While Flag is bound to a specific thread, it may be deleted from another
+ // via base::WeakPtr::~WeakPtr().
+ class Flag : public RefCountedThreadSafe<Flag> {
public:
- Flag(Flag** handle);
- ~Flag();
+ explicit Flag(Flag** handle);
- void AddRef() const;
- void Release() const;
void Invalidate();
bool IsValid() const;
- void DetachFromThread() { base::NonThreadSafe::DetachFromThread(); }
+ void DetachFromThread() { thread_checker_.DetachFromThread(); }
private:
+ friend class base::RefCountedThreadSafe<Flag>;
+
+ ~Flag();
+
+ ThreadChecker thread_checker_;
Flag** handle_;
};
@@ -235,6 +239,11 @@ class WeakPtrFactory {
return weak_reference_owner_.HasRefs();
}
+ // Indicates that this object will be used on another thread from now on.
+ void DetachFromThread() {
+ weak_reference_owner_.DetachFromThread();
+ }
+
private:
internal::WeakReferenceOwner weak_reference_owner_;
T* ptr_;