| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 118 } |
| 119 | 119 |
| 120 void MessagePumpMojo::DoInternalWork(bool block) { | 120 void MessagePumpMojo::DoInternalWork(bool block) { |
| 121 const MojoDeadline deadline = block ? GetDeadlineForWait() : 0; | 121 const MojoDeadline deadline = block ? GetDeadlineForWait() : 0; |
| 122 const WaitState wait_state = GetWaitState(); | 122 const WaitState wait_state = GetWaitState(); |
| 123 const MojoResult result = | 123 const MojoResult result = |
| 124 WaitMany(wait_state.handles, wait_state.wait_flags, deadline); | 124 WaitMany(wait_state.handles, wait_state.wait_flags, deadline); |
| 125 if (result == 0) { | 125 if (result == 0) { |
| 126 // Control pipe was written to. | 126 // Control pipe was written to. |
| 127 uint32_t num_bytes = 0; | 127 uint32_t num_bytes = 0; |
| 128 ReadMessageRaw(run_state_->read_handle, NULL, &num_bytes, NULL, NULL, | 128 ReadMessageRaw(run_state_->read_handle.get(), NULL, &num_bytes, NULL, NULL, |
| 129 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); | 129 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); |
| 130 } else if (result > 0) { | 130 } else if (result > 0) { |
| 131 const size_t index = static_cast<size_t>(result); | 131 const size_t index = static_cast<size_t>(result); |
| 132 DCHECK(handlers_.find(wait_state.handles[index]) != handlers_.end()); | 132 DCHECK(handlers_.find(wait_state.handles[index]) != handlers_.end()); |
| 133 handlers_[wait_state.handles[index]].handler->OnHandleReady( | 133 handlers_[wait_state.handles[index]].handler->OnHandleReady( |
| 134 wait_state.handles[index]); | 134 wait_state.handles[index]); |
| 135 } else { | 135 } else { |
| 136 switch (result) { | 136 switch (result) { |
| 137 case MOJO_RESULT_INVALID_ARGUMENT: | 137 case MOJO_RESULT_INVALID_ARGUMENT: |
| 138 case MOJO_RESULT_FAILED_PRECONDITION: | 138 case MOJO_RESULT_FAILED_PRECONDITION: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 DCHECK_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); | 180 DCHECK_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | 184 |
| 185 void MessagePumpMojo::SignalControlPipe() { | 185 void MessagePumpMojo::SignalControlPipe() { |
| 186 if (!run_state_) | 186 if (!run_state_) |
| 187 return; | 187 return; |
| 188 | 188 |
| 189 // TODO(sky): deal with error? | 189 // TODO(sky): deal with error? |
| 190 WriteMessageRaw(run_state_->write_handle, NULL, 0, NULL, 0, | 190 WriteMessageRaw(run_state_->write_handle.get(), NULL, 0, NULL, 0, |
| 191 MOJO_WRITE_MESSAGE_FLAG_NONE); | 191 MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 192 } | 192 } |
| 193 | 193 |
| 194 MessagePumpMojo::WaitState MessagePumpMojo::GetWaitState() const { | 194 MessagePumpMojo::WaitState MessagePumpMojo::GetWaitState() const { |
| 195 WaitState wait_state; | 195 WaitState wait_state; |
| 196 wait_state.handles.push_back(run_state_->read_handle); | 196 wait_state.handles.push_back(run_state_->read_handle.get()); |
| 197 wait_state.wait_flags.push_back(MOJO_WAIT_FLAG_READABLE); | 197 wait_state.wait_flags.push_back(MOJO_WAIT_FLAG_READABLE); |
| 198 | 198 |
| 199 for (HandleToHandler::const_iterator i = handlers_.begin(); | 199 for (HandleToHandler::const_iterator i = handlers_.begin(); |
| 200 i != handlers_.end(); ++i) { | 200 i != handlers_.end(); ++i) { |
| 201 wait_state.handles.push_back(i->first); | 201 wait_state.handles.push_back(i->first); |
| 202 wait_state.wait_flags.push_back(i->second.wait_flags); | 202 wait_state.wait_flags.push_back(i->second.wait_flags); |
| 203 } | 203 } |
| 204 return wait_state; | 204 return wait_state; |
| 205 } | 205 } |
| 206 | 206 |
| 207 MojoDeadline MessagePumpMojo::GetDeadlineForWait() const { | 207 MojoDeadline MessagePumpMojo::GetDeadlineForWait() const { |
| 208 base::TimeTicks min_time = run_state_->delayed_work_time; | 208 base::TimeTicks min_time = run_state_->delayed_work_time; |
| 209 for (HandleToHandler::const_iterator i = handlers_.begin(); | 209 for (HandleToHandler::const_iterator i = handlers_.begin(); |
| 210 i != handlers_.end(); ++i) { | 210 i != handlers_.end(); ++i) { |
| 211 if (min_time.is_null() && i->second.deadline < min_time) | 211 if (min_time.is_null() && i->second.deadline < min_time) |
| 212 min_time = i->second.deadline; | 212 min_time = i->second.deadline; |
| 213 } | 213 } |
| 214 return min_time.is_null() ? MOJO_DEADLINE_INDEFINITE : | 214 return min_time.is_null() ? MOJO_DEADLINE_INDEFINITE : |
| 215 std::max(static_cast<MojoDeadline>(0), | 215 std::max(static_cast<MojoDeadline>(0), |
| 216 static_cast<MojoDeadline>( | 216 static_cast<MojoDeadline>( |
| 217 (min_time - base::TimeTicks::Now()).InMicroseconds())); | 217 (min_time - base::TimeTicks::Now()).InMicroseconds())); |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace common | 220 } // namespace common |
| 221 } // namespace mojo | 221 } // namespace mojo |
| OLD | NEW |