| 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 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/callback_internal.h" | 8 #include "base/callback_internal.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 TestForReentrancy tfr; | 141 TestForReentrancy tfr; |
| 142 ASSERT_FALSE(tfr.cb.is_null()); | 142 ASSERT_FALSE(tfr.cb.is_null()); |
| 143 ASSERT_FALSE(tfr.cb_already_run); | 143 ASSERT_FALSE(tfr.cb_already_run); |
| 144 ResetAndReturn(&tfr.cb).Run(); | 144 ResetAndReturn(&tfr.cb).Run(); |
| 145 ASSERT_TRUE(tfr.cb.is_null()); | 145 ASSERT_TRUE(tfr.cb.is_null()); |
| 146 ASSERT_TRUE(tfr.cb_already_run); | 146 ASSERT_TRUE(tfr.cb_already_run); |
| 147 } | 147 } |
| 148 | 148 |
| 149 class CallbackOwner : public base::RefCounted<CallbackOwner> { | 149 class CallbackOwner : public base::RefCounted<CallbackOwner> { |
| 150 public: | 150 public: |
| 151 CallbackOwner(bool* deleted) { | 151 explicit CallbackOwner(bool* deleted) { |
| 152 callback_ = Bind(&CallbackOwner::Unused, this); | 152 callback_ = Bind(&CallbackOwner::Unused, this); |
| 153 deleted_ = deleted; | 153 deleted_ = deleted; |
| 154 } | 154 } |
| 155 void Reset() { | 155 void Reset() { |
| 156 callback_.Reset(); | 156 callback_.Reset(); |
| 157 // We are deleted here if no-one else had a ref to us. | 157 // We are deleted here if no-one else had a ref to us. |
| 158 } | 158 } |
| 159 | 159 |
| 160 private: | 160 private: |
| 161 friend class base::RefCounted<CallbackOwner>; | 161 friend class base::RefCounted<CallbackOwner>; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 | 172 |
| 173 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) { | 173 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) { |
| 174 bool deleted = false; | 174 bool deleted = false; |
| 175 CallbackOwner* owner = new CallbackOwner(&deleted); | 175 CallbackOwner* owner = new CallbackOwner(&deleted); |
| 176 owner->Reset(); | 176 owner->Reset(); |
| 177 ASSERT_TRUE(deleted); | 177 ASSERT_TRUE(deleted); |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace | 180 } // namespace |
| 181 } // namespace base | 181 } // namespace base |
| OLD | NEW |