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

Unified Diff: mojo/edk/embedder/embedder.cc

Issue 728133002: Update mojo sdk to rev e01f9a49449381a5eb430c1fd88bf2cae73ec35a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android + ios gyp fixes Created 6 years, 1 month 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/embedder/embedder.h ('k') | mojo/edk/embedder/embedder_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/embedder/embedder.cc
diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc
index ca2169ab29809d768d4cf741d2ef66950ee24809..9c73eb0e1250159694cfcb534c30511aae58f578 100644
--- a/mojo/edk/embedder/embedder.cc
+++ b/mojo/edk/embedder/embedder.cc
@@ -9,12 +9,13 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "mojo/edk/embedder/embedder_internal.h"
#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/entrypoints.h"
#include "mojo/edk/system/message_pipe_dispatcher.h"
#include "mojo/edk/system/platform_handle_dispatcher.h"
#include "mojo/edk/system/raw_channel.h"
@@ -24,39 +25,41 @@ namespace embedder {
namespace {
-// Helper for |CreateChannel...()|. (Note: May return null for some failures.)
-scoped_refptr<system::Channel> MakeChannel(
- system::Core* core,
+// 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(core->platform_support());
+ new system::Channel(internal::g_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).
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(
- system::Core* core,
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(core, 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()) {
@@ -69,8 +72,23 @@ void CreateChannelHelper(
} // namespace
+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) {
- system::entrypoints::SetCore(new system::Core(platform_support.Pass()));
+ 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() {
+ return system::GetMutableConfiguration();
}
// TODO(vtl): Write tests for this.
@@ -84,14 +102,12 @@ ScopedMessagePipeHandle CreateChannelOnIOThread(
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint);
- system::Core* core = system::entrypoints::GetCore();
- DCHECK(core);
+ DCHECK(internal::g_core);
ScopedMessagePipeHandle rv(
- MessagePipeHandle(core->AddDispatcher(dispatcher)));
+ MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher)));
- *channel_info = new ChannelInfo(
- MakeChannel(core, platform_handle.Pass(), channel_endpoint),
- base::MessageLoopProxy::current());
+ *channel_info =
+ new ChannelInfo(MakeChannel(platform_handle.Pass(), channel_endpoint));
return rv.Pass();
}
@@ -109,24 +125,19 @@ ScopedMessagePipeHandle CreateChannel(
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint);
- system::Core* core = system::entrypoints::GetCore();
- DCHECK(core);
+ DCHECK(internal::g_core);
ScopedMessagePipeHandle rv(
- MessagePipeHandle(core->AddDispatcher(dispatcher)));
+ 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(FROM_HERE,
- base::Bind(&CreateChannelHelper,
- base::Unretained(core),
- base::Passed(&platform_handle),
- base::Passed(&channel_info),
- channel_endpoint,
- callback,
- callback_thread_task_runner));
+ io_thread_task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(&CreateChannelHelper, base::Passed(&platform_handle),
+ base::Passed(&channel_info), channel_endpoint, callback,
+ callback_thread_task_runner));
} else {
(callback_thread_task_runner.get() ? callback_thread_task_runner
: io_thread_task_runner)
@@ -136,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(
@@ -175,9 +176,8 @@ MojoResult CreatePlatformHandleWrapper(
scoped_refptr<system::Dispatcher> dispatcher(
new system::PlatformHandleDispatcher(platform_handle.Pass()));
- system::Core* core = system::entrypoints::GetCore();
- DCHECK(core);
- MojoHandle h = core->AddDispatcher(dispatcher);
+ DCHECK(internal::g_core);
+ MojoHandle h = internal::g_core->AddDispatcher(dispatcher);
if (h == MOJO_HANDLE_INVALID) {
LOG(ERROR) << "Handle table full";
dispatcher->Close();
@@ -192,10 +192,9 @@ MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
ScopedPlatformHandle* platform_handle) {
DCHECK(platform_handle);
- system::Core* core = system::entrypoints::GetCore();
- DCHECK(core);
+ DCHECK(internal::g_core);
scoped_refptr<system::Dispatcher> dispatcher(
- core->GetDispatcher(platform_handle_wrapper_handle));
+ internal::g_core->GetDispatcher(platform_handle_wrapper_handle));
if (!dispatcher.get())
return MOJO_RESULT_INVALID_ARGUMENT;
« no previous file with comments | « mojo/edk/embedder/embedder.h ('k') | mojo/edk/embedder/embedder_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698