Index: mojo/edk/embedder/embedder.cc |
diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc |
index 7b0dd3997cc824546b90ff4f01b5445b0dd42abe..ca2169ab29809d768d4cf741d2ef66950ee24809 100644 |
--- a/mojo/edk/embedder/embedder.cc |
+++ b/mojo/edk/embedder/embedder.cc |
@@ -9,13 +9,12 @@ |
#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/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" |
@@ -27,13 +26,14 @@ |
// Helper for |CreateChannel...()|. (Note: May return null for some failures.) |
scoped_refptr<system::Channel> MakeChannel( |
+ system::Core* core, |
ScopedPlatformHandle platform_handle, |
scoped_refptr<system::ChannelEndpoint> channel_endpoint) { |
DCHECK(platform_handle.is_valid()); |
// Create and initialize a |system::Channel|. |
scoped_refptr<system::Channel> channel = |
- new system::Channel(internal::g_core->platform_support()); |
+ 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). |
@@ -49,12 +49,14 @@ |
} |
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(platform_handle.Pass(), channel_endpoint); |
+ channel_info->channel = |
+ MakeChannel(core, platform_handle.Pass(), channel_endpoint); |
// Hand the channel back to the embedder. |
if (callback_thread_task_runner.get()) { |
@@ -67,21 +69,8 @@ |
} // namespace |
-namespace internal { |
- |
-// Declared in embedder_internal.h. |
-system::Core* g_core = nullptr; |
- |
-} // namespace internal |
- |
void Init(scoped_ptr<PlatformSupport> platform_support) { |
- // TODO(vtl): Uncomment after fixing Python bindings tests. crbug.com/432670 |
- // DCHECK(!internal::g_core); |
- internal::g_core = new system::Core(platform_support.Pass()); |
-} |
- |
-Configuration* GetConfiguration() { |
- return system::GetMutableConfiguration(); |
+ system::entrypoints::SetCore(new system::Core(platform_support.Pass())); |
} |
// TODO(vtl): Write tests for this. |
@@ -95,13 +84,14 @@ |
scoped_refptr<system::MessagePipeDispatcher> dispatcher = |
system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint); |
- DCHECK(internal::g_core); |
+ system::Core* core = system::entrypoints::GetCore(); |
+ DCHECK(core); |
ScopedMessagePipeHandle rv( |
- MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); |
- |
- *channel_info = |
- new ChannelInfo(MakeChannel(platform_handle.Pass(), channel_endpoint), |
- base::MessageLoopProxy::current()); |
+ MessagePipeHandle(core->AddDispatcher(dispatcher))); |
+ |
+ *channel_info = new ChannelInfo( |
+ MakeChannel(core, platform_handle.Pass(), channel_endpoint), |
+ base::MessageLoopProxy::current()); |
return rv.Pass(); |
} |
@@ -119,20 +109,24 @@ |
scoped_refptr<system::MessagePipeDispatcher> dispatcher = |
system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint); |
- DCHECK(internal::g_core); |
+ system::Core* core = system::entrypoints::GetCore(); |
+ DCHECK(core); |
ScopedMessagePipeHandle rv( |
- MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); |
+ MessagePipeHandle(core->AddDispatcher(dispatcher))); |
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::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::Unretained(core), |
+ 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) |
@@ -181,8 +175,9 @@ |
scoped_refptr<system::Dispatcher> dispatcher( |
new system::PlatformHandleDispatcher(platform_handle.Pass())); |
- DCHECK(internal::g_core); |
- MojoHandle h = internal::g_core->AddDispatcher(dispatcher); |
+ system::Core* core = system::entrypoints::GetCore(); |
+ DCHECK(core); |
+ MojoHandle h = core->AddDispatcher(dispatcher); |
if (h == MOJO_HANDLE_INVALID) { |
LOG(ERROR) << "Handle table full"; |
dispatcher->Close(); |
@@ -197,9 +192,10 @@ |
ScopedPlatformHandle* platform_handle) { |
DCHECK(platform_handle); |
- DCHECK(internal::g_core); |
+ system::Core* core = system::entrypoints::GetCore(); |
+ DCHECK(core); |
scoped_refptr<system::Dispatcher> dispatcher( |
- internal::g_core->GetDispatcher(platform_handle_wrapper_handle)); |
+ core->GetDispatcher(platform_handle_wrapper_handle)); |
if (!dispatcher.get()) |
return MOJO_RESULT_INVALID_ARGUMENT; |