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

Unified Diff: mojo/edk/system/core.cc

Issue 1748503002: [mojo-edk] Add MojoWatch and MojoCancelWatch APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 10 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
Index: mojo/edk/system/core.cc
diff --git a/mojo/edk/system/core.cc b/mojo/edk/system/core.cc
index 69c918c0be8b50df111abb11646daac1a610a3b9..a72addabbd3af35ddbd23819b293f482fe10db34 100644
--- a/mojo/edk/system/core.cc
+++ b/mojo/edk/system/core.cc
@@ -47,6 +47,13 @@ const uint32_t kMaxHandlesPerMessage = 1024 * 1024;
// too; for now we just use a constant. This only affects bootstrap pipes.
const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL;
+void CallWatchCallback(MojoWatchCallback callback,
+ uintptr_t context,
+ MojoResult result,
+ MojoHandleSignalsState signals_state) {
+ callback(context, result, signals_state);
+}
+
} // namespace
Core::Core() {}
@@ -105,8 +112,9 @@ bool Core::AddDispatchersFromTransit(
failed = true;
}
if (failed) {
+ Dispatcher::RequestContext request_context;
for (auto d : dispatchers)
- d.dispatcher->Close();
+ d.dispatcher->Close(&request_context);
return false;
}
return true;
@@ -134,7 +142,10 @@ MojoResult Core::PassWrappedPlatformHandle(
PlatformHandleDispatcher* phd =
static_cast<PlatformHandleDispatcher*>(d.get());
*platform_handle = phd->PassPlatformHandle();
- phd->Close();
+
+ Dispatcher::RequestContext request_context;
+ phd->Close(&request_context);
+
return MOJO_RESULT_OK;
}
@@ -201,7 +212,9 @@ MojoResult Core::PassSharedMemoryHandle(
*read_only = false;
*shared_memory_handle = platform_shared_buffer->DuplicateSharedMemoryHandle();
- shm_dispatcher->Close();
+ Dispatcher::RequestContext request_context;
+ shm_dispatcher->Close(&request_context);
+
return result;
}
@@ -275,7 +288,9 @@ MojoResult Core::Close(MojoHandle handle) {
if (rv != MOJO_RESULT_OK)
return rv;
}
- dispatcher->Close();
+
+ Dispatcher::RequestContext request_context;
+ dispatcher->Close(&request_context);
return MOJO_RESULT_OK;
}
@@ -319,6 +334,27 @@ MojoResult Core::WaitMany(const MojoHandle* handles,
return rv;
}
+MojoResult Core::Watch(MojoHandle handle,
+ MojoHandleSignals signals,
+ MojoWatchCallback callback,
+ uintptr_t context) {
+ scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle);
+ if (!dispatcher)
+ return MOJO_RESULT_INVALID_ARGUMENT;
+
+ Dispatcher::RequestContext request_context;
+ return dispatcher->Watch(
+ signals, base::Bind(&CallWatchCallback, callback, context), context,
+ &request_context);
+}
+
+MojoResult Core::CancelWatch(MojoHandle handle, uintptr_t context) {
+ scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle);
+ if (!dispatcher)
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ return dispatcher->CancelWatch(context);
+}
+
MojoResult Core::CreateWaitSet(MojoHandle* wait_set_handle) {
if (!wait_set_handle)
return MOJO_RESULT_INVALID_ARGUMENT;
@@ -327,7 +363,8 @@ MojoResult Core::CreateWaitSet(MojoHandle* wait_set_handle) {
MojoHandle h = AddDispatcher(dispatcher);
if (h == MOJO_HANDLE_INVALID) {
LOG(ERROR) << "Handle table full";
- dispatcher->Close();
+ Dispatcher::RequestContext request_context;
+ dispatcher->Close(&request_context);
return MOJO_RESULT_RESOURCE_EXHAUSTED;
}
@@ -412,8 +449,9 @@ MojoResult Core::CreateMessagePipe(
*message_pipe_handle1 = AddDispatcher(
new MessagePipeDispatcher(GetNodeController(), port1, pipe_id, 1));
if (*message_pipe_handle1 == MOJO_HANDLE_INVALID) {
+ Dispatcher::RequestContext request_context;
scoped_refptr<Dispatcher> unused;
- unused->Close();
+ unused->Close(&request_context);
handles_.GetAndRemoveDispatcher(*message_pipe_handle0, &unused);
return MOJO_RESULT_RESOURCE_EXHAUSTED;
}
@@ -431,8 +469,12 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
- if (num_handles == 0) // Fast path: no handles.
- return dispatcher->WriteMessage(bytes, num_bytes, nullptr, 0, flags);
+ Dispatcher::RequestContext request_context;
+ if (num_handles == 0) {
+ // Fast path: no handles.
+ return dispatcher->WriteMessage(
+ bytes, num_bytes, nullptr, 0, flags, &request_context);
+ }
CHECK(handles);
@@ -447,23 +489,25 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
std::vector<Dispatcher::DispatcherInTransit> dispatchers;
{
base::AutoLock lock(handles_lock_);
- MojoResult rv = handles_.BeginTransit(handles, num_handles, &dispatchers);
+ MojoResult rv = handles_.BeginTransit(
+ handles, num_handles, &dispatchers, &request_context);
if (rv != MOJO_RESULT_OK) {
- handles_.CancelTransit(dispatchers);
+ handles_.CancelTransit(dispatchers, &request_context);
return rv;
}
}
DCHECK_EQ(num_handles, dispatchers.size());
MojoResult rv = dispatcher->WriteMessage(
- bytes, num_bytes, dispatchers.data(), num_handles, flags);
+ bytes, num_bytes, dispatchers.data(), num_handles, flags,
+ &request_context);
{
base::AutoLock lock(handles_lock_);
if (rv == MOJO_RESULT_OK) {
- handles_.CompleteTransitAndClose(dispatchers);
+ handles_.CompleteTransitAndClose(dispatchers, &request_context);
} else {
- handles_.CancelTransit(dispatchers);
+ handles_.CancelTransit(dispatchers, &request_context);
}
}
@@ -481,7 +525,9 @@ MojoResult Core::ReadMessage(MojoHandle message_pipe_handle,
auto dispatcher = GetDispatcher(message_pipe_handle);
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
- return dispatcher->ReadMessage(bytes, num_bytes, handles, num_handles, flags);
+ Dispatcher::RequestContext request_context;
+ return dispatcher->ReadMessage(
+ bytes, num_bytes, handles, num_handles, flags, &request_context);
}
MojoResult Core::CreateDataPipe(
@@ -530,8 +576,10 @@ MojoResult Core::CreateDataPipe(
scoped_refptr<Dispatcher> unused;
handles_.GetAndRemoveDispatcher(*data_pipe_producer_handle, &unused);
}
- producer->Close();
- consumer->Close();
+
+ Dispatcher::RequestContext request_context;
+ producer->Close(&request_context);
+ consumer->Close(&request_context);
return MOJO_RESULT_RESOURCE_EXHAUSTED;
}
@@ -627,7 +675,8 @@ MojoResult Core::CreateSharedBuffer(
*shared_buffer_handle = AddDispatcher(dispatcher);
if (*shared_buffer_handle == MOJO_HANDLE_INVALID) {
LOG(ERROR) << "Handle table full";
- dispatcher->Close();
+ Dispatcher::RequestContext request_context;
+ dispatcher->Close(&request_context);
return MOJO_RESULT_RESOURCE_EXHAUSTED;
}
@@ -652,7 +701,8 @@ MojoResult Core::DuplicateBufferHandle(
*new_buffer_handle = AddDispatcher(new_dispatcher);
if (*new_buffer_handle == MOJO_HANDLE_INVALID) {
LOG(ERROR) << "Handle table full";
- dispatcher->Close();
+ Dispatcher::RequestContext request_context;
+ dispatcher->Close(&request_context);
return MOJO_RESULT_RESOURCE_EXHAUSTED;
}

Powered by Google App Engine
This is Rietveld 408576698