Chromium Code Reviews| Index: base/memory/scoped_vector_unittest.cc |
| diff --git a/base/memory/scoped_vector_unittest.cc b/base/memory/scoped_vector_unittest.cc |
| index 220cfb04687c74fbf13f950bd52b757cf340ca44..4dee9c9004e93e3c0a0ddfdaa58ec6d9079439fa 100644 |
| --- a/base/memory/scoped_vector_unittest.cc |
| +++ b/base/memory/scoped_vector_unittest.cc |
| @@ -24,7 +24,8 @@ class LifeCycleObject { |
| }; |
| ~LifeCycleObject() { |
| - observer_->OnLifeCycleDestroy(this); |
| + if (observer_) |
| + observer_->OnLifeCycleDestroy(this); |
| } |
| private: |
| @@ -35,6 +36,10 @@ class LifeCycleObject { |
| observer_->OnLifeCycleConstruct(this); |
| } |
| + void DisconnectObserver() { |
| + observer_ = nullptr; |
| + } |
| + |
| Observer* observer_; |
| DISALLOW_COPY_AND_ASSIGN(LifeCycleObject); |
| @@ -62,7 +67,13 @@ enum LifeCycleState { |
| class LifeCycleWatcher : public LifeCycleObject::Observer { |
| public: |
| LifeCycleWatcher() : life_cycle_state_(LC_INITIAL) {} |
| - ~LifeCycleWatcher() override {} |
| + ~LifeCycleWatcher() override { |
| + // Stop watching the watched object. Without this, the object's destructor |
|
danakj
2015/09/24 17:43:51
Alternatively, you could just keep the watcher ali
Anand Mistry (off Chromium)
2015/09/24 21:56:27
The two tests that fail are WeakClear and InsertRa
|
| + // will call into OnLifeCycleDestroy when destructed, which happens after |
| + // this destructor has finished running. |
| + if (constructed_life_cycle_object_) |
| + constructed_life_cycle_object_->DisconnectObserver(); |
| + } |
| // Assert INITIAL -> CONSTRUCTED and no LifeCycleObject associated with this |
| // LifeCycleWatcher. |