• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 "base/memory/weak_ptr.h"
6 
7 namespace base {
8 namespace internal {
9 
Flag(Flag ** handle)10 WeakReference::Flag::Flag(Flag** handle) : handle_(handle) {
11 }
12 
Invalidate()13 void WeakReference::Flag::Invalidate() {
14   DCHECK(thread_checker_.CalledOnValidThread());
15   handle_ = NULL;
16 }
17 
IsValid() const18 bool WeakReference::Flag::IsValid() const {
19   DCHECK(thread_checker_.CalledOnValidThread());
20   return handle_ != NULL;
21 }
22 
~Flag()23 WeakReference::Flag::~Flag() {
24   if (handle_)
25     *handle_ = NULL;
26 }
27 
WeakReference()28 WeakReference::WeakReference() {
29 }
30 
WeakReference(Flag * flag)31 WeakReference::WeakReference(Flag* flag) : flag_(flag) {
32 }
33 
~WeakReference()34 WeakReference::~WeakReference() {
35 }
36 
is_valid() const37 bool WeakReference::is_valid() const {
38   return flag_ && flag_->IsValid();
39 }
40 
WeakReferenceOwner()41 WeakReferenceOwner::WeakReferenceOwner() : flag_(NULL) {
42 }
43 
~WeakReferenceOwner()44 WeakReferenceOwner::~WeakReferenceOwner() {
45   Invalidate();
46 }
47 
GetRef() const48 WeakReference WeakReferenceOwner::GetRef() const {
49   if (!flag_)
50     flag_ = new WeakReference::Flag(&flag_);
51   return WeakReference(flag_);
52 }
53 
Invalidate()54 void WeakReferenceOwner::Invalidate() {
55   if (flag_) {
56     flag_->Invalidate();
57     flag_ = NULL;
58   }
59 }
60 
WeakPtrBase()61 WeakPtrBase::WeakPtrBase() {
62 }
63 
~WeakPtrBase()64 WeakPtrBase::~WeakPtrBase() {
65 }
66 
WeakPtrBase(const WeakReference & ref)67 WeakPtrBase::WeakPtrBase(const WeakReference& ref) : ref_(ref) {
68 }
69 
70 }  // namespace internal
71 }  // namespace base
72