| Index: mojo/edk/embedder/embedder.cc
|
| diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc
|
| index 1d8d89d6c46f5b8157940ff9883dc07e2c60d416..9c73eb0e1250159694cfcb534c30511aae58f578 100644
|
| --- a/mojo/edk/embedder/embedder.cc
|
| +++ b/mojo/edk/embedder/embedder.cc
|
| @@ -13,7 +13,7 @@
|
| #include "mojo/edk/embedder/platform_support.h"
|
| #include "mojo/edk/system/channel.h"
|
| #include "mojo/edk/system/channel_endpoint.h"
|
| -#include "mojo/edk/system/channel_info.h"
|
| +#include "mojo/edk/system/channel_manager.h"
|
| #include "mojo/edk/system/configuration.h"
|
| #include "mojo/edk/system/core.h"
|
| #include "mojo/edk/system/message_pipe_dispatcher.h"
|
| @@ -25,13 +25,15 @@ namespace embedder {
|
|
|
| namespace {
|
|
|
| -// Helper for |CreateChannel...()|. (Note: May return null for some failures.)
|
| -scoped_refptr<system::Channel> MakeChannel(
|
| +// Helper for |CreateChannel...()|. Returns 0 on failure. Called on the channel
|
| +// creation thread.
|
| +system::ChannelId MakeChannel(
|
| ScopedPlatformHandle platform_handle,
|
| scoped_refptr<system::ChannelEndpoint> channel_endpoint) {
|
| DCHECK(platform_handle.is_valid());
|
|
|
| // Create and initialize a |system::Channel|.
|
| + DCHECK(internal::g_core);
|
| scoped_refptr<system::Channel> channel =
|
| new system::Channel(internal::g_core->platform_support());
|
| if (!channel->Init(system::RawChannel::Create(platform_handle.Pass()))) {
|
| @@ -39,22 +41,25 @@ scoped_refptr<system::Channel> MakeChannel(
|
| // reached some system resource limit).
|
| LOG(ERROR) << "Channel::Init() failed";
|
| // Return null, since |Shutdown()| shouldn't be called in this case.
|
| - return scoped_refptr<system::Channel>();
|
| + return 0;
|
| }
|
| - // Once |Init()| has succeeded, we have to return |channel| (since
|
| - // |Shutdown()| will have to be called on it).
|
|
|
| channel->AttachAndRunEndpoint(channel_endpoint, true);
|
| - return channel;
|
| +
|
| + DCHECK(internal::g_channel_manager);
|
| + return internal::g_channel_manager->AddChannel(
|
| + channel, base::MessageLoopProxy::current());
|
| }
|
|
|
| +// Helper for |CreateChannel()|. Called on the channel creation thread.
|
| void CreateChannelHelper(
|
| ScopedPlatformHandle platform_handle,
|
| scoped_ptr<ChannelInfo> channel_info,
|
| scoped_refptr<system::ChannelEndpoint> channel_endpoint,
|
| DidCreateChannelCallback callback,
|
| scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
|
| - channel_info->channel = MakeChannel(platform_handle.Pass(), channel_endpoint);
|
| + channel_info->channel_id =
|
| + MakeChannel(platform_handle.Pass(), channel_endpoint);
|
|
|
| // Hand the channel back to the embedder.
|
| if (callback_thread_task_runner.get()) {
|
| @@ -71,12 +76,15 @@ namespace internal {
|
|
|
| // Declared in embedder_internal.h.
|
| system::Core* g_core = nullptr;
|
| +system::ChannelManager* g_channel_manager = nullptr;
|
|
|
| } // namespace internal
|
|
|
| void Init(scoped_ptr<PlatformSupport> platform_support) {
|
| DCHECK(!internal::g_core);
|
| internal::g_core = new system::Core(platform_support.Pass());
|
| + DCHECK(!internal::g_channel_manager);
|
| + internal::g_channel_manager = new system::ChannelManager();
|
| }
|
|
|
| Configuration* GetConfiguration() {
|
| @@ -99,8 +107,7 @@ ScopedMessagePipeHandle CreateChannelOnIOThread(
|
| MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher)));
|
|
|
| *channel_info =
|
| - new ChannelInfo(MakeChannel(platform_handle.Pass(), channel_endpoint),
|
| - base::MessageLoopProxy::current());
|
| + new ChannelInfo(MakeChannel(platform_handle.Pass(), channel_endpoint));
|
|
|
| return rv.Pass();
|
| }
|
| @@ -122,9 +129,8 @@ ScopedMessagePipeHandle CreateChannel(
|
| ScopedMessagePipeHandle rv(
|
| MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher)));
|
|
|
| + // We'll have to set |channel_info->channel_id| on the I/O thread.
|
| scoped_ptr<ChannelInfo> channel_info(new ChannelInfo());
|
| - // We'll have to set |channel_info->channel| on the I/O thread.
|
| - channel_info->channel_thread_task_runner = io_thread_task_runner;
|
|
|
| if (rv.is_valid()) {
|
| io_thread_task_runner->PostTask(
|
| @@ -141,35 +147,25 @@ ScopedMessagePipeHandle CreateChannel(
|
| return rv.Pass();
|
| }
|
|
|
| -void DestroyChannelOnIOThread(ChannelInfo* channel_info) {
|
| - DCHECK(channel_info);
|
| - if (!channel_info->channel.get()) {
|
| - // Presumably, |Init()| on the channel failed.
|
| - return;
|
| - }
|
| -
|
| - channel_info->channel->Shutdown();
|
| - delete channel_info;
|
| -}
|
| -
|
| // TODO(vtl): Write tests for this.
|
| void DestroyChannel(ChannelInfo* channel_info) {
|
| DCHECK(channel_info);
|
| - DCHECK(channel_info->channel_thread_task_runner.get());
|
| -
|
| - if (!channel_info->channel.get()) {
|
| + if (!channel_info->channel_id) {
|
| // Presumably, |Init()| on the channel failed.
|
| return;
|
| }
|
|
|
| - channel_info->channel->WillShutdownSoon();
|
| - channel_info->channel_thread_task_runner->PostTask(
|
| - FROM_HERE, base::Bind(&DestroyChannelOnIOThread, channel_info));
|
| + DCHECK(internal::g_channel_manager);
|
| + // This will destroy the channel synchronously if called from the channel
|
| + // thread.
|
| + internal::g_channel_manager->ShutdownChannel(channel_info->channel_id);
|
| + delete channel_info;
|
| }
|
|
|
| void WillDestroyChannelSoon(ChannelInfo* channel_info) {
|
| DCHECK(channel_info);
|
| - channel_info->channel->WillShutdownSoon();
|
| + DCHECK(internal::g_channel_manager);
|
| + internal::g_channel_manager->WillShutdownChannel(channel_info->channel_id);
|
| }
|
|
|
| MojoResult CreatePlatformHandleWrapper(
|
|
|