OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef MOJO_SERVICES_MEDIA_FACTORY_EVENT_H_ | 5 #ifndef MOJO_SERVICES_MEDIA_FACTORY_EVENT_H_ |
6 #define MOJO_SERVICES_MEDIA_FACTORY_EVENT_H_ | 6 #define MOJO_SERVICES_MEDIA_FACTORY_EVENT_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return *this; | 114 return *this; |
115 } | 115 } |
116 | 116 |
117 // Makes this Event null. | 117 // Makes this Event null. |
118 const Event& operator=(std::nullptr_t) { | 118 const Event& operator=(std::nullptr_t) { |
119 impl_.reset(); | 119 impl_.reset(); |
120 return *this; | 120 return *this; |
121 } | 121 } |
122 | 122 |
123 // Determines whether this Event is non-null. | 123 // Determines whether this Event is non-null. |
124 explicit operator bool() const { | 124 explicit operator bool() const { return static_cast<bool>(impl_); } |
125 return static_cast<bool>(impl_); | |
126 } | |
127 | 125 |
128 // Executes the consequence when this Event occurs. If this Event hasn't | 126 // Executes the consequence when this Event occurs. If this Event hasn't |
129 // occurred or been cancelled when this method is called, a copy of the | 127 // occurred or been cancelled when this method is called, a copy of the |
130 // consequence is held until this Event occurs or is cancelled. If this Event | 128 // consequence is held until this Event occurs or is cancelled. If this Event |
131 // has occurred when this method is called, the consequence is executed | 129 // has occurred when this method is called, the consequence is executed |
132 // immediately and no copy of the consequence is held. If this Event is | 130 // immediately and no copy of the consequence is held. If this Event is |
133 // cancelled when this method is called, the method does nothing. | 131 // cancelled when this method is called, the method does nothing. |
134 // Returns this. | 132 // Returns this. |
135 const Event& When(const std::function<void()>& consequence) const; | 133 const Event& When(const std::function<void()>& consequence) const; |
136 | 134 |
137 // Determines if this Event has occurred due to a past call to Occur or Run. | 135 // Determines if this Event has occurred due to a past call to Occur or Run. |
138 bool occurred() const; | 136 bool occurred() const; |
139 | 137 |
140 // Determines if this Event has been cancelled. | 138 // Determines if this Event has been cancelled. |
141 bool cancelled() const; | 139 bool cancelled() const; |
142 | 140 |
143 // If this Event hasn't yet occurred or been cancelled, this method makes | 141 // If this Event hasn't yet occurred or been cancelled, this method makes |
144 // this Event occur, executing and deleting all its consequences. Otherwise, | 142 // this Event occur, executing and deleting all its consequences. Otherwise, |
145 // does nothing. | 143 // does nothing. |
146 void Occur() const; | 144 void Occur() const; |
147 | 145 |
148 // If this Event hasn't yet occurred or been cancelled, this method cancels | 146 // If this Event hasn't yet occurred or been cancelled, this method cancels |
149 // this Event and deletes all its consequences. Otherwise, does nothing. | 147 // this Event and deletes all its consequences. Otherwise, does nothing. |
150 void Cancel() const; | 148 void Cancel() const; |
151 | 149 |
152 // Calls Occur. This method makes an Event convertible to | 150 // Calls Occur. This method makes an Event convertible to |
153 // mojo::Callback<void()>. | 151 // mojo::Callback<void()>. |
154 void Run() const { | 152 void Run() const { Occur(); } |
155 Occur(); | |
156 } | |
157 | 153 |
158 private: | 154 private: |
159 explicit Event(const std::shared_ptr<EventImpl>& impl); | 155 explicit Event(const std::shared_ptr<EventImpl>& impl); |
160 | 156 |
161 std::shared_ptr<EventImpl> impl_; | 157 std::shared_ptr<EventImpl> impl_; |
162 }; | 158 }; |
163 | 159 |
164 } // namespace media | 160 } // namespace media |
165 } // namespace mojo | 161 } // namespace mojo |
166 | 162 |
167 #endif // MOJO_SERVICES_MEDIA_FACTORY_EVENT_H_ | 163 #endif // MOJO_SERVICES_MEDIA_FACTORY_EVENT_H_ |
OLD | NEW |