Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: mojo/common/message_pump_mojo.cc

Issue 409943003: Makes HandleWatcher block until no longer waiting on pipe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more java fixes Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); 150 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD);
151 } else if (result > 0) { 151 } else if (result > 0) {
152 const size_t index = static_cast<size_t>(result); 152 const size_t index = static_cast<size_t>(result);
153 DCHECK(handlers_.find(wait_state.handles[index]) != handlers_.end()); 153 DCHECK(handlers_.find(wait_state.handles[index]) != handlers_.end());
154 handlers_[wait_state.handles[index]].handler->OnHandleReady( 154 handlers_[wait_state.handles[index]].handler->OnHandleReady(
155 wait_state.handles[index]); 155 wait_state.handles[index]);
156 } else { 156 } else {
157 switch (result) { 157 switch (result) {
158 case MOJO_RESULT_CANCELLED: 158 case MOJO_RESULT_CANCELLED:
159 case MOJO_RESULT_FAILED_PRECONDITION: 159 case MOJO_RESULT_FAILED_PRECONDITION:
160 case MOJO_RESULT_INVALID_ARGUMENT:
161 RemoveFirstInvalidHandle(wait_state); 160 RemoveFirstInvalidHandle(wait_state);
162 break; 161 break;
163 case MOJO_RESULT_DEADLINE_EXCEEDED: 162 case MOJO_RESULT_DEADLINE_EXCEEDED:
164 break; 163 break;
165 default: 164 default:
166 base::debug::Alias(&result); 165 base::debug::Alias(&result);
167 // Unexpected result is likely fatal, crash so we can determine cause. 166 // Unexpected result is likely fatal, crash so we can determine cause.
168 CHECK(false); 167 CHECK(false);
169 } 168 }
170 } 169 }
(...skipping 12 matching lines...) Expand all
183 i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED); 182 i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED);
184 } 183 }
185 } 184 }
186 } 185 }
187 186
188 void MessagePumpMojo::RemoveFirstInvalidHandle(const WaitState& wait_state) { 187 void MessagePumpMojo::RemoveFirstInvalidHandle(const WaitState& wait_state) {
189 // TODO(sky): deal with control pipe going bad. 188 // TODO(sky): deal with control pipe going bad.
190 for (size_t i = 1; i < wait_state.handles.size(); ++i) { 189 for (size_t i = 1; i < wait_state.handles.size(); ++i) {
191 const MojoResult result = 190 const MojoResult result =
192 Wait(wait_state.handles[i], wait_state.wait_signals[i], 0); 191 Wait(wait_state.handles[i], wait_state.wait_signals[i], 0);
193 if (result == MOJO_RESULT_INVALID_ARGUMENT || 192 if (result == MOJO_RESULT_INVALID_ARGUMENT) {
194 result == MOJO_RESULT_FAILED_PRECONDITION || 193 // We should never have an invalid argument. If we do it indicates
195 result == MOJO_RESULT_CANCELLED) { 194 // RemoveHandler() was not invoked and is likely to cause problems else
195 // where in the stack if we ignore it.
196 CHECK(false);
197 } else if (result == MOJO_RESULT_FAILED_PRECONDITION ||
198 result == MOJO_RESULT_CANCELLED) {
196 // Remove the handle first, this way if OnHandleError() tries to remove 199 // Remove the handle first, this way if OnHandleError() tries to remove
197 // the handle our iterator isn't invalidated. 200 // the handle our iterator isn't invalidated.
198 DCHECK(handlers_.find(wait_state.handles[i]) != handlers_.end()); 201 DCHECK(handlers_.find(wait_state.handles[i]) != handlers_.end());
199 MessagePumpMojoHandler* handler = 202 MessagePumpMojoHandler* handler =
200 handlers_[wait_state.handles[i]].handler; 203 handlers_[wait_state.handles[i]].handler;
201 handlers_.erase(wait_state.handles[i]); 204 handlers_.erase(wait_state.handles[i]);
202 handler->OnHandleError(wait_state.handles[i], result); 205 handler->OnHandleError(wait_state.handles[i], result);
203 return; 206 return;
204 } 207 }
205 } 208 }
(...skipping 28 matching lines...) Expand all
234 min_time = i->second.deadline; 237 min_time = i->second.deadline;
235 } 238 }
236 return min_time.is_null() ? MOJO_DEADLINE_INDEFINITE : 239 return min_time.is_null() ? MOJO_DEADLINE_INDEFINITE :
237 std::max(static_cast<MojoDeadline>(0), 240 std::max(static_cast<MojoDeadline>(0),
238 static_cast<MojoDeadline>( 241 static_cast<MojoDeadline>(
239 (min_time - internal::NowTicks()).InMicroseconds())); 242 (min_time - internal::NowTicks()).InMicroseconds()));
240 } 243 }
241 244
242 } // namespace common 245 } // namespace common
243 } // namespace mojo 246 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698