EDK: Convert Core::GetAndRemoveDispatcher() to GetAndRemoveHandle(). R=azani@chromium.org Review URL: https://codereview.chromium.org/1957763002 .
diff --git a/mojo/edk/embedder/system_impl_private_entrypoints.cc b/mojo/edk/embedder/system_impl_private_entrypoints.cc index 79cd309..f35c91f 100644 --- a/mojo/edk/embedder/system_impl_private_entrypoints.cc +++ b/mojo/edk/embedder/system_impl_private_entrypoints.cc
@@ -20,6 +20,7 @@ using mojo::embedder::internal::g_core; using mojo::system::Core; using mojo::system::Dispatcher; +using mojo::system::Handle; using mojo::system::MakeUserPointer; using mojo::util::RefPtr; @@ -55,23 +56,23 @@ if (result_handle == nullptr) return MOJO_RESULT_INVALID_ARGUMENT; - RefPtr<Dispatcher> d; - MojoResult result = from_core->GetAndRemoveDispatcher(handle, &d); + Handle h; + MojoResult result = from_core->GetAndRemoveHandle(handle, &h); if (result != MOJO_RESULT_OK) return result; - // TODO(vtl): The rights should come from the original handle (to be dealt - // with when I fix/replace |Core::GetAndRemoveDispatcher()|. - MojoHandle created_handle = to_core->AddHandle(mojo::system::Handle( - d.Clone(), MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ | - MOJO_HANDLE_RIGHT_WRITE)); + MojoHandle created_handle = + to_core->AddHandle(Handle(h.dispatcher.Clone(), h.rights)); if (created_handle == MOJO_HANDLE_INVALID) { // The handle has been lost, unfortunately. There's no guarentee we can put // it back where it came from, or get the original ID back. Holding locks // for multiple cores risks deadlock, so that isn't a solution. This case // should not happen for reasonable uses of this API, however. + // TODO(vtl): This behaviour is pretty crappy. This can be fixed by marking + // the original handle as busy and only removing it on success, though + // that'd require some work. LOG(ERROR) << "Could not transfer handle"; - d->Close(); + h.dispatcher->Close(); return MOJO_RESULT_RESOURCE_EXHAUSTED; }
diff --git a/mojo/edk/system/core.cc b/mojo/edk/system/core.cc index a3a2bcf..1f2ba7e 100644 --- a/mojo/edk/system/core.cc +++ b/mojo/edk/system/core.cc
@@ -105,17 +105,12 @@ return handle_table_.GetHandle(handle, h); } -MojoResult Core::GetAndRemoveDispatcher(MojoHandle handle, - RefPtr<Dispatcher>* dispatcher) { +MojoResult Core::GetAndRemoveHandle(MojoHandle handle, Handle* h) { if (handle == MOJO_HANDLE_INVALID) return MOJO_RESULT_INVALID_ARGUMENT; MutexLocker locker(&handle_table_mutex_); - Handle h; - MojoResult result = handle_table_.GetAndRemoveHandle(handle, &h); - if (result == MOJO_RESULT_OK) - *dispatcher = std::move(h.dispatcher); - return result; + return handle_table_.GetAndRemoveHandle(handle, h); } MojoResult Core::GetDispatcherAndCheckRights(
diff --git a/mojo/edk/system/core.h b/mojo/edk/system/core.h index 05504fd..74c5f47 100644 --- a/mojo/edk/system/core.h +++ b/mojo/edk/system/core.h
@@ -63,11 +63,9 @@ // busy. MojoResult GetHandle(MojoHandle handle, Handle* h); - // TODO(vtl): Convert this to |GetAndRemoveHandle()|. - // Like |GetDispatcher()|, but on success also removes the handle from the + // Like |GetHandle()|, but on success also removes the handle from the // handle table. - MojoResult GetAndRemoveDispatcher(MojoHandle handle, - util::RefPtr<Dispatcher>* dispatcher); + MojoResult GetAndRemoveHandle(MojoHandle handle, Handle* h); // Gets the dispatcher for the given handle value, which must have (all of) // the rights in |required_handle_rights|.