summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-19 03:34:37 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-19 03:36:18 +0000
commitdc5de5193565621968e835ef4220b4e920c9701b (patch)
tree82eadf365150e0a63b079ae59bf2c1f593a22b5a /mojo
parent847ee88f3dd51a3c197016f27e5696ed3e3a90bf (diff)
downloadchromium_src-dc5de5193565621968e835ef4220b4e920c9701b.zip
chromium_src-dc5de5193565621968e835ef4220b4e920c9701b.tar.gz
chromium_src-dc5de5193565621968e835ef4220b4e920c9701b.tar.bz2
Mojo: Make Core own a PlatformSupport, and plumb it through to Channel.
And make SharedBufferDispatcher::Deserialize() use the PlatformSupport from the Channel that's passed to it. (For now, just initialize Core's platform_dispatcher_ with a SimplePlatformSupport. Next, I'll have to add it to Core's ctor and do all the required plumbing for that.) R=darin@chromium.org Review URL: https://codereview.chromium.org/484893004 Cr-Commit-Position: refs/heads/master@{#290475} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/embedder/embedder.cc11
-rw-r--r--mojo/system/channel.cc5
-rw-r--r--mojo/system/channel.h15
-rw-r--r--mojo/system/channel_unittest.cc4
-rw-r--r--mojo/system/core.cc9
-rw-r--r--mojo/system/core.h22
-rw-r--r--mojo/system/multiprocess_message_pipe_unittest.cc23
-rw-r--r--mojo/system/remote_message_pipe_unittest.cc7
-rw-r--r--mojo/system/shared_buffer_dispatcher.cc9
9 files changed, 72 insertions, 33 deletions
diff --git a/mojo/embedder/embedder.cc b/mojo/embedder/embedder.cc
index a9f70c5..cfeddba 100644
--- a/mojo/embedder/embedder.cc
+++ b/mojo/embedder/embedder.cc
@@ -38,12 +38,14 @@ namespace {
// Helper for |CreateChannel...()|. (Note: May return null for some failures.)
scoped_refptr<system::Channel> MakeChannel(
+ system::Core* core,
ScopedPlatformHandle platform_handle,
scoped_refptr<system::MessagePipe> message_pipe) {
DCHECK(platform_handle.is_valid());
// Create and initialize a |system::Channel|.
- scoped_refptr<system::Channel> channel = new system::Channel();
+ scoped_refptr<system::Channel> channel =
+ new system::Channel(core->platform_support());
if (!channel->Init(system::RawChannel::Create(platform_handle.Pass()))) {
// This is very unusual (e.g., maybe |platform_handle| was invalid or we
// reached some system resource limit).
@@ -76,12 +78,14 @@ scoped_refptr<system::Channel> MakeChannel(
}
void CreateChannelHelper(
+ system::Core* core,
ScopedPlatformHandle platform_handle,
scoped_ptr<ChannelInfo> channel_info,
scoped_refptr<system::MessagePipe> message_pipe,
DidCreateChannelCallback callback,
scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
- channel_info->channel = MakeChannel(platform_handle.Pass(), message_pipe);
+ channel_info->channel =
+ MakeChannel(core, platform_handle.Pass(), message_pipe);
// Hand the channel back to the embedder.
if (callback_thread_task_runner) {
@@ -116,7 +120,7 @@ ScopedMessagePipeHandle CreateChannelOnIOThread(
*channel_info = new ChannelInfo();
(*channel_info)->channel =
- MakeChannel(platform_handle.Pass(), remote_message_pipe.second);
+ MakeChannel(core, platform_handle.Pass(), remote_message_pipe.second);
return rv.Pass();
}
@@ -143,6 +147,7 @@ ScopedMessagePipeHandle CreateChannel(
if (rv.is_valid()) {
io_thread_task_runner->PostTask(FROM_HERE,
base::Bind(&CreateChannelHelper,
+ base::Unretained(core),
base::Passed(&platform_handle),
base::Passed(&channel_info),
remote_message_pipe.second,
diff --git a/mojo/system/channel.cc b/mojo/system/channel.cc
index fd5364e..c0b68f1 100644
--- a/mojo/system/channel.cc
+++ b/mojo/system/channel.cc
@@ -36,8 +36,9 @@ Channel::EndpointInfo::EndpointInfo(scoped_refptr<MessagePipe> message_pipe,
Channel::EndpointInfo::~EndpointInfo() {
}
-Channel::Channel()
- : is_running_(false),
+Channel::Channel(embedder::PlatformSupport* platform_support)
+ : platform_support_(platform_support),
+ is_running_(false),
is_shutting_down_(false),
next_local_id_(kBootstrapEndpointId) {
}
diff --git a/mojo/system/channel.h b/mojo/system/channel.h
index 61895d6..0ad0e10 100644
--- a/mojo/system/channel.h
+++ b/mojo/system/channel.h
@@ -23,6 +23,11 @@
#include "mojo/system/system_impl_export.h"
namespace mojo {
+
+namespace embedder {
+class PlatformSupport;
+}
+
namespace system {
// This class is mostly thread-safe. It must be created on an I/O thread.
@@ -55,7 +60,9 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel
// The first message pipe endpoint attached will have this as its local ID.
static const MessageInTransit::EndpointId kBootstrapEndpointId = 1;
- Channel();
+ // |platform_support| (typically owned by |Core|) must remain alive until
+ // after |Shutdown()| is called.
+ explicit Channel(embedder::PlatformSupport* platform_support);
// This must be called on the creation thread before any other methods are
// called, and before references to this object are given to any other
@@ -120,6 +127,10 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel
// See |RawChannel::GetSerializedPlatformHandleSize()|.
size_t GetSerializedPlatformHandleSize() const;
+ embedder::PlatformSupport* platform_support() const {
+ return platform_support_;
+ }
+
private:
struct EndpointInfo {
enum State {
@@ -180,6 +191,8 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel
base::ThreadChecker creation_thread_checker_;
+ embedder::PlatformSupport* const platform_support_;
+
// Note: |MessagePipe|s MUST NOT be used under |lock_|. I.e., |lock_| can only
// be acquired after |MessagePipe::lock_|, never before. Thus to call into a
// |MessagePipe|, a reference should be acquired from
diff --git a/mojo/system/channel_unittest.cc b/mojo/system/channel_unittest.cc
index 33fa6ec..0f6c774 100644
--- a/mojo/system/channel_unittest.cc
+++ b/mojo/system/channel_unittest.cc
@@ -8,6 +8,7 @@
#include "base/location.h"
#include "base/message_loop/message_loop.h"
#include "mojo/embedder/platform_channel_pair.h"
+#include "mojo/embedder/simple_platform_support.h"
#include "mojo/system/local_message_pipe_endpoint.h"
#include "mojo/system/message_in_transit.h"
#include "mojo/system/message_pipe.h"
@@ -42,7 +43,7 @@ class ChannelTest : public testing::Test {
void CreateChannelOnIOThread() {
CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
- channel_ = new Channel();
+ channel_ = new Channel(&platform_support_);
}
void InitChannelOnIOThread() {
@@ -78,6 +79,7 @@ class ChannelTest : public testing::Test {
other_platform_handle_ = channel_pair.PassClientHandle();
}
+ embedder::SimplePlatformSupport platform_support_;
test::TestIOThread io_thread_;
scoped_ptr<RawChannel> raw_channel_;
embedder::ScopedPlatformHandle other_platform_handle_;
diff --git a/mojo/system/core.cc b/mojo/system/core.cc
index 47d63f6..82cb117 100644
--- a/mojo/system/core.cc
+++ b/mojo/system/core.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/time/time.h"
#include "mojo/embedder/platform_shared_buffer.h"
+#include "mojo/embedder/platform_support.h"
#include "mojo/embedder/simple_platform_support.h" // TODO(vtl): Remove this.
#include "mojo/public/c/system/macros.h"
#include "mojo/system/constants.h"
@@ -75,7 +76,8 @@ namespace system {
// - Locks at the "INF" level may not have any locks taken while they are
// held.
-Core::Core() {
+// TODO(vtl): This should take a |scoped_ptr<PlatformSupport>| as a parameter.
+Core::Core() : platform_support_(new embedder::SimplePlatformSupport()) {
}
Core::~Core() {
@@ -463,12 +465,9 @@ MojoResult Core::CreateSharedBuffer(
if (result != MOJO_RESULT_OK)
return result;
- // TODO(vtl): |Core| should have a |PlatformSupport| passed in at creation
- // time, and we should use that instead.
- embedder::SimplePlatformSupport platform_support;
scoped_refptr<SharedBufferDispatcher> dispatcher;
result = SharedBufferDispatcher::Create(
- &platform_support, validated_options, num_bytes, &dispatcher);
+ platform_support(), validated_options, num_bytes, &dispatcher);
if (result != MOJO_RESULT_OK) {
DCHECK(!dispatcher);
return result;
diff --git a/mojo/system/core.h b/mojo/system/core.h
index d590db2..eb9d0f7 100644
--- a/mojo/system/core.h
+++ b/mojo/system/core.h
@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/data_pipe.h"
@@ -20,6 +21,11 @@
#include "mojo/system/system_impl_export.h"
namespace mojo {
+
+namespace embedder {
+class PlatformSupport;
+}
+
namespace system {
class Dispatcher;
@@ -29,7 +35,9 @@ struct HandleSignalsState;
// are thread-safe.
class MOJO_SYSTEM_IMPL_EXPORT Core {
public:
- // These methods are only to be used by via the embedder API (and internally).
+ // ---------------------------------------------------------------------------
+
+ // These methods are only to be used by via the embedder API (and internally):
Core();
virtual ~Core();
@@ -41,7 +49,13 @@ class MOJO_SYSTEM_IMPL_EXPORT Core {
// invalid.
scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle);
- // System calls implementation.
+ embedder::PlatformSupport* platform_support() const {
+ return platform_support_.get();
+ }
+
+ // ---------------------------------------------------------------------------
+
+ // System calls implementation:
MojoTimeTicks GetTimeTicksNow();
MojoResult Close(MojoHandle handle);
MojoResult Wait(MojoHandle handle,
@@ -123,7 +137,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Core {
uint32_t* result_index,
HandleSignalsState* signals_states);
- // ---------------------------------------------------------------------------
+ const scoped_ptr<embedder::PlatformSupport> platform_support_;
// TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we
// had them).
@@ -133,8 +147,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Core {
base::Lock mapping_table_lock_; // Protects |mapping_table_|.
MappingTable mapping_table_;
- // ---------------------------------------------------------------------------
-
DISALLOW_COPY_AND_ASSIGN(Core);
};
diff --git a/mojo/system/multiprocess_message_pipe_unittest.cc b/mojo/system/multiprocess_message_pipe_unittest.cc
index 41a6c91..bccf08c 100644
--- a/mojo/system/multiprocess_message_pipe_unittest.cc
+++ b/mojo/system/multiprocess_message_pipe_unittest.cc
@@ -42,7 +42,9 @@ namespace {
class ChannelThread {
public:
- ChannelThread() : test_io_thread_(test::TestIOThread::kManualStart) {}
+ explicit ChannelThread(embedder::PlatformSupport* platform_support)
+ : platform_support_(platform_support),
+ test_io_thread_(test::TestIOThread::kManualStart) {}
~ChannelThread() { Stop(); }
void Start(embedder::ScopedPlatformHandle platform_handle,
@@ -79,7 +81,7 @@ class ChannelThread {
CHECK(platform_handle.is_valid());
// Create and initialize |Channel|.
- channel_ = new Channel();
+ channel_ = new Channel(platform_support_);
CHECK(channel_->Init(RawChannel::Create(platform_handle.Pass())));
// Attach the message pipe endpoint.
@@ -101,6 +103,7 @@ class ChannelThread {
channel_ = NULL;
}
+ embedder::PlatformSupport* const platform_support_;
test::TestIOThread test_io_thread_;
scoped_refptr<Channel> channel_;
@@ -109,7 +112,7 @@ class ChannelThread {
class MultiprocessMessagePipeTest : public testing::Test {
public:
- MultiprocessMessagePipeTest() {}
+ MultiprocessMessagePipeTest() : channel_thread_(&platform_support_) {}
virtual ~MultiprocessMessagePipeTest() {}
protected:
@@ -117,9 +120,11 @@ class MultiprocessMessagePipeTest : public testing::Test {
channel_thread_.Start(helper_.server_platform_handle.Pass(), mp);
}
+ embedder::PlatformSupport* platform_support() { return &platform_support_; }
mojo::test::MultiprocessTestHelper* helper() { return &helper_; }
private:
+ embedder::SimplePlatformSupport platform_support_;
ChannelThread channel_thread_;
mojo::test::MultiprocessTestHelper helper_;
@@ -148,7 +153,8 @@ MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp,
// (which it doesn't reply to). It'll return the number of messages received,
// not including any "quitquitquit" message, modulo 100.
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
- ChannelThread channel_thread;
+ embedder::SimplePlatformSupport platform_support;
+ ChannelThread channel_thread(&platform_support);
embedder::ScopedPlatformHandle client_platform_handle =
mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
CHECK(client_platform_handle.is_valid());
@@ -317,7 +323,8 @@ TEST_F(MultiprocessMessagePipeTest, QueueMessages) {
}
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
- ChannelThread channel_thread;
+ embedder::SimplePlatformSupport platform_support;
+ ChannelThread channel_thread(&platform_support);
embedder::ScopedPlatformHandle client_platform_handle =
mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
CHECK(client_platform_handle.is_valid());
@@ -428,11 +435,10 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
Init(mp);
// Make a shared buffer.
- embedder::SimplePlatformSupport platform_support;
scoped_refptr<SharedBufferDispatcher> dispatcher;
EXPECT_EQ(MOJO_RESULT_OK,
SharedBufferDispatcher::Create(
- &platform_support,
+ platform_support(),
SharedBufferDispatcher::kDefaultCreateOptions,
100,
&dispatcher));
@@ -515,7 +521,8 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
}
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
- ChannelThread channel_thread;
+ embedder::SimplePlatformSupport platform_support;
+ ChannelThread channel_thread(&platform_support);
embedder::ScopedPlatformHandle client_platform_handle =
mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
CHECK(client_platform_handle.is_valid());
diff --git a/mojo/system/remote_message_pipe_unittest.cc b/mojo/system/remote_message_pipe_unittest.cc
index 0a961bf..f635436 100644
--- a/mojo/system/remote_message_pipe_unittest.cc
+++ b/mojo/system/remote_message_pipe_unittest.cc
@@ -94,6 +94,7 @@ class RemoteMessagePipeTest : public testing::Test {
base::Unretained(this)));
}
+ embedder::PlatformSupport* platform_support() { return &platform_support_; }
test::TestIOThread* io_thread() { return &io_thread_; }
private:
@@ -123,7 +124,7 @@ class RemoteMessagePipeTest : public testing::Test {
CHECK(channel_index == 0 || channel_index == 1);
CHECK(!channels_[channel_index]);
- channels_[channel_index] = new Channel();
+ channels_[channel_index] = new Channel(&platform_support_);
CHECK(channels_[channel_index]->Init(
RawChannel::Create(platform_handles_[channel_index].Pass())));
}
@@ -171,6 +172,7 @@ class RemoteMessagePipeTest : public testing::Test {
SetUpOnIOThread();
}
+ embedder::SimplePlatformSupport platform_support_;
test::TestIOThread io_thread_;
embedder::ScopedPlatformHandle platform_handles_[2];
scoped_refptr<Channel> channels_[2];
@@ -702,11 +704,10 @@ TEST_F(RemoteMessagePipeTest, MAYBE_SharedBufferPassing) {
ConnectMessagePipes(mp0, mp1);
// We'll try to pass this dispatcher.
- embedder::SimplePlatformSupport platform_support;
scoped_refptr<SharedBufferDispatcher> dispatcher;
EXPECT_EQ(MOJO_RESULT_OK,
SharedBufferDispatcher::Create(
- &platform_support,
+ platform_support(),
SharedBufferDispatcher::kDefaultCreateOptions,
100,
&dispatcher));
diff --git a/mojo/system/shared_buffer_dispatcher.cc b/mojo/system/shared_buffer_dispatcher.cc
index fc1a664..3354904 100644
--- a/mojo/system/shared_buffer_dispatcher.cc
+++ b/mojo/system/shared_buffer_dispatcher.cc
@@ -9,8 +9,8 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "mojo/embedder/platform_support.h"
-#include "mojo/embedder/simple_platform_shared_buffer.h" // TODO(vtl): Remove.
#include "mojo/public/c/system/macros.h"
+#include "mojo/system/channel.h"
#include "mojo/system/constants.h"
#include "mojo/system/memory.h"
#include "mojo/system/options_validation.h"
@@ -91,6 +91,8 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize(
const void* source,
size_t size,
embedder::PlatformHandleVector* platform_handles) {
+ DCHECK(channel);
+
if (size != sizeof(SerializedSharedBufferDispatcher)) {
LOG(ERROR) << "Invalid serialized shared buffer dispatcher (bad size)";
return scoped_refptr<SharedBufferDispatcher>();
@@ -121,11 +123,8 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize(
// Wrapping |platform_handle| in a |ScopedPlatformHandle| means that it'll be
// closed even if creation fails.
- // TODO(vtl): This is obviously wrong -- but we need to have a
- // |PlatformSupport| plumbed through (probably via the |Channel|), and use its
- // |CreateSharedBufferFromHandle()|.
scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer(
- embedder::SimplePlatformSharedBuffer::CreateFromPlatformHandle(
+ channel->platform_support()->CreateSharedBufferFromHandle(
num_bytes, embedder::ScopedPlatformHandle(platform_handle)));
if (!shared_buffer) {
LOG(ERROR)