OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/base/delayed_unique_notifier.h" | 5 #include "cc/base/delayed_unique_notifier.h" |
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/location.h" | 9 #include "base/location.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 base::Bind(&DelayedUniqueNotifier::NotifyIfTime, | 36 base::Bind(&DelayedUniqueNotifier::NotifyIfTime, |
37 weak_ptr_factory_.GetWeakPtr()), | 37 weak_ptr_factory_.GetWeakPtr()), |
38 delay_); | 38 delay_); |
39 notification_pending_ = true; | 39 notification_pending_ = true; |
40 } | 40 } |
41 | 41 |
42 void DelayedUniqueNotifier::Cancel() { | 42 void DelayedUniqueNotifier::Cancel() { |
43 next_notification_time_ = base::TimeTicks(); | 43 next_notification_time_ = base::TimeTicks(); |
44 } | 44 } |
45 | 45 |
| 46 void DelayedUniqueNotifier::Shutdown() { |
| 47 // This function must destroy any weak ptrs since after being cancelled, this |
| 48 // class may be destroyed on another thread during compositor shutdown. |
| 49 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 50 // Deliberately leaves notification_pending_ = true forever so new tasks with |
| 51 // weak ptrs can not be created. |
| 52 notification_pending_ = true; |
| 53 } |
| 54 |
46 bool DelayedUniqueNotifier::HasPendingNotification() const { | 55 bool DelayedUniqueNotifier::HasPendingNotification() const { |
47 return notification_pending_ && !next_notification_time_.is_null(); | 56 return notification_pending_ && !next_notification_time_.is_null(); |
48 } | 57 } |
49 | 58 |
50 base::TimeTicks DelayedUniqueNotifier::Now() const { | 59 base::TimeTicks DelayedUniqueNotifier::Now() const { |
51 return base::TimeTicks::Now(); | 60 return base::TimeTicks::Now(); |
52 } | 61 } |
53 | 62 |
54 void DelayedUniqueNotifier::NotifyIfTime() { | 63 void DelayedUniqueNotifier::NotifyIfTime() { |
55 // If next notifiaction time is not valid, then this schedule was canceled. | 64 // If next notifiaction time is not valid, then this schedule was canceled. |
(...skipping 13 matching lines...) Expand all Loading... |
69 next_notification_time_ - now); | 78 next_notification_time_ - now); |
70 return; | 79 return; |
71 } | 80 } |
72 | 81 |
73 // Note the order here is important since closure might schedule another run. | 82 // Note the order here is important since closure might schedule another run. |
74 notification_pending_ = false; | 83 notification_pending_ = false; |
75 closure_.Run(); | 84 closure_.Run(); |
76 } | 85 } |
77 | 86 |
78 } // namespace cc | 87 } // namespace cc |
OLD | NEW |