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

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

Issue 1412283002: Convert mojo::system::Dispatcher to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: no change Created 5 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/edk/system/shared_buffer_dispatcher_unittest.cc ('k') | mojo/edk/system/waiter_test_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/simple_dispatcher_unittest.cc
diff --git a/mojo/edk/system/simple_dispatcher_unittest.cc b/mojo/edk/system/simple_dispatcher_unittest.cc
index 099f8f9bf1ecac59e2aaa6b6bb55f9b5c41809b0..8b5fb5c198946ee8d335cd87470cc7f9c320af99 100644
--- a/mojo/edk/system/simple_dispatcher_unittest.cc
+++ b/mojo/edk/system/simple_dispatcher_unittest.cc
@@ -13,8 +13,9 @@
#include <vector>
#include "base/logging.h"
-#include "base/memory/ref_counted.h"
+#include "mojo/edk/system/ref_ptr.h"
#include "mojo/edk/system/test_utils.h"
+#include "mojo/edk/system/thread_annotations.h"
#include "mojo/edk/system/waiter.h"
#include "mojo/edk/system/waiter_test_utils.h"
#include "mojo/edk/util/make_unique.h"
@@ -27,11 +28,7 @@ namespace {
class MockSimpleDispatcher final : public SimpleDispatcher {
public:
- MockSimpleDispatcher()
- : state_(MOJO_HANDLE_SIGNAL_NONE,
- MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE) {}
- explicit MockSimpleDispatcher(const HandleSignalsState& state)
- : state_(state) {}
+ // Note: Use |MakeRefCounted<MockSimpleDispatcher>()|.
void SetSatisfiedSignals(MojoHandleSignals new_satisfied_signals) {
MutexLocker locker(&mutex());
@@ -65,12 +62,18 @@ class MockSimpleDispatcher final : public SimpleDispatcher {
Type GetType() const override { return Type::UNKNOWN; }
private:
+ FRIEND_MAKE_REF_COUNTED(MockSimpleDispatcher);
+
+ MockSimpleDispatcher()
+ : state_(MOJO_HANDLE_SIGNAL_NONE,
+ MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE) {}
+ explicit MockSimpleDispatcher(const HandleSignalsState& state)
+ : state_(state) {}
~MockSimpleDispatcher() override {}
- scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock()
- override {
- scoped_refptr<MockSimpleDispatcher> rv(new MockSimpleDispatcher(state_));
- return scoped_refptr<Dispatcher>(rv.get());
+ RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() override
+ MOJO_NO_THREAD_SAFETY_ANALYSIS {
+ return MakeRefCounted<MockSimpleDispatcher>(state_);
}
// |Dispatcher| override:
@@ -87,7 +90,7 @@ class MockSimpleDispatcher final : public SimpleDispatcher {
TEST(SimpleDispatcherTest, Basic) {
test::Stopwatch stopwatch;
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
Waiter w;
uint32_t context = 0;
HandleSignalsState hss;
@@ -189,7 +192,7 @@ TEST(SimpleDispatcherTest, Basic) {
TEST(SimpleDispatcherTest, BasicUnsatisfiable) {
test::Stopwatch stopwatch;
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
Waiter w;
uint32_t context = 0;
HandleSignalsState hss;
@@ -262,13 +265,13 @@ TEST(SimpleDispatcherTest, BasicUnsatisfiable) {
TEST(SimpleDispatcherTest, BasicClosed) {
test::Stopwatch stopwatch;
- scoped_refptr<MockSimpleDispatcher> d;
+ RefPtr<MockSimpleDispatcher> d;
Waiter w;
uint32_t context = 0;
HandleSignalsState hss;
// Try adding a writable waiter when the dispatcher has been closed.
- d = new MockSimpleDispatcher();
+ d = MakeRefCounted<MockSimpleDispatcher>();
w.Init();
EXPECT_EQ(MOJO_RESULT_OK, d->Close());
hss = HandleSignalsState();
@@ -279,7 +282,7 @@ TEST(SimpleDispatcherTest, BasicClosed) {
// Shouldn't need to remove the waiter (it was not added).
// Wait (forever) for writable and then the dispatcher is closed.
- d = new MockSimpleDispatcher();
+ d = MakeRefCounted<MockSimpleDispatcher>();
w.Init();
ASSERT_EQ(MOJO_RESULT_OK,
d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2, nullptr));
@@ -291,7 +294,7 @@ TEST(SimpleDispatcherTest, BasicClosed) {
// Don't need to remove waiters from closed dispatchers.
// Wait for zero time for writable and then the dispatcher is closed.
- d = new MockSimpleDispatcher();
+ d = MakeRefCounted<MockSimpleDispatcher>();
w.Init();
ASSERT_EQ(MOJO_RESULT_OK,
d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3, nullptr));
@@ -304,7 +307,7 @@ TEST(SimpleDispatcherTest, BasicClosed) {
// Wait for non-zero, finite time for writable and then the dispatcher is
// closed.
- d = new MockSimpleDispatcher();
+ d = MakeRefCounted<MockSimpleDispatcher>();
w.Init();
ASSERT_EQ(MOJO_RESULT_OK,
d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, nullptr));
@@ -326,7 +329,7 @@ TEST(SimpleDispatcherTest, BasicThreaded) {
// Wait for readable (already readable).
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
{
d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
@@ -347,7 +350,7 @@ TEST(SimpleDispatcherTest, BasicThreaded) {
// Wait for readable and becomes readable after some time.
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
{
test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
MOJO_DEADLINE_INDEFINITE, 2, &did_wait, &result,
@@ -371,7 +374,7 @@ TEST(SimpleDispatcherTest, BasicThreaded) {
// Wait for readable and becomes never-readable after some time.
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
{
test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
MOJO_DEADLINE_INDEFINITE, 3, &did_wait, &result,
@@ -394,7 +397,7 @@ TEST(SimpleDispatcherTest, BasicThreaded) {
// Wait for readable and dispatcher gets closed.
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
MOJO_DEADLINE_INDEFINITE, 4, &did_wait, &result,
&context, &hss);
@@ -414,7 +417,7 @@ TEST(SimpleDispatcherTest, BasicThreaded) {
// Wait for readable and times out.
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
{
test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
2 * test::EpsilonDeadline(), 5, &did_wait,
@@ -448,7 +451,7 @@ TEST(SimpleDispatcherTest, MultipleWaiters) {
// All wait for readable and becomes readable after some time.
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
std::vector<std::unique_ptr<test::WaiterThread>> threads;
for (uint32_t i = 0; i < kNumWaiters; i++) {
threads.push_back(util::MakeUnique<test::WaiterThread>(
@@ -471,7 +474,7 @@ TEST(SimpleDispatcherTest, MultipleWaiters) {
// Some wait for readable, some for writable, and becomes readable after some
// time.
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
std::vector<std::unique_ptr<test::WaiterThread>> threads;
for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
threads.push_back(util::MakeUnique<test::WaiterThread>(
@@ -508,7 +511,7 @@ TEST(SimpleDispatcherTest, MultipleWaiters) {
// Some wait for readable, some for writable, and becomes readable and
// never-writable after some time.
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
std::vector<std::unique_ptr<test::WaiterThread>> threads;
for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
threads.push_back(util::MakeUnique<test::WaiterThread>(
@@ -546,7 +549,7 @@ TEST(SimpleDispatcherTest, MultipleWaiters) {
// Some wait for readable, some for writable, and becomes readable after some
// time.
{
- scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
+ auto d = MakeRefCounted<MockSimpleDispatcher>();
std::vector<std::unique_ptr<test::WaiterThread>> threads;
for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
threads.push_back(util::MakeUnique<test::WaiterThread>(
« no previous file with comments | « mojo/edk/system/shared_buffer_dispatcher_unittest.cc ('k') | mojo/edk/system/waiter_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698