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/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 TargetWithFactory() : factory(this) {} | 55 TargetWithFactory() : factory(this) {} |
56 WeakPtrFactory<Target> factory; | 56 WeakPtrFactory<Target> factory; |
57 }; | 57 }; |
58 | 58 |
59 // Helper class to create and destroy weak pointer copies | 59 // Helper class to create and destroy weak pointer copies |
60 // and delete objects on a background thread. | 60 // and delete objects on a background thread. |
61 class BackgroundThread : public Thread { | 61 class BackgroundThread : public Thread { |
62 public: | 62 public: |
63 BackgroundThread() : Thread("owner_thread") {} | 63 BackgroundThread() : Thread("owner_thread") {} |
64 | 64 |
65 virtual ~BackgroundThread() { | 65 ~BackgroundThread() override { Stop(); } |
66 Stop(); | |
67 } | |
68 | 66 |
69 void CreateArrowFromTarget(Arrow** arrow, Target* target) { | 67 void CreateArrowFromTarget(Arrow** arrow, Target* target) { |
70 WaitableEvent completion(true, false); | 68 WaitableEvent completion(true, false); |
71 message_loop()->PostTask( | 69 message_loop()->PostTask( |
72 FROM_HERE, | 70 FROM_HERE, |
73 base::Bind(&BackgroundThread::DoCreateArrowFromTarget, | 71 base::Bind(&BackgroundThread::DoCreateArrowFromTarget, |
74 arrow, target, &completion)); | 72 arrow, target, &completion)); |
75 completion.Wait(); | 73 completion.Wait(); |
76 } | 74 } |
77 | 75 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 background.Start(); | 607 background.Start(); |
610 background.DeleteTarget(target.release()); | 608 background.DeleteTarget(target.release()); |
611 | 609 |
612 // Main thread attempts to dereference the target, violating thread binding. | 610 // Main thread attempts to dereference the target, violating thread binding. |
613 ASSERT_DEATH(arrow.target.get(), ""); | 611 ASSERT_DEATH(arrow.target.get(), ""); |
614 } | 612 } |
615 | 613 |
616 #endif | 614 #endif |
617 | 615 |
618 } // namespace base | 616 } // namespace base |
OLD | NEW |