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

Unified Diff: mojo/common/message_pump_mojo.cc

Issue 461133002: Revert of Adds some CHECKs to MessagePumpMojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/common/message_pump_mojo.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/message_pump_mojo.cc
diff --git a/mojo/common/message_pump_mojo.cc b/mojo/common/message_pump_mojo.cc
index d4b4949ae59de67c1632a6063d1b588acd0f208e..c7903f2831be0bf5666ee3e7c1488b23ab2716b9 100644
--- a/mojo/common/message_pump_mojo.cc
+++ b/mojo/common/message_pump_mojo.cc
@@ -15,19 +15,6 @@
namespace mojo {
namespace common {
-namespace {
-
-MojoDeadline TimeTicksToMojoDeadline(base::TimeTicks time_ticks,
- base::TimeTicks now) {
- // The is_null() check matches that of HandleWatcher.
- if (time_ticks.is_null())
- return MOJO_DEADLINE_INDEFINITE;
- const int64_t delta = (time_ticks - now).InMicroseconds();
- return delta < 0 ? static_cast<MojoDeadline>(0) :
- static_cast<MojoDeadline>(delta);
-}
-
-} // namespace
// State needed for one iteration of WaitMany. The first handle and flags
// corresponds to that of the control pipe.
@@ -65,10 +52,10 @@
const Handle& handle,
MojoHandleSignals wait_signals,
base::TimeTicks deadline) {
- CHECK(handler);
+ DCHECK(handler);
DCHECK(handle.is_valid());
// Assume it's an error if someone tries to reregister an existing handle.
- CHECK_EQ(0u, handlers_.count(handle));
+ DCHECK_EQ(0u, handlers_.count(handle));
Handler handler_data;
handler_data.handler = handler;
handler_data.wait_signals = wait_signals;
@@ -199,7 +186,7 @@
void MessagePumpMojo::RemoveFirstInvalidHandle(const WaitState& wait_state) {
// TODO(sky): deal with control pipe going bad.
- for (size_t i = 0; i < wait_state.handles.size(); ++i) {
+ for (size_t i = 1; i < wait_state.handles.size(); ++i) {
const MojoResult result =
Wait(wait_state.handles[i], wait_state.wait_signals[i], 0);
if (result == MOJO_RESULT_INVALID_ARGUMENT) {
@@ -209,11 +196,9 @@
CHECK(false);
} else if (result == MOJO_RESULT_FAILED_PRECONDITION ||
result == MOJO_RESULT_CANCELLED) {
- CHECK_NE(i, 0u); // Indicates the control pipe went bad.
-
// Remove the handle first, this way if OnHandleError() tries to remove
// the handle our iterator isn't invalidated.
- CHECK(handlers_.find(wait_state.handles[i]) != handlers_.end());
+ DCHECK(handlers_.find(wait_state.handles[i]) != handlers_.end());
MessagePumpMojoHandler* handler =
handlers_[wait_state.handles[i]].handler;
handlers_.erase(wait_state.handles[i]);
@@ -224,12 +209,9 @@
}
void MessagePumpMojo::SignalControlPipe(const RunState& run_state) {
- const MojoResult result =
- WriteMessageRaw(run_state.write_handle.get(), NULL, 0, NULL, 0,
- MOJO_WRITE_MESSAGE_FLAG_NONE);
- // If we can't write we likely won't wake up the thread and there is a strong
- // chance we'll deadlock.
- CHECK_EQ(MOJO_RESULT_OK, result);
+ // TODO(sky): deal with error?
+ WriteMessageRaw(run_state.write_handle.get(), NULL, 0, NULL, 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE);
}
MessagePumpMojo::WaitState MessagePumpMojo::GetWaitState(
@@ -248,16 +230,16 @@
MojoDeadline MessagePumpMojo::GetDeadlineForWait(
const RunState& run_state) const {
- const base::TimeTicks now(internal::NowTicks());
- MojoDeadline deadline = static_cast<MojoDeadline>(0);
- if (!run_state.delayed_work_time.is_null())
- deadline = TimeTicksToMojoDeadline(run_state.delayed_work_time, now);
+ base::TimeTicks min_time = run_state.delayed_work_time;
for (HandleToHandler::const_iterator i = handlers_.begin();
i != handlers_.end(); ++i) {
- deadline = std::min(
- TimeTicksToMojoDeadline(i->second.deadline, now), deadline);
- }
- return deadline;
+ if (min_time.is_null() && i->second.deadline < min_time)
+ min_time = i->second.deadline;
+ }
+ return min_time.is_null() ? MOJO_DEADLINE_INDEFINITE :
+ std::max(static_cast<MojoDeadline>(0),
+ static_cast<MojoDeadline>(
+ (min_time - internal::NowTicks()).InMicroseconds()));
}
} // namespace common
« no previous file with comments | « mojo/common/message_pump_mojo.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698