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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 #endif // defined(OS_WIN) | 390 #endif // defined(OS_WIN) |
391 | 391 |
392 // This is used to inject a test point for recording the destructor calls for | 392 // This is used to inject a test point for recording the destructor calls for |
393 // Closure objects send to MessageLoop::PostTask(). It is awkward usage since we | 393 // Closure objects send to MessageLoop::PostTask(). It is awkward usage since we |
394 // are trying to hook the actual destruction, which is not a common operation. | 394 // are trying to hook the actual destruction, which is not a common operation. |
395 class RecordDeletionProbe : public base::RefCounted<RecordDeletionProbe> { | 395 class RecordDeletionProbe : public base::RefCounted<RecordDeletionProbe> { |
396 public: | 396 public: |
397 RecordDeletionProbe(RecordDeletionProbe* post_on_delete, bool* was_deleted) | 397 RecordDeletionProbe(RecordDeletionProbe* post_on_delete, bool* was_deleted) |
398 : post_on_delete_(post_on_delete), was_deleted_(was_deleted) { | 398 : post_on_delete_(post_on_delete), was_deleted_(was_deleted) { |
399 } | 399 } |
| 400 void Run() {} |
| 401 |
| 402 private: |
| 403 friend class base::RefCounted<RecordDeletionProbe>; |
| 404 |
400 ~RecordDeletionProbe() { | 405 ~RecordDeletionProbe() { |
401 *was_deleted_ = true; | 406 *was_deleted_ = true; |
402 if (post_on_delete_) | 407 if (post_on_delete_) |
403 MessageLoop::current()->PostTask( | 408 MessageLoop::current()->PostTask( |
404 FROM_HERE, | 409 FROM_HERE, |
405 base::Bind(&RecordDeletionProbe::Run, post_on_delete_.get())); | 410 base::Bind(&RecordDeletionProbe::Run, post_on_delete_.get())); |
406 } | 411 } |
407 void Run() {} | 412 |
408 private: | |
409 scoped_refptr<RecordDeletionProbe> post_on_delete_; | 413 scoped_refptr<RecordDeletionProbe> post_on_delete_; |
410 bool* was_deleted_; | 414 bool* was_deleted_; |
411 }; | 415 }; |
412 | 416 |
413 void RunTest_EnsureDeletion(MessageLoop::Type message_loop_type) { | 417 void RunTest_EnsureDeletion(MessageLoop::Type message_loop_type) { |
414 bool a_was_deleted = false; | 418 bool a_was_deleted = false; |
415 bool b_was_deleted = false; | 419 bool b_was_deleted = false; |
416 { | 420 { |
417 MessageLoop loop(message_loop_type); | 421 MessageLoop loop(message_loop_type); |
418 loop.PostTask( | 422 loop.PostTask( |
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 // send to MessageLoop::PostTask(). It is awkward usage since we are trying to | 1621 // send to MessageLoop::PostTask(). It is awkward usage since we are trying to |
1618 // hook the actual destruction, which is not a common operation. | 1622 // hook the actual destruction, which is not a common operation. |
1619 class DestructionObserverProbe : | 1623 class DestructionObserverProbe : |
1620 public base::RefCounted<DestructionObserverProbe> { | 1624 public base::RefCounted<DestructionObserverProbe> { |
1621 public: | 1625 public: |
1622 DestructionObserverProbe(bool* task_destroyed, | 1626 DestructionObserverProbe(bool* task_destroyed, |
1623 bool* destruction_observer_called) | 1627 bool* destruction_observer_called) |
1624 : task_destroyed_(task_destroyed), | 1628 : task_destroyed_(task_destroyed), |
1625 destruction_observer_called_(destruction_observer_called) { | 1629 destruction_observer_called_(destruction_observer_called) { |
1626 } | 1630 } |
1627 virtual ~DestructionObserverProbe() { | |
1628 EXPECT_FALSE(*destruction_observer_called_); | |
1629 *task_destroyed_ = true; | |
1630 } | |
1631 virtual void Run() { | 1631 virtual void Run() { |
1632 // This task should never run. | 1632 // This task should never run. |
1633 ADD_FAILURE(); | 1633 ADD_FAILURE(); |
1634 } | 1634 } |
1635 private: | 1635 private: |
| 1636 friend class base::RefCounted<DestructionObserverProbe>; |
| 1637 |
| 1638 virtual ~DestructionObserverProbe() { |
| 1639 EXPECT_FALSE(*destruction_observer_called_); |
| 1640 *task_destroyed_ = true; |
| 1641 } |
| 1642 |
1636 bool* task_destroyed_; | 1643 bool* task_destroyed_; |
1637 bool* destruction_observer_called_; | 1644 bool* destruction_observer_called_; |
1638 }; | 1645 }; |
1639 | 1646 |
1640 class MLDestructionObserver : public MessageLoop::DestructionObserver { | 1647 class MLDestructionObserver : public MessageLoop::DestructionObserver { |
1641 public: | 1648 public: |
1642 MLDestructionObserver(bool* task_destroyed, bool* destruction_observer_called) | 1649 MLDestructionObserver(bool* task_destroyed, bool* destruction_observer_called) |
1643 : task_destroyed_(task_destroyed), | 1650 : task_destroyed_(task_destroyed), |
1644 destruction_observer_called_(destruction_observer_called), | 1651 destruction_observer_called_(destruction_observer_called), |
1645 task_destroyed_before_message_loop_(false) { | 1652 task_destroyed_before_message_loop_(false) { |
(...skipping 29 matching lines...) Expand all Loading... |
1675 base::Bind(&DestructionObserverProbe::Run, | 1682 base::Bind(&DestructionObserverProbe::Run, |
1676 new DestructionObserverProbe(&task_destroyed, | 1683 new DestructionObserverProbe(&task_destroyed, |
1677 &destruction_observer_called)), | 1684 &destruction_observer_called)), |
1678 kDelay); | 1685 kDelay); |
1679 delete loop; | 1686 delete loop; |
1680 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); | 1687 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); |
1681 // The task should have been destroyed when we deleted the loop. | 1688 // The task should have been destroyed when we deleted the loop. |
1682 EXPECT_TRUE(task_destroyed); | 1689 EXPECT_TRUE(task_destroyed); |
1683 EXPECT_TRUE(destruction_observer_called); | 1690 EXPECT_TRUE(destruction_observer_called); |
1684 } | 1691 } |
OLD | NEW |