Make Dispatcher::Type an enum class. * It's not clear if I should make it sized (as int32_t) or not, so I left it unsized for now. * I made the various operator<< inline, and added a missing export macro. (Everything ends up including <ostream> anyway.) * Being strongly typed means that I found a non-sensical static_cast in dispatcher.cc. R=yzshen@chromium.org Review URL: https://codereview.chromium.org/1160203002
diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc index 29c5217..e6c2720 100644 --- a/mojo/edk/embedder/embedder.cc +++ b/mojo/edk/embedder/embedder.cc
@@ -148,7 +148,7 @@ if (!dispatcher) return MOJO_RESULT_INVALID_ARGUMENT; - if (dispatcher->GetType() != system::Dispatcher::kTypePlatformHandle) + if (dispatcher->GetType() != system::Dispatcher::Type::PLATFORM_HANDLE) return MOJO_RESULT_INVALID_ARGUMENT; *platform_handle =
diff --git a/mojo/edk/system/channel_endpoint_id.h b/mojo/edk/system/channel_endpoint_id.h index c673258..afacb4e 100644 --- a/mojo/edk/system/channel_endpoint_id.h +++ b/mojo/edk/system/channel_endpoint_id.h
@@ -81,8 +81,9 @@ "ChannelEndpointId has incorrect size"); // So logging macros and |DCHECK_EQ()|, etc. work. -inline std::ostream& operator<<(std::ostream& out, - const ChannelEndpointId& channel_endpoint_id) { +MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( + std::ostream& out, + const ChannelEndpointId& channel_endpoint_id) { return out << channel_endpoint_id.value(); }
diff --git a/mojo/edk/system/core_test_base.cc b/mojo/edk/system/core_test_base.cc index 7196886..0e58363 100644 --- a/mojo/edk/system/core_test_base.cc +++ b/mojo/edk/system/core_test_base.cc
@@ -30,7 +30,7 @@ } // |Dispatcher| private methods: - Type GetType() const override { return kTypeUnknown; } + Type GetType() const override { return Type::UNKNOWN; } private: ~MockDispatcher() override { info_->IncrementDtorCallCount(); }
diff --git a/mojo/edk/system/data_pipe_consumer_dispatcher.cc b/mojo/edk/system/data_pipe_consumer_dispatcher.cc index bee4b23..076b724 100644 --- a/mojo/edk/system/data_pipe_consumer_dispatcher.cc +++ b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
@@ -20,7 +20,7 @@ } Dispatcher::Type DataPipeConsumerDispatcher::GetType() const { - return kTypeDataPipeConsumer; + return Type::DATA_PIPE_CONSUMER; } // static
diff --git a/mojo/edk/system/data_pipe_impl_unittest.cc b/mojo/edk/system/data_pipe_impl_unittest.cc index 3a77488..1688e3d 100644 --- a/mojo/edk/system/data_pipe_impl_unittest.cc +++ b/mojo/edk/system/data_pipe_impl_unittest.cc
@@ -376,7 +376,7 @@ EXPECT_TRUE(to_send->HasOneRef()); to_send = nullptr; - ASSERT_EQ(Dispatcher::kTypeDataPipeProducer, to_receive->GetType()); + ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType()); producer_dispatcher_ = static_cast<DataPipeProducerDispatcher*>(to_receive.get()); } @@ -426,7 +426,7 @@ EXPECT_TRUE(to_send->HasOneRef()); to_send = nullptr; - ASSERT_EQ(Dispatcher::kTypeDataPipeConsumer, to_receive->GetType()); + ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType()); consumer_dispatcher_ = static_cast<DataPipeConsumerDispatcher*>(to_receive.get()); } @@ -480,7 +480,7 @@ // destroyed. EXPECT_TRUE(to_send->HasOneRef()); to_send = nullptr; - ASSERT_EQ(Dispatcher::kTypeDataPipeProducer, to_receive->GetType()); + ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType()); to_send = static_cast<DataPipeProducerDispatcher*>(to_receive.get()); to_receive = nullptr; @@ -491,7 +491,7 @@ EXPECT_TRUE(to_send->HasOneRef()); to_send = nullptr; - ASSERT_EQ(Dispatcher::kTypeDataPipeProducer, to_receive->GetType()); + ASSERT_EQ(Dispatcher::Type::DATA_PIPE_PRODUCER, to_receive->GetType()); producer_dispatcher_ = static_cast<DataPipeProducerDispatcher*>(to_receive.get()); } @@ -527,7 +527,7 @@ // destroyed. EXPECT_TRUE(to_send->HasOneRef()); to_send = nullptr; - ASSERT_EQ(Dispatcher::kTypeDataPipeConsumer, to_receive->GetType()); + ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType()); to_send = static_cast<DataPipeConsumerDispatcher*>(to_receive.get()); to_receive = nullptr; @@ -538,7 +538,7 @@ EXPECT_TRUE(to_send->HasOneRef()); to_send = nullptr; - ASSERT_EQ(Dispatcher::kTypeDataPipeConsumer, to_receive->GetType()); + ASSERT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, to_receive->GetType()); consumer_dispatcher_ = static_cast<DataPipeConsumerDispatcher*>(to_receive.get()); }
diff --git a/mojo/edk/system/data_pipe_producer_dispatcher.cc b/mojo/edk/system/data_pipe_producer_dispatcher.cc index 2480097..ccd0291 100644 --- a/mojo/edk/system/data_pipe_producer_dispatcher.cc +++ b/mojo/edk/system/data_pipe_producer_dispatcher.cc
@@ -20,7 +20,7 @@ } Dispatcher::Type DataPipeProducerDispatcher::GetType() const { - return kTypeDataPipeProducer; + return Type::DATA_PIPE_PRODUCER; } // static
diff --git a/mojo/edk/system/dispatcher.cc b/mojo/edk/system/dispatcher.cc index e8695e8..24f2c26 100644 --- a/mojo/edk/system/dispatcher.cc +++ b/mojo/edk/system/dispatcher.cc
@@ -71,23 +71,23 @@ const void* source, size_t size, embedder::PlatformHandleVector* platform_handles) { - switch (static_cast<int32_t>(type)) { - case kTypeUnknown: + switch (static_cast<Dispatcher::Type>(type)) { + case Type::UNKNOWN: DVLOG(2) << "Deserializing invalid handle"; return nullptr; - case kTypeMessagePipe: + case Type::MESSAGE_PIPE: return scoped_refptr<Dispatcher>( MessagePipeDispatcher::Deserialize(channel, source, size)); - case kTypeDataPipeProducer: + case Type::DATA_PIPE_PRODUCER: return scoped_refptr<Dispatcher>( DataPipeProducerDispatcher::Deserialize(channel, source, size)); - case kTypeDataPipeConsumer: + case Type::DATA_PIPE_CONSUMER: return scoped_refptr<Dispatcher>( DataPipeConsumerDispatcher::Deserialize(channel, source, size)); - case kTypeSharedBuffer: + case Type::SHARED_BUFFER: return scoped_refptr<Dispatcher>(SharedBufferDispatcher::Deserialize( channel, source, size, platform_handles)); - case kTypePlatformHandle: + case Type::PLATFORM_HANDLE: return scoped_refptr<Dispatcher>(PlatformHandleDispatcher::Deserialize( channel, source, size, platform_handles)); }
diff --git a/mojo/edk/system/dispatcher.h b/mojo/edk/system/dispatcher.h index 8d7e1cb..d7b7780 100644 --- a/mojo/edk/system/dispatcher.h +++ b/mojo/edk/system/dispatcher.h
@@ -8,6 +8,7 @@ #include <stddef.h> #include <stdint.h> +#include <ostream> #include <vector> #include "base/macros.h" @@ -59,15 +60,15 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher : public base::RefCountedThreadSafe<Dispatcher> { public: - enum Type { - kTypeUnknown = 0, - kTypeMessagePipe, - kTypeDataPipeProducer, - kTypeDataPipeConsumer, - kTypeSharedBuffer, + enum class Type { + UNKNOWN = 0, + MESSAGE_PIPE, + DATA_PIPE_PRODUCER, + DATA_PIPE_CONSUMER, + SHARED_BUFFER, // "Private" types (not exposed via the public interface): - kTypePlatformHandle = -1 + PLATFORM_HANDLE = -1 }; virtual Type GetType() const = 0; @@ -399,6 +400,12 @@ // Copy and assign allowed. }; +// So logging macros and |DCHECK_EQ()|, etc. work. +MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, + Dispatcher::Type type) { + return out << static_cast<int>(type); +} + } // namespace system } // namespace mojo
diff --git a/mojo/edk/system/dispatcher_unittest.cc b/mojo/edk/system/dispatcher_unittest.cc index 97e2eed..2b853d2 100644 --- a/mojo/edk/system/dispatcher_unittest.cc +++ b/mojo/edk/system/dispatcher_unittest.cc
@@ -23,7 +23,7 @@ public: TrivialDispatcher() {} - Type GetType() const override { return kTypeUnknown; } + Type GetType() const override { return Type::UNKNOWN; } private: friend class base::RefCountedThreadSafe<TrivialDispatcher>; @@ -41,7 +41,7 @@ TEST(DispatcherTest, Basic) { scoped_refptr<Dispatcher> d(new TrivialDispatcher()); - EXPECT_EQ(Dispatcher::kTypeUnknown, d->GetType()); + EXPECT_EQ(Dispatcher::Type::UNKNOWN, d->GetType()); EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->WriteMessage(NullUserPointer(), 0, nullptr,
diff --git a/mojo/edk/system/message_in_transit.cc b/mojo/edk/system/message_in_transit.cc index 47148f3..4909336 100644 --- a/mojo/edk/system/message_in_transit.cc +++ b/mojo/edk/system/message_in_transit.cc
@@ -205,13 +205,5 @@ } } -std::ostream& operator<<(std::ostream& out, MessageInTransit::Type type) { - return out << static_cast<uint16_t>(type); -} - -std::ostream& operator<<(std::ostream& out, MessageInTransit::Subtype subtype) { - return out << static_cast<uint16_t>(subtype); -} - } // namespace system } // namespace mojo
diff --git a/mojo/edk/system/message_in_transit.h b/mojo/edk/system/message_in_transit.h index 946308c..7e79c48 100644 --- a/mojo/edk/system/message_in_transit.h +++ b/mojo/edk/system/message_in_transit.h
@@ -8,7 +8,7 @@ #include <stddef.h> #include <stdint.h> -#include <iosfwd> +#include <ostream> #include <vector> #include "base/macros.h" @@ -284,10 +284,19 @@ DISALLOW_COPY_AND_ASSIGN(MessageInTransit); }; -// Stream operator for |MessageInTransit::Type| and |Subtype| so we can use -// |CHECK_EQ()|, |EXPECT_EQ()|, etc. -std::ostream& operator<<(std::ostream& out, MessageInTransit::Type type); -std::ostream& operator<<(std::ostream& out, MessageInTransit::Subtype subtype); +// So logging macros and |DCHECK_EQ()|, etc. work. +MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( + std::ostream& out, + MessageInTransit::Type type) { + return out << static_cast<uint16_t>(type); +} + +// So logging macros and |DCHECK_EQ()|, etc. work. +MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( + std::ostream& out, + MessageInTransit::Subtype subtype) { + return out << static_cast<uint16_t>(subtype); +} } // namespace system } // namespace mojo
diff --git a/mojo/edk/system/message_pipe.cc b/mojo/edk/system/message_pipe.cc index 473bf5d..b17344c 100644 --- a/mojo/edk/system/message_pipe.cc +++ b/mojo/edk/system/message_pipe.cc
@@ -352,7 +352,7 @@ for (size_t i = 0; i < transports->size(); i++) { if (!(*transports)[i].is_valid()) continue; - if ((*transports)[i].GetType() == Dispatcher::kTypeMessagePipe) { + if ((*transports)[i].GetType() == Dispatcher::Type::MESSAGE_PIPE) { MessagePipeDispatcherTransport mp_transport((*transports)[i]); if (mp_transport.GetMessagePipe() == this) { // The other case should have been disallowed by |Core|. (Note: |port|
diff --git a/mojo/edk/system/message_pipe_dispatcher.cc b/mojo/edk/system/message_pipe_dispatcher.cc index a6733db..95faede 100644 --- a/mojo/edk/system/message_pipe_dispatcher.cc +++ b/mojo/edk/system/message_pipe_dispatcher.cc
@@ -68,7 +68,7 @@ } Dispatcher::Type MessagePipeDispatcher::GetType() const { - return kTypeMessagePipe; + return Type::MESSAGE_PIPE; } // static @@ -223,7 +223,8 @@ MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( DispatcherTransport transport) : DispatcherTransport(transport) { - DCHECK_EQ(message_pipe_dispatcher()->GetType(), Dispatcher::kTypeMessagePipe); + DCHECK_EQ(message_pipe_dispatcher()->GetType(), + Dispatcher::Type::MESSAGE_PIPE); } } // namespace system
diff --git a/mojo/edk/system/message_pipe_dispatcher_unittest.cc b/mojo/edk/system/message_pipe_dispatcher_unittest.cc index 760aced..55aedb3 100644 --- a/mojo/edk/system/message_pipe_dispatcher_unittest.cc +++ b/mojo/edk/system/message_pipe_dispatcher_unittest.cc
@@ -43,7 +43,7 @@ for (unsigned i = 0; i < 2; i++) { scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher( MessagePipeDispatcher::kDefaultCreateOptions)); - EXPECT_EQ(Dispatcher::kTypeMessagePipe, d0->GetType()); + EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, d0->GetType()); scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher( MessagePipeDispatcher::kDefaultCreateOptions)); {
diff --git a/mojo/edk/system/multiprocess_message_pipe_unittest.cc b/mojo/edk/system/multiprocess_message_pipe_unittest.cc index 3512868..ed2f30f 100644 --- a/mojo/edk/system/multiprocess_message_pipe_unittest.cc +++ b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
@@ -240,7 +240,7 @@ CHECK_EQ(read_buffer, std::string("go 1")); CHECK_EQ(num_dispatchers, 1u); - CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypeSharedBuffer); + CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::Type::SHARED_BUFFER); scoped_refptr<SharedBufferDispatcher> dispatcher( static_cast<SharedBufferDispatcher*>(dispatchers[0].get())); @@ -424,7 +424,7 @@ CHECK_GT(num_handles, 0); for (int i = 0; i < num_handles; ++i) { - CHECK_EQ(dispatchers[i]->GetType(), Dispatcher::kTypePlatformHandle); + CHECK_EQ(dispatchers[i]->GetType(), Dispatcher::Type::PLATFORM_HANDLE); scoped_refptr<PlatformHandleDispatcher> dispatcher( static_cast<PlatformHandleDispatcher*>(dispatchers[i].get()));
diff --git a/mojo/edk/system/platform_handle_dispatcher.cc b/mojo/edk/system/platform_handle_dispatcher.cc index f064c67..94e10e2 100644 --- a/mojo/edk/system/platform_handle_dispatcher.cc +++ b/mojo/edk/system/platform_handle_dispatcher.cc
@@ -32,7 +32,7 @@ } Dispatcher::Type PlatformHandleDispatcher::GetType() const { - return kTypePlatformHandle; + return Type::PLATFORM_HANDLE; } // static
diff --git a/mojo/edk/system/platform_handle_dispatcher_unittest.cc b/mojo/edk/system/platform_handle_dispatcher_unittest.cc index dae53b4..3b37b72 100644 --- a/mojo/edk/system/platform_handle_dispatcher_unittest.cc +++ b/mojo/edk/system/platform_handle_dispatcher_unittest.cc
@@ -39,7 +39,7 @@ scoped_refptr<PlatformHandleDispatcher> dispatcher( new PlatformHandleDispatcher(h.Pass())); EXPECT_FALSE(h.is_valid()); - EXPECT_EQ(Dispatcher::kTypePlatformHandle, dispatcher->GetType()); + EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, dispatcher->GetType()); h = dispatcher->PassPlatformHandle().Pass(); EXPECT_TRUE(h.is_valid()); @@ -79,7 +79,7 @@ DispatcherTransport transport( test::DispatcherTryStartTransport(dispatcher.get())); EXPECT_TRUE(transport.is_valid()); - EXPECT_EQ(Dispatcher::kTypePlatformHandle, transport.GetType()); + EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType()); EXPECT_FALSE(transport.IsBusy()); scoped_refptr<Dispatcher> generic_dispatcher = @@ -90,7 +90,7 @@ EXPECT_TRUE(dispatcher->HasOneRef()); dispatcher = nullptr; - ASSERT_EQ(Dispatcher::kTypePlatformHandle, generic_dispatcher->GetType()); + ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, generic_dispatcher->GetType()); dispatcher = static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get()); fp = mojo::test::FILEFromPlatformHandle(dispatcher->PassPlatformHandle(),
diff --git a/mojo/edk/system/remote_data_pipe_impl_unittest.cc b/mojo/edk/system/remote_data_pipe_impl_unittest.cc index 7efd40a..40d2f6f 100644 --- a/mojo/edk/system/remote_data_pipe_impl_unittest.cc +++ b/mojo/edk/system/remote_data_pipe_impl_unittest.cc
@@ -226,7 +226,8 @@ ASSERT_TRUE(read_dispatchers[0]); EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); - EXPECT_EQ(Dispatcher::kTypeDataPipeConsumer, read_dispatchers[0]->GetType()); + EXPECT_EQ(Dispatcher::Type::DATA_PIPE_CONSUMER, + read_dispatchers[0]->GetType()); consumer = static_cast<DataPipeConsumerDispatcher*>(read_dispatchers[0].get()); read_dispatchers.clear();
diff --git a/mojo/edk/system/remote_message_pipe_unittest.cc b/mojo/edk/system/remote_message_pipe_unittest.cc index 1860c23..6d22da7 100644 --- a/mojo/edk/system/remote_message_pipe_unittest.cc +++ b/mojo/edk/system/remote_message_pipe_unittest.cc
@@ -674,7 +674,7 @@ ASSERT_TRUE(read_dispatchers[0]); EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); - EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); + EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, read_dispatchers[0]->GetType()); dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); // Add the waiter now, before it becomes readable to avoid a race. @@ -848,7 +848,7 @@ ASSERT_TRUE(read_dispatchers[0]); EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); - EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); + EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, read_dispatchers[0]->GetType()); dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); // |dispatcher| should already be readable and not writable. @@ -982,7 +982,7 @@ ASSERT_TRUE(read_dispatchers[0]); EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); - EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType()); + EXPECT_EQ(Dispatcher::Type::SHARED_BUFFER, read_dispatchers[0]->GetType()); dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get()); // Make another mapping. @@ -1101,7 +1101,7 @@ ASSERT_TRUE(read_dispatchers[0]); EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); - EXPECT_EQ(Dispatcher::kTypePlatformHandle, read_dispatchers[0]->GetType()); + EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, read_dispatchers[0]->GetType()); dispatcher = static_cast<PlatformHandleDispatcher*>(read_dispatchers[0].get()); @@ -1238,7 +1238,7 @@ ASSERT_TRUE(read_dispatchers[0]); EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); - EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); + EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, read_dispatchers[0]->GetType()); dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); read_dispatchers.clear(); @@ -1295,7 +1295,7 @@ ASSERT_TRUE(read_dispatchers[0]); EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); - EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); + EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, read_dispatchers[0]->GetType()); dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); read_dispatchers.clear();
diff --git a/mojo/edk/system/shared_buffer_dispatcher.cc b/mojo/edk/system/shared_buffer_dispatcher.cc index db823d5..653c507 100644 --- a/mojo/edk/system/shared_buffer_dispatcher.cc +++ b/mojo/edk/system/shared_buffer_dispatcher.cc
@@ -82,7 +82,7 @@ } Dispatcher::Type SharedBufferDispatcher::GetType() const { - return kTypeSharedBuffer; + return Type::SHARED_BUFFER; } // static
diff --git a/mojo/edk/system/shared_buffer_dispatcher_unittest.cc b/mojo/edk/system/shared_buffer_dispatcher_unittest.cc index 29dcb57..42446c5 100644 --- a/mojo/edk/system/shared_buffer_dispatcher_unittest.cc +++ b/mojo/edk/system/shared_buffer_dispatcher_unittest.cc
@@ -119,7 +119,7 @@ SharedBufferDispatcher::kDefaultCreateOptions, 100, &dispatcher)); ASSERT_TRUE(dispatcher); - EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType()); + EXPECT_EQ(Dispatcher::Type::SHARED_BUFFER, dispatcher->GetType()); // Make a couple of mappings. scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1; @@ -166,7 +166,7 @@ EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle( NullUserPointer(), &dispatcher2)); ASSERT_TRUE(dispatcher2); - EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType()); + EXPECT_EQ(Dispatcher::Type::SHARED_BUFFER, dispatcher2->GetType()); EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); @@ -194,7 +194,7 @@ EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle( MakeUserPointer(&options[i]), &dispatcher2)); ASSERT_TRUE(dispatcher2); - EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType()); + EXPECT_EQ(Dispatcher::Type::SHARED_BUFFER, dispatcher2->GetType()); EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close()); }
diff --git a/mojo/edk/system/simple_dispatcher_unittest.cc b/mojo/edk/system/simple_dispatcher_unittest.cc index b8e57e9..58f1458 100644 --- a/mojo/edk/system/simple_dispatcher_unittest.cc +++ b/mojo/edk/system/simple_dispatcher_unittest.cc
@@ -60,7 +60,7 @@ HandleSignalsStateChangedNoLock(); } - Type GetType() const override { return kTypeUnknown; } + Type GetType() const override { return Type::UNKNOWN; } private: friend class base::RefCountedThreadSafe<MockSimpleDispatcher>;
diff --git a/mojo/edk/system/transport_data.cc b/mojo/edk/system/transport_data.cc index 24b49ec..783a51d 100644 --- a/mojo/edk/system/transport_data.cc +++ b/mojo/edk/system/transport_data.cc
@@ -137,8 +137,8 @@ for (size_t i = 0; i < num_handles; i++) { Dispatcher* dispatcher = (*dispatchers)[i].get(); if (!dispatcher) { - static_assert(Dispatcher::kTypeUnknown == 0, - "Value of Dispatcher::kTypeUnknown must be 0"); + static_assert(static_cast<int32_t>(Dispatcher::Type::UNKNOWN) == 0, + "Value of Dispatcher::Type::UNKNOWN must be 0"); continue; } @@ -166,7 +166,7 @@ #endif } else { // Nothing to do on failure, since |buffer_| was cleared, and - // |kTypeUnknown| is zero. The handle was simply closed. + // |Type::UNKNOWN| is zero. The handle was simply closed. LOG(ERROR) << "Failed to serialize handle to remote message pipe"; }
diff --git a/mojo/edk/system/transport_data.h b/mojo/edk/system/transport_data.h index 9911b11..7cb25d3 100644 --- a/mojo/edk/system/transport_data.h +++ b/mojo/edk/system/transport_data.h
@@ -162,7 +162,8 @@ }; struct HandleTableEntry { - int32_t type; // From |Dispatcher::Type| (|kTypeUnknown| for "invalid"). + // TODO(vtl): Should I make |Dispatcher::Type| an |int32_t| enum class? + int32_t type; // From |Dispatcher::Type| (|UNKNOWN| for "invalid"). uint32_t offset; // Relative to the start of the "secondary buffer". uint32_t size; // (Not including any padding.) uint32_t unused;