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/entrypoints.h" |
13 #include "mojo/system/message_pipe.h" | 14 #include "mojo/system/message_pipe.h" |
14 #include "mojo/system/message_pipe_dispatcher.h" | 15 #include "mojo/system/message_pipe_dispatcher.h" |
15 #include "mojo/system/raw_channel.h" | 16 #include "mojo/system/raw_channel.h" |
16 | 17 |
17 namespace mojo { | 18 namespace mojo { |
18 namespace embedder { | 19 namespace embedder { |
19 | 20 |
| 21 void Init() { |
| 22 system::entrypoints::SetCore(new system::Core()); |
| 23 } |
| 24 |
20 struct ChannelInfo { | 25 struct ChannelInfo { |
21 scoped_refptr<system::Channel> channel; | 26 scoped_refptr<system::Channel> channel; |
22 }; | 27 }; |
23 | 28 |
24 static void CreateChannelOnIOThread( | 29 static void CreateChannelOnIOThread( |
25 ScopedPlatformHandle platform_handle, | 30 ScopedPlatformHandle platform_handle, |
26 scoped_refptr<system::MessagePipe> message_pipe, | 31 scoped_refptr<system::MessagePipe> message_pipe, |
27 DidCreateChannelCallback callback, | 32 DidCreateChannelCallback callback, |
28 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { | 33 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { |
29 CHECK(platform_handle.is_valid()); | 34 CHECK(platform_handle.is_valid()); |
(...skipping 17 matching lines...) Expand all Loading... |
47 // Hand the channel back to the embedder. | 52 // Hand the channel back to the embedder. |
48 if (callback_thread_task_runner) { | 53 if (callback_thread_task_runner) { |
49 callback_thread_task_runner->PostTask(FROM_HERE, | 54 callback_thread_task_runner->PostTask(FROM_HERE, |
50 base::Bind(callback, | 55 base::Bind(callback, |
51 channel_info.release())); | 56 channel_info.release())); |
52 } else { | 57 } else { |
53 callback.Run(channel_info.release()); | 58 callback.Run(channel_info.release()); |
54 } | 59 } |
55 } | 60 } |
56 | 61 |
57 void Init() { | |
58 Core::Init(new system::CoreImpl()); | |
59 } | |
60 | |
61 ScopedMessagePipeHandle CreateChannel( | 62 ScopedMessagePipeHandle CreateChannel( |
62 ScopedPlatformHandle platform_handle, | 63 ScopedPlatformHandle platform_handle, |
63 scoped_refptr<base::TaskRunner> io_thread_task_runner, | 64 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
64 DidCreateChannelCallback callback, | 65 DidCreateChannelCallback callback, |
65 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { | 66 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { |
66 DCHECK(platform_handle.is_valid()); | 67 DCHECK(platform_handle.is_valid()); |
67 | 68 |
68 std::pair<scoped_refptr<system::MessagePipeDispatcher>, | 69 std::pair<scoped_refptr<system::MessagePipeDispatcher>, |
69 scoped_refptr<system::MessagePipe> > remote_message_pipe = | 70 scoped_refptr<system::MessagePipe> > remote_message_pipe = |
70 system::MessagePipeDispatcher::CreateRemoteMessagePipe(); | 71 system::MessagePipeDispatcher::CreateRemoteMessagePipe(); |
71 | 72 |
72 system::CoreImpl* core_impl = static_cast<system::CoreImpl*>(Core::Get()); | 73 system::Core* core = system::entrypoints::GetCore(); |
73 DCHECK(core_impl); | 74 DCHECK(core); |
74 ScopedMessagePipeHandle rv( | 75 ScopedMessagePipeHandle rv( |
75 MessagePipeHandle(core_impl->AddDispatcher(remote_message_pipe.first))); | 76 MessagePipeHandle(core->AddDispatcher(remote_message_pipe.first))); |
76 // TODO(vtl): Do we properly handle the failure case here? | 77 // TODO(vtl): Do we properly handle the failure case here? |
77 if (rv.is_valid()) { | 78 if (rv.is_valid()) { |
78 io_thread_task_runner->PostTask(FROM_HERE, | 79 io_thread_task_runner->PostTask(FROM_HERE, |
79 base::Bind(&CreateChannelOnIOThread, | 80 base::Bind(&CreateChannelOnIOThread, |
80 base::Passed(&platform_handle), | 81 base::Passed(&platform_handle), |
81 remote_message_pipe.second, | 82 remote_message_pipe.second, |
82 callback, | 83 callback, |
83 callback_thread_task_runner)); | 84 callback_thread_task_runner)); |
84 } | 85 } |
85 return rv.Pass(); | 86 return rv.Pass(); |
86 } | 87 } |
87 | 88 |
88 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { | 89 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { |
89 DCHECK(channel_info); | 90 DCHECK(channel_info); |
90 DCHECK(channel_info->channel.get()); | 91 DCHECK(channel_info->channel.get()); |
91 channel_info->channel->Shutdown(); | 92 channel_info->channel->Shutdown(); |
92 delete channel_info; | 93 delete channel_info; |
93 } | 94 } |
94 | 95 |
95 } // namespace embedder | 96 } // namespace embedder |
96 } // namespace mojo | 97 } // namespace mojo |
OLD | NEW |