Chromium Code Reviews| 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/common/message_pump_mojo.h" | 5 #include "mojo/common/message_pump_mojo.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 uint32_t num_bytes = 0; | 147 uint32_t num_bytes = 0; |
| 148 ReadMessageRaw(run_state.read_handle.get(), NULL, &num_bytes, NULL, NULL, | 148 ReadMessageRaw(run_state.read_handle.get(), NULL, &num_bytes, NULL, NULL, |
| 149 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); | 149 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); |
| 150 } else if (result > 0) { | 150 } else if (result > 0) { |
| 151 const size_t index = static_cast<size_t>(result); | 151 const size_t index = static_cast<size_t>(result); |
| 152 DCHECK(handlers_.find(wait_state.handles[index]) != handlers_.end()); | 152 DCHECK(handlers_.find(wait_state.handles[index]) != handlers_.end()); |
| 153 handlers_[wait_state.handles[index]].handler->OnHandleReady( | 153 handlers_[wait_state.handles[index]].handler->OnHandleReady( |
| 154 wait_state.handles[index]); | 154 wait_state.handles[index]); |
| 155 } else { | 155 } else { |
| 156 switch (result) { | 156 switch (result) { |
| 157 case MOJO_RESULT_CANCELLED: | |
| 158 case MOJO_RESULT_FAILED_PRECONDITION: | |
| 157 case MOJO_RESULT_INVALID_ARGUMENT: | 159 case MOJO_RESULT_INVALID_ARGUMENT: |
| 158 case MOJO_RESULT_FAILED_PRECONDITION: | |
| 159 RemoveFirstInvalidHandle(wait_state); | 160 RemoveFirstInvalidHandle(wait_state); |
| 160 break; | 161 break; |
| 161 case MOJO_RESULT_DEADLINE_EXCEEDED: | 162 case MOJO_RESULT_DEADLINE_EXCEEDED: |
| 162 break; | 163 break; |
| 163 default: | 164 default: |
| 164 NOTREACHED(); | 165 NOTREACHED(); |
|
darin (slow to review)
2014/05/09 22:00:15
should this CHECK(false) so we learn if this ever
sky
2014/05/09 22:04:51
Done.
| |
| 165 } | 166 } |
| 166 } | 167 } |
| 167 | 168 |
| 168 // Notify and remove any handlers whose time has expired. Make a copy in case | 169 // Notify and remove any handlers whose time has expired. Make a copy in case |
| 169 // someone tries to add/remove new handlers from notification. | 170 // someone tries to add/remove new handlers from notification. |
| 170 const HandleToHandler cloned_handlers(handlers_); | 171 const HandleToHandler cloned_handlers(handlers_); |
| 171 const base::TimeTicks now(internal::NowTicks()); | 172 const base::TimeTicks now(internal::NowTicks()); |
| 172 for (HandleToHandler::const_iterator i = cloned_handlers.begin(); | 173 for (HandleToHandler::const_iterator i = cloned_handlers.begin(); |
| 173 i != cloned_handlers.end(); ++i) { | 174 i != cloned_handlers.end(); ++i) { |
| 174 // Since we're iterating over a clone of the handlers, verify the handler is | 175 // Since we're iterating over a clone of the handlers, verify the handler is |
| 175 // still valid before notifying. | 176 // still valid before notifying. |
| 176 if (!i->second.deadline.is_null() && i->second.deadline < now && | 177 if (!i->second.deadline.is_null() && i->second.deadline < now && |
| 177 handlers_.find(i->first) != handlers_.end() && | 178 handlers_.find(i->first) != handlers_.end() && |
| 178 handlers_[i->first].id == i->second.id) { | 179 handlers_[i->first].id == i->second.id) { |
| 179 i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED); | 180 i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED); |
| 180 } | 181 } |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 | 184 |
| 184 void MessagePumpMojo::RemoveFirstInvalidHandle(const WaitState& wait_state) { | 185 void MessagePumpMojo::RemoveFirstInvalidHandle(const WaitState& wait_state) { |
| 185 // TODO(sky): deal with control pipe going bad. | 186 // TODO(sky): deal with control pipe going bad. |
| 186 for (size_t i = 1; i < wait_state.handles.size(); ++i) { | 187 for (size_t i = 1; i < wait_state.handles.size(); ++i) { |
| 187 const MojoResult result = | 188 const MojoResult result = |
| 188 Wait(wait_state.handles[i], wait_state.wait_flags[i], 0); | 189 Wait(wait_state.handles[i], wait_state.wait_flags[i], 0); |
| 189 if (result == MOJO_RESULT_INVALID_ARGUMENT || | 190 if (result == MOJO_RESULT_INVALID_ARGUMENT || |
| 190 result == MOJO_RESULT_FAILED_PRECONDITION) { | 191 result == MOJO_RESULT_FAILED_PRECONDITION || |
| 192 result == MOJO_RESULT_CANCELLED) { | |
| 191 // Remove the handle first, this way if OnHandleError() tries to remove | 193 // Remove the handle first, this way if OnHandleError() tries to remove |
| 192 // the handle our iterator isn't invalidated. | 194 // the handle our iterator isn't invalidated. |
| 193 DCHECK(handlers_.find(wait_state.handles[i]) != handlers_.end()); | 195 DCHECK(handlers_.find(wait_state.handles[i]) != handlers_.end()); |
| 194 MessagePumpMojoHandler* handler = | 196 MessagePumpMojoHandler* handler = |
| 195 handlers_[wait_state.handles[i]].handler; | 197 handlers_[wait_state.handles[i]].handler; |
| 196 handlers_.erase(wait_state.handles[i]); | 198 handlers_.erase(wait_state.handles[i]); |
| 197 handler->OnHandleError(wait_state.handles[i], result); | 199 handler->OnHandleError(wait_state.handles[i], result); |
| 198 return; | 200 return; |
| 199 } | 201 } |
| 200 } | 202 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 229 min_time = i->second.deadline; | 231 min_time = i->second.deadline; |
| 230 } | 232 } |
| 231 return min_time.is_null() ? MOJO_DEADLINE_INDEFINITE : | 233 return min_time.is_null() ? MOJO_DEADLINE_INDEFINITE : |
| 232 std::max(static_cast<MojoDeadline>(0), | 234 std::max(static_cast<MojoDeadline>(0), |
| 233 static_cast<MojoDeadline>( | 235 static_cast<MojoDeadline>( |
| 234 (min_time - internal::NowTicks()).InMicroseconds())); | 236 (min_time - internal::NowTicks()).InMicroseconds())); |
| 235 } | 237 } |
| 236 | 238 |
| 237 } // namespace common | 239 } // namespace common |
| 238 } // namespace mojo | 240 } // namespace mojo |
| OLD | NEW |