diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-10 00:02:46 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-10 00:02:46 +0000 |
commit | 17d26c54db794bc23b4b87ae8f509bcb13d8eb3c (patch) | |
tree | d3f13a7c405b45c4f854976c8b4f86a9659470c7 /mojo/system | |
parent | e4e5e6b5eedfba3d2754ca41134cdcb885bf7fa5 (diff) | |
download | chromium_src-17d26c54db794bc23b4b87ae8f509bcb13d8eb3c.zip chromium_src-17d26c54db794bc23b4b87ae8f509bcb13d8eb3c.tar.gz chromium_src-17d26c54db794bc23b4b87ae8f509bcb13d8eb3c.tar.bz2 |
Mojo: Make default Options directly accessible.
(So tests don't have to run the validation method to get the default.)
R=sky@chromium.org
Review URL: https://codereview.chromium.org/320343002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275881 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/system')
-rw-r--r-- | mojo/system/data_pipe.cc | 18 | ||||
-rw-r--r-- | mojo/system/data_pipe.h | 6 | ||||
-rw-r--r-- | mojo/system/shared_buffer_dispatcher.cc | 13 | ||||
-rw-r--r-- | mojo/system/shared_buffer_dispatcher.h | 5 | ||||
-rw-r--r-- | mojo/system/shared_buffer_dispatcher_unittest.cc | 59 |
5 files changed, 48 insertions, 53 deletions
diff --git a/mojo/system/data_pipe.cc b/mojo/system/data_pipe.cc index 226c381..7f05c04 100644 --- a/mojo/system/data_pipe.cc +++ b/mojo/system/data_pipe.cc @@ -20,19 +20,21 @@ namespace mojo { namespace system { // static +const MojoCreateDataPipeOptions DataPipe::kDefaultCreateOptions = { + static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)), + MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, + 1u, + static_cast<uint32_t>(kDefaultDataPipeCapacityBytes) +}; + +// static MojoResult DataPipe::ValidateCreateOptions( const MojoCreateDataPipeOptions* in_options, MojoCreateDataPipeOptions* out_options) { const MojoCreateDataPipeOptionsFlags kKnownFlags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD; - static const MojoCreateDataPipeOptions kDefaultOptions = { - static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)), - MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, - 1u, - static_cast<uint32_t>(kDefaultDataPipeCapacityBytes) - }; - - *out_options = kDefaultOptions; + + *out_options = kDefaultCreateOptions; if (!in_options) return MOJO_RESULT_OK; diff --git a/mojo/system/data_pipe.h b/mojo/system/data_pipe.h index c4e0d78..d544f87 100644 --- a/mojo/system/data_pipe.h +++ b/mojo/system/data_pipe.h @@ -28,6 +28,12 @@ class WaiterList; class MOJO_SYSTEM_IMPL_EXPORT DataPipe : public base::RefCountedThreadSafe<DataPipe> { public: + // The default options to use for the constructor (and subclasses' + // constructors). (Real uses should obtain this via |ValidateCreateOptions()| + // with a null |in_options|; this is exposed directly for testing + // convenience.) + static const MojoCreateDataPipeOptions kDefaultCreateOptions; + // Validates and/or sets default options for |MojoCreateDataPipeOptions|. If // non-null, |in_options| must point to a struct of at least // |in_options->struct_size| bytes. |out_options| must point to a (current) diff --git a/mojo/system/shared_buffer_dispatcher.cc b/mojo/system/shared_buffer_dispatcher.cc index dc7d35c..57f0b6e 100644 --- a/mojo/system/shared_buffer_dispatcher.cc +++ b/mojo/system/shared_buffer_dispatcher.cc @@ -27,17 +27,20 @@ struct SerializedSharedBufferDispatcher { } // namespace // static +const MojoCreateSharedBufferOptions + SharedBufferDispatcher::kDefaultCreateOptions = { + static_cast<uint32_t>(sizeof(MojoCreateSharedBufferOptions)), + MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE +}; + +// static MojoResult SharedBufferDispatcher::ValidateCreateOptions( const MojoCreateSharedBufferOptions* in_options, MojoCreateSharedBufferOptions* out_options) { const MojoCreateSharedBufferOptionsFlags kKnownFlags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; - static const MojoCreateSharedBufferOptions kDefaultOptions = { - static_cast<uint32_t>(sizeof(MojoCreateSharedBufferOptions)), - MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE - }; - *out_options = kDefaultOptions; + *out_options = kDefaultCreateOptions; if (!in_options) return MOJO_RESULT_OK; diff --git a/mojo/system/shared_buffer_dispatcher.h b/mojo/system/shared_buffer_dispatcher.h index 0599a30..f7c4d1b 100644 --- a/mojo/system/shared_buffer_dispatcher.h +++ b/mojo/system/shared_buffer_dispatcher.h @@ -17,6 +17,11 @@ namespace system { // have anything that's waitable. I want to add a "transferrable" wait flag. class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher : public SimpleDispatcher { public: + // The default options to use for |MojoCreateSharedBuffer()|. (Real uses + // should obtain this via |ValidateCreateOptions()| with a null |in_options|; + // this is exposed directly for testing convenience.) + static const MojoCreateSharedBufferOptions kDefaultCreateOptions; + // Validates and/or sets default options for |MojoCreateSharedBufferOptions|. // If non-null, |in_options| must point to a struct of at least // |in_options->struct_size| bytes. |out_options| must point to a (current) diff --git a/mojo/system/shared_buffer_dispatcher_unittest.cc b/mojo/system/shared_buffer_dispatcher_unittest.cc index 82bc3b3..2683751 100644 --- a/mojo/system/shared_buffer_dispatcher_unittest.cc +++ b/mojo/system/shared_buffer_dispatcher_unittest.cc @@ -100,15 +100,11 @@ TEST(SharedBufferDispatcherTest, ValidateCreateOptionsInvalid) { } TEST(SharedBufferDispatcherTest, CreateAndMapBuffer) { - MojoCreateSharedBufferOptions validated_options = {}; - EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::ValidateCreateOptions(NULL, - &validated_options)); - scoped_refptr<SharedBufferDispatcher> dispatcher; EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::Create(validated_options, 100, - &dispatcher)); + SharedBufferDispatcher::Create( + SharedBufferDispatcher::kDefaultCreateOptions, 100, + &dispatcher)); ASSERT_TRUE(dispatcher); EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType()); @@ -141,13 +137,10 @@ TEST(SharedBufferDispatcherTest, CreateAndMapBuffer) { } TEST(SharedBufferDispatcher, DuplicateBufferHandle) { - MojoCreateSharedBufferOptions validated_options = {}; - EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::ValidateCreateOptions(NULL, - &validated_options)); scoped_refptr<SharedBufferDispatcher> dispatcher1; EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::Create(validated_options, 100, + SharedBufferDispatcher::Create( + SharedBufferDispatcher::kDefaultCreateOptions, 100, &dispatcher1)); // Map and write something. @@ -177,14 +170,11 @@ TEST(SharedBufferDispatcher, DuplicateBufferHandle) { } TEST(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) { - MojoCreateSharedBufferOptions validated_options = {}; - EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::ValidateCreateOptions(NULL, - &validated_options)); scoped_refptr<SharedBufferDispatcher> dispatcher1; EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::Create(validated_options, 100, - &dispatcher1)); + SharedBufferDispatcher::Create( + SharedBufferDispatcher::kDefaultCreateOptions, 100, + &dispatcher1)); MojoDuplicateBufferHandleOptions options[] = { {sizeof(MojoDuplicateBufferHandleOptions), @@ -204,14 +194,11 @@ TEST(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) { } TEST(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) { - MojoCreateSharedBufferOptions validated_options = {}; - EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::ValidateCreateOptions(NULL, - &validated_options)); scoped_refptr<SharedBufferDispatcher> dispatcher1; EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::Create(validated_options, 100, - &dispatcher1)); + SharedBufferDispatcher::Create( + SharedBufferDispatcher::kDefaultCreateOptions, 100, + &dispatcher1)); // Invalid |struct_size|. { @@ -239,35 +226,27 @@ TEST(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) { } TEST(SharedBufferDispatcherTest, CreateInvalidNumBytes) { - MojoCreateSharedBufferOptions validated_options = {}; - EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::ValidateCreateOptions(NULL, - &validated_options)); - // Size too big. scoped_refptr<SharedBufferDispatcher> dispatcher; EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, - SharedBufferDispatcher::Create(validated_options, - std::numeric_limits<uint64_t>::max(), - &dispatcher)); + SharedBufferDispatcher::Create( + SharedBufferDispatcher::kDefaultCreateOptions, + std::numeric_limits<uint64_t>::max(), &dispatcher)); EXPECT_FALSE(dispatcher); // Zero size. EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, - SharedBufferDispatcher::Create(validated_options, 0, &dispatcher)); + SharedBufferDispatcher::Create( + SharedBufferDispatcher::kDefaultCreateOptions, 0, &dispatcher)); EXPECT_FALSE(dispatcher); } TEST(SharedBufferDispatcherTest, MapBufferInvalidArguments) { - MojoCreateSharedBufferOptions validated_options = {}; - EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::ValidateCreateOptions(NULL, - &validated_options)); - scoped_refptr<SharedBufferDispatcher> dispatcher; EXPECT_EQ(MOJO_RESULT_OK, - SharedBufferDispatcher::Create(validated_options, 100, - &dispatcher)); + SharedBufferDispatcher::Create( + SharedBufferDispatcher::kDefaultCreateOptions, 100, + &dispatcher)); scoped_ptr<RawSharedBufferMapping> mapping; EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |