| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/embedder/embedder.h" | 5 #include "mojo/embedder/embedder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "mojo/system/channel.h" | 11 #include "mojo/system/channel.h" |
| 12 #include "mojo/system/core_impl.h" | 12 #include "mojo/system/core.h" |
| 13 #include "mojo/system/message_pipe.h" | 13 #include "mojo/system/message_pipe.h" |
| 14 #include "mojo/system/message_pipe_dispatcher.h" | 14 #include "mojo/system/message_pipe_dispatcher.h" |
| 15 #include "mojo/system/raw_channel.h" | 15 #include "mojo/system/raw_channel.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace embedder { | 18 namespace embedder { |
| 19 | 19 |
| 20 struct ChannelInfo { | 20 struct ChannelInfo { |
| 21 scoped_refptr<system::Channel> channel; | 21 scoped_refptr<system::Channel> channel; |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 void Init() { |
| 25 system::Core::GetInstance(); |
| 26 } |
| 27 |
| 24 static void CreateChannelOnIOThread( | 28 static void CreateChannelOnIOThread( |
| 25 ScopedPlatformHandle platform_handle, | 29 ScopedPlatformHandle platform_handle, |
| 26 scoped_refptr<system::MessagePipe> message_pipe, | 30 scoped_refptr<system::MessagePipe> message_pipe, |
| 27 DidCreateChannelCallback callback, | 31 DidCreateChannelCallback callback, |
| 28 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { | 32 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { |
| 29 CHECK(platform_handle.is_valid()); | 33 CHECK(platform_handle.is_valid()); |
| 30 | 34 |
| 31 scoped_ptr<ChannelInfo> channel_info(new ChannelInfo); | 35 scoped_ptr<ChannelInfo> channel_info(new ChannelInfo); |
| 32 | 36 |
| 33 // Create and initialize a |system::Channel|. | 37 // Create and initialize a |system::Channel|. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 // Hand the channel back to the embedder. | 51 // Hand the channel back to the embedder. |
| 48 if (callback_thread_task_runner) { | 52 if (callback_thread_task_runner) { |
| 49 callback_thread_task_runner->PostTask(FROM_HERE, | 53 callback_thread_task_runner->PostTask(FROM_HERE, |
| 50 base::Bind(callback, | 54 base::Bind(callback, |
| 51 channel_info.release())); | 55 channel_info.release())); |
| 52 } else { | 56 } else { |
| 53 callback.Run(channel_info.release()); | 57 callback.Run(channel_info.release()); |
| 54 } | 58 } |
| 55 } | 59 } |
| 56 | 60 |
| 57 void Init() { | |
| 58 Core::Init(new system::CoreImpl()); | |
| 59 } | |
| 60 | |
| 61 ScopedMessagePipeHandle CreateChannel( | 61 ScopedMessagePipeHandle CreateChannel( |
| 62 ScopedPlatformHandle platform_handle, | 62 ScopedPlatformHandle platform_handle, |
| 63 scoped_refptr<base::TaskRunner> io_thread_task_runner, | 63 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
| 64 DidCreateChannelCallback callback, | 64 DidCreateChannelCallback callback, |
| 65 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { | 65 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { |
| 66 DCHECK(platform_handle.is_valid()); | 66 DCHECK(platform_handle.is_valid()); |
| 67 | 67 |
| 68 std::pair<scoped_refptr<system::MessagePipeDispatcher>, | 68 std::pair<scoped_refptr<system::MessagePipeDispatcher>, |
| 69 scoped_refptr<system::MessagePipe> > remote_message_pipe = | 69 scoped_refptr<system::MessagePipe> > remote_message_pipe = |
| 70 system::MessagePipeDispatcher::CreateRemoteMessagePipe(); | 70 system::MessagePipeDispatcher::CreateRemoteMessagePipe(); |
| 71 | 71 |
| 72 system::CoreImpl* core_impl = static_cast<system::CoreImpl*>(Core::Get()); | 72 system::Core* core = system::Core::GetInstance(); |
| 73 DCHECK(core_impl); | 73 DCHECK(core); |
| 74 ScopedMessagePipeHandle rv( | 74 ScopedMessagePipeHandle rv( |
| 75 MessagePipeHandle(core_impl->AddDispatcher(remote_message_pipe.first))); | 75 MessagePipeHandle(core->AddDispatcher(remote_message_pipe.first))); |
| 76 // TODO(vtl): Do we properly handle the failure case here? | 76 // TODO(vtl): Do we properly handle the failure case here? |
| 77 if (rv.is_valid()) { | 77 if (rv.is_valid()) { |
| 78 io_thread_task_runner->PostTask(FROM_HERE, | 78 io_thread_task_runner->PostTask(FROM_HERE, |
| 79 base::Bind(&CreateChannelOnIOThread, | 79 base::Bind(&CreateChannelOnIOThread, |
| 80 base::Passed(&platform_handle), | 80 base::Passed(&platform_handle), |
| 81 remote_message_pipe.second, | 81 remote_message_pipe.second, |
| 82 callback, | 82 callback, |
| 83 callback_thread_task_runner)); | 83 callback_thread_task_runner)); |
| 84 } | 84 } |
| 85 return rv.Pass(); | 85 return rv.Pass(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { | 88 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { |
| 89 DCHECK(channel_info); | 89 DCHECK(channel_info); |
| 90 DCHECK(channel_info->channel.get()); | 90 DCHECK(channel_info->channel.get()); |
| 91 channel_info->channel->Shutdown(); | 91 channel_info->channel->Shutdown(); |
| 92 delete channel_info; | 92 delete channel_info; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace embedder | 95 } // namespace embedder |
| 96 } // namespace mojo | 96 } // namespace mojo |
| OLD | NEW |