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/edk/embedder/embedder.h" | 5 #include "mojo/edk/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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 void CreateChannelHelper( | 55 void CreateChannelHelper( |
56 ScopedPlatformHandle platform_handle, | 56 ScopedPlatformHandle platform_handle, |
57 scoped_ptr<ChannelInfo> channel_info, | 57 scoped_ptr<ChannelInfo> channel_info, |
58 scoped_refptr<system::ChannelEndpoint> channel_endpoint, | 58 scoped_refptr<system::ChannelEndpoint> channel_endpoint, |
59 DidCreateChannelCallback callback, | 59 DidCreateChannelCallback callback, |
60 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { | 60 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { |
61 channel_info->channel_id = | 61 channel_info->channel_id = |
62 MakeChannel(platform_handle.Pass(), channel_endpoint); | 62 MakeChannel(platform_handle.Pass(), channel_endpoint); |
63 | 63 |
64 // Hand the channel back to the embedder. | 64 // Hand the channel back to the embedder. |
65 if (callback_thread_task_runner.get()) { | 65 if (callback_thread_task_runner) { |
66 callback_thread_task_runner->PostTask( | 66 callback_thread_task_runner->PostTask( |
67 FROM_HERE, base::Bind(callback, channel_info.release())); | 67 FROM_HERE, base::Bind(callback, channel_info.release())); |
68 } else { | 68 } else { |
69 callback.Run(channel_info.release()); | 69 callback.Run(channel_info.release()); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 namespace internal { | 75 namespace internal { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 return rv.Pass(); | 112 return rv.Pass(); |
113 } | 113 } |
114 | 114 |
115 ScopedMessagePipeHandle CreateChannel( | 115 ScopedMessagePipeHandle CreateChannel( |
116 ScopedPlatformHandle platform_handle, | 116 ScopedPlatformHandle platform_handle, |
117 scoped_refptr<base::TaskRunner> io_thread_task_runner, | 117 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
118 DidCreateChannelCallback callback, | 118 DidCreateChannelCallback callback, |
119 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { | 119 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { |
120 DCHECK(platform_handle.is_valid()); | 120 DCHECK(platform_handle.is_valid()); |
121 DCHECK(io_thread_task_runner.get()); | 121 DCHECK(io_thread_task_runner); |
122 DCHECK(!callback.is_null()); | 122 DCHECK(!callback.is_null()); |
123 | 123 |
124 scoped_refptr<system::ChannelEndpoint> channel_endpoint; | 124 scoped_refptr<system::ChannelEndpoint> channel_endpoint; |
125 scoped_refptr<system::MessagePipeDispatcher> dispatcher = | 125 scoped_refptr<system::MessagePipeDispatcher> dispatcher = |
126 system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint); | 126 system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint); |
127 | 127 |
128 DCHECK(internal::g_core); | 128 DCHECK(internal::g_core); |
129 ScopedMessagePipeHandle rv( | 129 ScopedMessagePipeHandle rv( |
130 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); | 130 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); |
131 | 131 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 return MOJO_RESULT_OK; | 188 return MOJO_RESULT_OK; |
189 } | 189 } |
190 | 190 |
191 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, | 191 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, |
192 ScopedPlatformHandle* platform_handle) { | 192 ScopedPlatformHandle* platform_handle) { |
193 DCHECK(platform_handle); | 193 DCHECK(platform_handle); |
194 | 194 |
195 DCHECK(internal::g_core); | 195 DCHECK(internal::g_core); |
196 scoped_refptr<system::Dispatcher> dispatcher( | 196 scoped_refptr<system::Dispatcher> dispatcher( |
197 internal::g_core->GetDispatcher(platform_handle_wrapper_handle)); | 197 internal::g_core->GetDispatcher(platform_handle_wrapper_handle)); |
198 if (!dispatcher.get()) | 198 if (!dispatcher) |
199 return MOJO_RESULT_INVALID_ARGUMENT; | 199 return MOJO_RESULT_INVALID_ARGUMENT; |
200 | 200 |
201 if (dispatcher->GetType() != system::Dispatcher::kTypePlatformHandle) | 201 if (dispatcher->GetType() != system::Dispatcher::kTypePlatformHandle) |
202 return MOJO_RESULT_INVALID_ARGUMENT; | 202 return MOJO_RESULT_INVALID_ARGUMENT; |
203 | 203 |
204 *platform_handle = | 204 *platform_handle = |
205 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get()) | 205 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get()) |
206 ->PassPlatformHandle() | 206 ->PassPlatformHandle() |
207 .Pass(); | 207 .Pass(); |
208 return MOJO_RESULT_OK; | 208 return MOJO_RESULT_OK; |
209 } | 209 } |
210 | 210 |
211 } // namespace embedder | 211 } // namespace embedder |
212 } // namespace mojo | 212 } // namespace mojo |
OLD | NEW |