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

Unified Diff: mojo/edk/test/mojo_test_base.cc

Issue 2750273002: Revert of Mojo EDK: Introduce MojoQueryHandleSignalsState API (Closed)
Patch Set: Created 3 years, 9 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/edk/test/mojo_test_base.h ('k') | mojo/public/c/system/functions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/test/mojo_test_base.cc
diff --git a/mojo/edk/test/mojo_test_base.cc b/mojo/edk/test/mojo_test_base.cc
index 7b83e5708c675e5f1073ac3efcd0f3ad5f90004d..f1032d7e3f5fe0ef45957dba5c8949cd1cdf5602 100644
--- a/mojo/edk/test/mojo_test_base.cc
+++ b/mojo/edk/test/mojo_test_base.cc
@@ -5,16 +5,13 @@
#include "mojo/edk/test/mojo_test_base.h"
#include "base/memory/ptr_util.h"
-#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "base/synchronization/waitable_event.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/system/handle_signals_state.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/functions.h"
-#include "mojo/public/c/system/watcher.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_MACOSX) && !defined(OS_IOS)
@@ -25,103 +22,6 @@
namespace edk {
namespace test {
-namespace {
-
-class Waiter {
- public:
- Waiter() {}
- ~Waiter() {}
-
- MojoResult Wait(MojoHandle handle,
- MojoHandleSignals signals,
- MojoHandleSignalsState* state) {
- MojoHandle watcher;
- MojoCreateWatcher(&Context::OnNotification, &watcher);
-
- context_ = new Context();
-
- // Balanced by OnNotification in the |MOJO_RESULT_CANCELLED| case.
- context_->AddRef();
-
- DCHECK_EQ(MOJO_RESULT_OK,
- MojoWatch(watcher, handle, signals,
- reinterpret_cast<uintptr_t>(context_.get())));
-
- uint32_t num_ready_contexts = 1;
- uintptr_t ready_context;
- MojoResult ready_result;
- MojoHandleSignalsState ready_state;
- MojoResult rv = MojoArmWatcher(watcher, &num_ready_contexts, &ready_context,
- &ready_result, &ready_state);
- if (rv == MOJO_RESULT_FAILED_PRECONDITION) {
- MojoClose(watcher);
- DCHECK_EQ(1u, num_ready_contexts);
- if (state)
- *state = ready_state;
- return ready_result;
- }
-
- // Wait for the first notification.
- context_->event().Wait();
-
- ready_result = context_->wait_result();
- DCHECK_NE(MOJO_RESULT_UNKNOWN, ready_result);
-
- if (state)
- *state = context_->wait_state();
-
- MojoClose(watcher);
-
- return ready_result;
- }
-
- private:
- class Context : public base::RefCountedThreadSafe<Context> {
- public:
- Context()
- : event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
- base::WaitableEvent::InitialState::NOT_SIGNALED) {}
-
- base::WaitableEvent& event() { return event_; }
- MojoResult wait_result() const { return wait_result_; }
- MojoHandleSignalsState wait_state() const { return wait_state_; }
-
- static void OnNotification(uintptr_t context_value,
- MojoResult result,
- MojoHandleSignalsState state,
- MojoWatcherNotificationFlags flags) {
- auto* context = reinterpret_cast<Context*>(context_value);
- context->Notify(result, state);
- if (result == MOJO_RESULT_CANCELLED)
- context->Release();
- }
-
- private:
- friend class base::RefCountedThreadSafe<Context>;
-
- ~Context() {}
-
- void Notify(MojoResult result, MojoHandleSignalsState state) {
- if (wait_result_ == MOJO_RESULT_UNKNOWN) {
- wait_result_ = result;
- wait_state_ = state;
- }
- event_.Signal();
- }
-
- base::WaitableEvent event_;
- MojoResult wait_result_ = MOJO_RESULT_UNKNOWN;
- MojoHandleSignalsState wait_state_ = {0, 0};
-
- DISALLOW_COPY_AND_ASSIGN(Context);
- };
-
- scoped_refptr<Context> context_;
-
- DISALLOW_COPY_AND_ASSIGN(Waiter);
-};
-
-} // namespace
#if defined(OS_MACOSX) && !defined(OS_IOS)
namespace {
@@ -230,7 +130,9 @@
MojoHandle mp,
MojoHandle* handles,
uint32_t expected_num_handles) {
- CHECK_EQ(WaitForSignals(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK);
+ CHECK_EQ(MojoWait(mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
+ nullptr),
+ MOJO_RESULT_OK);
uint32_t message_size = 0;
uint32_t num_handles = 0;
@@ -252,7 +154,9 @@
// static
std::string MojoTestBase::ReadMessageWithOptionalHandle(MojoHandle mp,
MojoHandle* handle) {
- CHECK_EQ(WaitForSignals(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK);
+ CHECK_EQ(MojoWait(mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
+ nullptr),
+ MOJO_RESULT_OK);
uint32_t message_size = 0;
uint32_t num_handles = 0;
@@ -287,7 +191,9 @@
void MojoTestBase::ReadMessage(MojoHandle mp,
char* data,
size_t num_bytes) {
- CHECK_EQ(WaitForSignals(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK);
+ CHECK_EQ(MojoWait(mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
+ nullptr),
+ MOJO_RESULT_OK);
uint32_t message_size = 0;
uint32_t num_handles = 0;
@@ -382,7 +288,8 @@
// static
void MojoTestBase::WriteData(MojoHandle producer, const std::string& data) {
- CHECK_EQ(WaitForSignals(producer, MOJO_HANDLE_SIGNAL_WRITABLE),
+ CHECK_EQ(MojoWait(producer, MOJO_HANDLE_SIGNAL_WRITABLE,
+ MOJO_DEADLINE_INDEFINITE, nullptr),
MOJO_RESULT_OK);
uint32_t num_bytes = static_cast<uint32_t>(data.size());
CHECK_EQ(MojoWriteData(producer, data.data(), &num_bytes,
@@ -393,7 +300,8 @@
// static
std::string MojoTestBase::ReadData(MojoHandle consumer, size_t size) {
- CHECK_EQ(WaitForSignals(consumer, MOJO_HANDLE_SIGNAL_READABLE),
+ CHECK_EQ(MojoWait(consumer, MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE, nullptr),
MOJO_RESULT_OK);
std::vector<char> buffer(size);
uint32_t num_bytes = static_cast<uint32_t>(size);
@@ -405,21 +313,6 @@
return std::string(buffer.data(), buffer.size());
}
-// static
-MojoHandleSignalsState MojoTestBase::GetSignalsState(MojoHandle handle) {
- MojoHandleSignalsState signals_state;
- CHECK_EQ(MOJO_RESULT_OK, MojoQueryHandleSignalsState(handle, &signals_state));
- return signals_state;
-}
-
-// static
-MojoResult MojoTestBase::WaitForSignals(MojoHandle handle,
- MojoHandleSignals signals,
- MojoHandleSignalsState* state) {
- Waiter waiter;
- return waiter.Wait(handle, signals, state);
-}
-
} // namespace test
} // namespace edk
} // namespace mojo
« no previous file with comments | « mojo/edk/test/mojo_test_base.h ('k') | mojo/public/c/system/functions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698