| 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" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 system::Core* core, | 82 system::Core* core, |
| 83 ScopedPlatformHandle platform_handle, | 83 ScopedPlatformHandle platform_handle, |
| 84 scoped_ptr<ChannelInfo> channel_info, | 84 scoped_ptr<ChannelInfo> channel_info, |
| 85 scoped_refptr<system::MessagePipe> message_pipe, | 85 scoped_refptr<system::MessagePipe> message_pipe, |
| 86 DidCreateChannelCallback callback, | 86 DidCreateChannelCallback callback, |
| 87 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { | 87 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { |
| 88 channel_info->channel = | 88 channel_info->channel = |
| 89 MakeChannel(core, platform_handle.Pass(), message_pipe); | 89 MakeChannel(core, platform_handle.Pass(), message_pipe); |
| 90 | 90 |
| 91 // Hand the channel back to the embedder. | 91 // Hand the channel back to the embedder. |
| 92 if (callback_thread_task_runner) { | 92 if (callback_thread_task_runner.get()) { |
| 93 callback_thread_task_runner->PostTask( | 93 callback_thread_task_runner->PostTask( |
| 94 FROM_HERE, base::Bind(callback, channel_info.release())); | 94 FROM_HERE, base::Bind(callback, channel_info.release())); |
| 95 } else { | 95 } else { |
| 96 callback.Run(channel_info.release()); | 96 callback.Run(channel_info.release()); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 void Init(scoped_ptr<PlatformSupport> platform_support) { | 102 void Init(scoped_ptr<PlatformSupport> platform_support) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 if (rv.is_valid()) { | 148 if (rv.is_valid()) { |
| 149 io_thread_task_runner->PostTask(FROM_HERE, | 149 io_thread_task_runner->PostTask(FROM_HERE, |
| 150 base::Bind(&CreateChannelHelper, | 150 base::Bind(&CreateChannelHelper, |
| 151 base::Unretained(core), | 151 base::Unretained(core), |
| 152 base::Passed(&platform_handle), | 152 base::Passed(&platform_handle), |
| 153 base::Passed(&channel_info), | 153 base::Passed(&channel_info), |
| 154 remote_message_pipe.second, | 154 remote_message_pipe.second, |
| 155 callback, | 155 callback, |
| 156 callback_thread_task_runner)); | 156 callback_thread_task_runner)); |
| 157 } else { | 157 } else { |
| 158 (callback_thread_task_runner ? callback_thread_task_runner | 158 (callback_thread_task_runner.get() ? callback_thread_task_runner |
| 159 : io_thread_task_runner) | 159 : io_thread_task_runner) |
| 160 ->PostTask(FROM_HERE, base::Bind(callback, channel_info.release())); | 160 ->PostTask(FROM_HERE, base::Bind(callback, channel_info.release())); |
| 161 } | 161 } |
| 162 | 162 |
| 163 return rv.Pass(); | 163 return rv.Pass(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { | 166 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { |
| 167 DCHECK(channel_info); | 167 DCHECK(channel_info); |
| 168 if (!channel_info->channel) { | 168 if (!channel_info->channel.get()) { |
| 169 // Presumably, |Init()| on the channel failed. | 169 // Presumably, |Init()| on the channel failed. |
| 170 return; | 170 return; |
| 171 } | 171 } |
| 172 | 172 |
| 173 channel_info->channel->Shutdown(); | 173 channel_info->channel->Shutdown(); |
| 174 delete channel_info; | 174 delete channel_info; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // TODO(vtl): Write tests for this. | 177 // TODO(vtl): Write tests for this. |
| 178 void DestroyChannel(ChannelInfo* channel_info) { | 178 void DestroyChannel(ChannelInfo* channel_info) { |
| 179 DCHECK(channel_info); | 179 DCHECK(channel_info); |
| 180 DCHECK(channel_info->io_thread_task_runner); | 180 DCHECK(channel_info->io_thread_task_runner.get()); |
| 181 | 181 |
| 182 if (!channel_info->channel) { | 182 if (!channel_info->channel.get()) { |
| 183 // Presumably, |Init()| on the channel failed. | 183 // Presumably, |Init()| on the channel failed. |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 | 186 |
| 187 channel_info->channel->WillShutdownSoon(); | 187 channel_info->channel->WillShutdownSoon(); |
| 188 channel_info->io_thread_task_runner->PostTask( | 188 channel_info->io_thread_task_runner->PostTask( |
| 189 FROM_HERE, base::Bind(&DestroyChannelOnIOThread, channel_info)); | 189 FROM_HERE, base::Bind(&DestroyChannelOnIOThread, channel_info)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void WillDestroyChannelSoon(ChannelInfo* channel_info) { | 192 void WillDestroyChannelSoon(ChannelInfo* channel_info) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 216 } | 216 } |
| 217 | 217 |
| 218 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, | 218 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, |
| 219 ScopedPlatformHandle* platform_handle) { | 219 ScopedPlatformHandle* platform_handle) { |
| 220 DCHECK(platform_handle); | 220 DCHECK(platform_handle); |
| 221 | 221 |
| 222 system::Core* core = system::entrypoints::GetCore(); | 222 system::Core* core = system::entrypoints::GetCore(); |
| 223 DCHECK(core); | 223 DCHECK(core); |
| 224 scoped_refptr<system::Dispatcher> dispatcher( | 224 scoped_refptr<system::Dispatcher> dispatcher( |
| 225 core->GetDispatcher(platform_handle_wrapper_handle)); | 225 core->GetDispatcher(platform_handle_wrapper_handle)); |
| 226 if (!dispatcher) | 226 if (!dispatcher.get()) |
| 227 return MOJO_RESULT_INVALID_ARGUMENT; | 227 return MOJO_RESULT_INVALID_ARGUMENT; |
| 228 | 228 |
| 229 if (dispatcher->GetType() != system::Dispatcher::kTypePlatformHandle) | 229 if (dispatcher->GetType() != system::Dispatcher::kTypePlatformHandle) |
| 230 return MOJO_RESULT_INVALID_ARGUMENT; | 230 return MOJO_RESULT_INVALID_ARGUMENT; |
| 231 | 231 |
| 232 *platform_handle = | 232 *platform_handle = |
| 233 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get()) | 233 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get()) |
| 234 ->PassPlatformHandle() | 234 ->PassPlatformHandle() |
| 235 .Pass(); | 235 .Pass(); |
| 236 return MOJO_RESULT_OK; | 236 return MOJO_RESULT_OK; |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace embedder | 239 } // namespace embedder |
| 240 } // namespace mojo | 240 } // namespace mojo |
| OLD | NEW |