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 }; |
(...skipping 24 matching lines...) Expand all Loading... | |
47 // Hand the channel back to the embedder. | 47 // Hand the channel back to the embedder. |
48 if (callback_thread_task_runner) { | 48 if (callback_thread_task_runner) { |
49 callback_thread_task_runner->PostTask(FROM_HERE, | 49 callback_thread_task_runner->PostTask(FROM_HERE, |
50 base::Bind(callback, | 50 base::Bind(callback, |
51 channel_info.release())); | 51 channel_info.release())); |
52 } else { | 52 } else { |
53 callback.Run(channel_info.release()); | 53 callback.Run(channel_info.release()); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 void Init() { | |
viettrungluu
2014/04/09 20:26:52
Please don't do this.
DaveMoore
2014/04/09 22:49:08
Done.
| |
58 Core::Init(new system::CoreImpl()); | |
59 } | |
60 | |
61 ScopedMessagePipeHandle CreateChannel( | 57 ScopedMessagePipeHandle CreateChannel( |
62 ScopedPlatformHandle platform_handle, | 58 ScopedPlatformHandle platform_handle, |
63 scoped_refptr<base::TaskRunner> io_thread_task_runner, | 59 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
64 DidCreateChannelCallback callback, | 60 DidCreateChannelCallback callback, |
65 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { | 61 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { |
66 DCHECK(platform_handle.is_valid()); | 62 DCHECK(platform_handle.is_valid()); |
67 | 63 |
68 std::pair<scoped_refptr<system::MessagePipeDispatcher>, | 64 std::pair<scoped_refptr<system::MessagePipeDispatcher>, |
69 scoped_refptr<system::MessagePipe> > remote_message_pipe = | 65 scoped_refptr<system::MessagePipe> > remote_message_pipe = |
70 system::MessagePipeDispatcher::CreateRemoteMessagePipe(); | 66 system::MessagePipeDispatcher::CreateRemoteMessagePipe(); |
71 | 67 |
72 system::CoreImpl* core_impl = static_cast<system::CoreImpl*>(Core::Get()); | 68 system::Core* core = system::Core::GetInstance(); |
73 DCHECK(core_impl); | 69 DCHECK(core); |
74 ScopedMessagePipeHandle rv( | 70 ScopedMessagePipeHandle rv( |
75 MessagePipeHandle(core_impl->AddDispatcher(remote_message_pipe.first))); | 71 MessagePipeHandle(core->AddDispatcher(remote_message_pipe.first))); |
76 // TODO(vtl): Do we properly handle the failure case here? | 72 // TODO(vtl): Do we properly handle the failure case here? |
77 if (rv.is_valid()) { | 73 if (rv.is_valid()) { |
78 io_thread_task_runner->PostTask(FROM_HERE, | 74 io_thread_task_runner->PostTask(FROM_HERE, |
79 base::Bind(&CreateChannelOnIOThread, | 75 base::Bind(&CreateChannelOnIOThread, |
80 base::Passed(&platform_handle), | 76 base::Passed(&platform_handle), |
81 remote_message_pipe.second, | 77 remote_message_pipe.second, |
82 callback, | 78 callback, |
83 callback_thread_task_runner)); | 79 callback_thread_task_runner)); |
84 } | 80 } |
85 return rv.Pass(); | 81 return rv.Pass(); |
86 } | 82 } |
87 | 83 |
88 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { | 84 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { |
89 DCHECK(channel_info); | 85 DCHECK(channel_info); |
90 DCHECK(channel_info->channel.get()); | 86 DCHECK(channel_info->channel.get()); |
91 channel_info->channel->Shutdown(); | 87 channel_info->channel->Shutdown(); |
92 delete channel_info; | 88 delete channel_info; |
93 } | 89 } |
94 | 90 |
95 } // namespace embedder | 91 } // namespace embedder |
96 } // namespace mojo | 92 } // namespace mojo |
OLD | NEW |