OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/public/utility/run_loop.h" | 5 #include "mojo/public/utility/run_loop.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 GetTimeTicksNow() + static_cast<MojoTimeTicks>(deadline); | 85 GetTimeTicksNow() + static_cast<MojoTimeTicks>(deadline); |
86 handler_data.id = next_handler_id_++; | 86 handler_data.id = next_handler_id_++; |
87 handler_data_[handle] = handler_data; | 87 handler_data_[handle] = handler_data; |
88 } | 88 } |
89 | 89 |
90 void RunLoop::RemoveHandler(const Handle& handle) { | 90 void RunLoop::RemoveHandler(const Handle& handle) { |
91 assert(current() == this); | 91 assert(current() == this); |
92 handler_data_.erase(handle); | 92 handler_data_.erase(handle); |
93 } | 93 } |
94 | 94 |
| 95 bool RunLoop::HasHandler(const Handle& handle) const { |
| 96 return handler_data_.find(handle) != handler_data_.end(); |
| 97 } |
| 98 |
95 void RunLoop::Run() { | 99 void RunLoop::Run() { |
96 assert(current() == this); | 100 assert(current() == this); |
97 // We don't currently support nesting. | 101 // We don't currently support nesting. |
98 assert(!run_state_); | 102 assert(!run_state_); |
99 RunState* old_state = run_state_; | 103 RunState* old_state = run_state_; |
100 RunState run_state; | 104 RunState run_state; |
101 run_state_ = &run_state; | 105 run_state_ = &run_state; |
102 while (!run_state.should_quit) | 106 while (!run_state.should_quit) |
103 Wait(); | 107 Wait(); |
104 run_state_ = old_state; | 108 run_state_ = old_state; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 const HandleToHandlerData cloned_handlers(handler_data_); | 151 const HandleToHandlerData cloned_handlers(handler_data_); |
148 const MojoTimeTicks now(GetTimeTicksNow()); | 152 const MojoTimeTicks now(GetTimeTicksNow()); |
149 for (HandleToHandlerData::const_iterator i = cloned_handlers.begin(); | 153 for (HandleToHandlerData::const_iterator i = cloned_handlers.begin(); |
150 i != cloned_handlers.end(); ++i) { | 154 i != cloned_handlers.end(); ++i) { |
151 // Since we're iterating over a clone of the handlers, verify the handler is | 155 // Since we're iterating over a clone of the handlers, verify the handler is |
152 // still valid before notifying. | 156 // still valid before notifying. |
153 if (i->second.deadline != kInvalidTimeTicks && | 157 if (i->second.deadline != kInvalidTimeTicks && |
154 i->second.deadline < now && | 158 i->second.deadline < now && |
155 handler_data_.find(i->first) != handler_data_.end() && | 159 handler_data_.find(i->first) != handler_data_.end() && |
156 handler_data_[i->first].id == i->second.id) { | 160 handler_data_[i->first].id == i->second.id) { |
| 161 handler_data_.erase(i->first); |
157 i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED); | 162 i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED); |
158 } | 163 } |
159 } | 164 } |
160 } | 165 } |
161 | 166 |
162 void RunLoop::RemoveFirstInvalidHandle(const WaitState& wait_state) { | 167 void RunLoop::RemoveFirstInvalidHandle(const WaitState& wait_state) { |
163 for (size_t i = 0; i < wait_state.handles.size(); ++i) { | 168 for (size_t i = 0; i < wait_state.handles.size(); ++i) { |
164 const MojoResult result = | 169 const MojoResult result = |
165 mojo::Wait(wait_state.handles[i], wait_state.wait_flags[i], | 170 mojo::Wait(wait_state.handles[i], wait_state.wait_flags[i], |
166 static_cast<MojoDeadline>(0)); | 171 static_cast<MojoDeadline>(0)); |
(...skipping 30 matching lines...) Expand all Loading... |
197 if (min_time < now) | 202 if (min_time < now) |
198 wait_state.deadline = static_cast<MojoDeadline>(0); | 203 wait_state.deadline = static_cast<MojoDeadline>(0); |
199 else | 204 else |
200 wait_state.deadline = static_cast<MojoDeadline>(min_time - now); | 205 wait_state.deadline = static_cast<MojoDeadline>(min_time - now); |
201 } | 206 } |
202 return wait_state; | 207 return wait_state; |
203 } | 208 } |
204 | 209 |
205 } // namespace utility | 210 } // namespace utility |
206 } // namespace mojo | 211 } // namespace mojo |
OLD | NEW |