Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
| 6 #include "base/single_thread_task_runner.h" | |
| 7 #include "base/thread_task_runner_handle.h" | |
| 6 | 8 |
| 7 namespace base { | 9 namespace base { |
| 8 namespace internal { | 10 namespace internal { |
| 9 | 11 |
| 10 WeakReference::Flag::Flag() : is_valid_(true) { | 12 WeakReference::Flag::Flag() |
| 13 : sequence_checker_(ThreadTaskRunnerHandle::GetIfExists()), | |
| 14 is_valid_(true) { | |
| 11 } | 15 } |
| 12 | 16 |
| 13 void WeakReference::Flag::Invalidate() { | 17 void WeakReference::Flag::Invalidate() { |
| 14 // The flag being invalidated with a single ref implies that there are no | 18 // The flag being invalidated with a single ref implies that there are no |
| 15 // weak pointers in existence. Allow deletion on other thread in this case. | 19 // weak pointers in existence. Allow deletion on other thread in this case. |
| 16 DCHECK(thread_checker_.CalledOnValidThread() || HasOneRef()); | 20 DCHECK(sequence_checker_.CalledInSequence() || HasOneRef()); |
|
jar (doing other things)
2013/02/16 02:37:27
nit: Although the semantics may be as intended (to
| |
| 17 is_valid_ = false; | 21 is_valid_ = false; |
| 18 } | 22 } |
| 19 | 23 |
| 20 bool WeakReference::Flag::IsValid() const { | 24 bool WeakReference::Flag::IsValid() const { |
| 21 DCHECK(thread_checker_.CalledOnValidThread()); | 25 DCHECK(sequence_checker_.CalledInSequence()); |
| 22 return is_valid_; | 26 return is_valid_; |
| 23 } | 27 } |
| 24 | 28 |
| 29 void WeakReference::Flag::DetachFromThread() { | |
| 30 sequence_checker_.ChangeSequence(ThreadTaskRunnerHandle::GetIfExists()); | |
|
jar (doing other things)
2013/02/16 02:37:27
nit: This "ChangeSequence" also seems confusing :-
| |
| 31 } | |
| 32 | |
| 25 WeakReference::Flag::~Flag() { | 33 WeakReference::Flag::~Flag() { |
| 26 } | 34 } |
| 27 | 35 |
| 28 WeakReference::WeakReference() { | 36 WeakReference::WeakReference() { |
| 29 } | 37 } |
| 30 | 38 |
| 31 WeakReference::WeakReference(const Flag* flag) : flag_(flag) { | 39 WeakReference::WeakReference(const Flag* flag) : flag_(flag) { |
| 32 } | 40 } |
| 33 | 41 |
| 34 WeakReference::~WeakReference() { | 42 WeakReference::~WeakReference() { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 64 } | 72 } |
| 65 | 73 |
| 66 WeakPtrBase::~WeakPtrBase() { | 74 WeakPtrBase::~WeakPtrBase() { |
| 67 } | 75 } |
| 68 | 76 |
| 69 WeakPtrBase::WeakPtrBase(const WeakReference& ref) : ref_(ref) { | 77 WeakPtrBase::WeakPtrBase(const WeakReference& ref) : ref_(ref) { |
| 70 } | 78 } |
| 71 | 79 |
| 72 } // namespace internal | 80 } // namespace internal |
| 73 } // namespace base | 81 } // namespace base |
| OLD | NEW |