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

Unified Diff: mojo/common/message_pump_mojo.cc

Issue 663873002: Add the ability to observe MessagePumpMojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 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') | mojo/common/message_pump_mojo_unittest.cc » ('j') | 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 6d21af2123834c1ab5ed77a7dfd00a7ecc37e38a..c06927015945f36ba451498a8df9c5639a2ebd95 100644
--- a/mojo/common/message_pump_mojo.cc
+++ b/mojo/common/message_pump_mojo.cc
@@ -97,6 +97,14 @@ void MessagePumpMojo::RemoveHandler(const Handle& handle) {
handlers_.erase(handle);
}
+void MessagePumpMojo::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void MessagePumpMojo::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
void MessagePumpMojo::Run(Delegate* delegate) {
RunState run_state;
// TODO: better deal with error handling.
@@ -175,8 +183,10 @@ bool MessagePumpMojo::DoInternalWork(const RunState& run_state, bool block) {
} else if (result > 0) {
const size_t index = static_cast<size_t>(result);
DCHECK(handlers_.find(wait_state.handles[index]) != handlers_.end());
+ WillSignalHandler();
handlers_[wait_state.handles[index]].handler->OnHandleReady(
wait_state.handles[index]);
+ DidSignalHandler();
} else {
switch (result) {
case MOJO_RESULT_CANCELLED:
@@ -204,7 +214,9 @@ bool MessagePumpMojo::DoInternalWork(const RunState& run_state, bool block) {
if (!i->second.deadline.is_null() && i->second.deadline < now &&
handlers_.find(i->first) != handlers_.end() &&
handlers_[i->first].id == i->second.id) {
+ WillSignalHandler();
i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED);
+ DidSignalHandler();
handlers_.erase(i->first);
did_work = true;
}
@@ -232,7 +244,9 @@ void MessagePumpMojo::RemoveFirstInvalidHandle(const WaitState& wait_state) {
MessagePumpMojoHandler* handler =
handlers_[wait_state.handles[i]].handler;
handlers_.erase(wait_state.handles[i]);
+ WillSignalHandler();
handler->OnHandleError(wait_state.handles[i], result);
+ DidSignalHandler();
return;
}
}
@@ -274,5 +288,13 @@ MojoDeadline MessagePumpMojo::GetDeadlineForWait(
return deadline;
}
+void MessagePumpMojo::WillSignalHandler() {
+ FOR_EACH_OBSERVER(Observer, observers_, WillSignalHandler());
+}
+
+void MessagePumpMojo::DidSignalHandler() {
+ FOR_EACH_OBSERVER(Observer, observers_, DidSignalHandler());
+}
+
} // namespace common
} // namespace mojo
« no previous file with comments | « mojo/common/message_pump_mojo.h ('k') | mojo/common/message_pump_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698