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 "ipc/mojo/ipc_channel_mojo.h" | 5 #include "ipc/mojo/ipc_channel_mojo.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "ipc/ipc_listener.h" | 10 #include "ipc/ipc_listener.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 listener, | 65 listener, |
66 io_thread_task_runner_).PassAs<Channel>(); | 66 io_thread_task_runner_).PassAs<Channel>(); |
67 } | 67 } |
68 | 68 |
69 private: | 69 private: |
70 ChannelHandle channel_handle_; | 70 ChannelHandle channel_handle_; |
71 Channel::Mode mode_; | 71 Channel::Mode mode_; |
72 scoped_refptr<base::TaskRunner> io_thread_task_runner_; | 72 scoped_refptr<base::TaskRunner> io_thread_task_runner_; |
73 }; | 73 }; |
74 | 74 |
75 mojo::embedder::PlatformHandle ToPlatformHandle( | |
76 const ChannelHandle& handle) { | |
77 #if defined(OS_POSIX) && !defined(OS_NACL) | |
78 return mojo::embedder::PlatformHandle(handle.socket.fd); | |
79 #elif defined(OS_WIN) | |
80 return mojo::embedder::PlatformHandle(handle.pipe.handle); | |
81 #else | |
82 #error "Unsupported Platform!" | |
83 #endif | |
84 } | |
85 | |
86 } // namespace | 75 } // namespace |
87 | 76 |
88 //------------------------------------------------------------------------------ | 77 //------------------------------------------------------------------------------ |
89 | 78 |
90 void ChannelMojo::ChannelInfoDeleter::operator()( | 79 void ChannelMojo::ChannelInfoDeleter::operator()( |
91 mojo::embedder::ChannelInfo* ptr) const { | 80 mojo::embedder::ChannelInfo* ptr) const { |
92 mojo::embedder::DestroyChannelOnIOThread(ptr); | 81 mojo::embedder::DestroyChannelOnIOThread(ptr); |
93 } | 82 } |
94 | 83 |
95 //------------------------------------------------------------------------------ | 84 //------------------------------------------------------------------------------ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 122 |
134 ChannelMojo::~ChannelMojo() { | 123 ChannelMojo::~ChannelMojo() { |
135 Close(); | 124 Close(); |
136 } | 125 } |
137 | 126 |
138 void ChannelMojo::InitOnIOThread() { | 127 void ChannelMojo::InitOnIOThread() { |
139 mojo::embedder::ChannelInfo* channel_info; | 128 mojo::embedder::ChannelInfo* channel_info; |
140 mojo::ScopedMessagePipeHandle control_pipe = | 129 mojo::ScopedMessagePipeHandle control_pipe = |
141 mojo::embedder::CreateChannelOnIOThread( | 130 mojo::embedder::CreateChannelOnIOThread( |
142 mojo::embedder::ScopedPlatformHandle( | 131 mojo::embedder::ScopedPlatformHandle( |
143 ToPlatformHandle(bootstrap_->TakePipeHandle())), | 132 mojo::embedder::PlatformHandle( |
| 133 bootstrap_->TakePipeHandle().platform_file())), |
144 &channel_info); | 134 &channel_info); |
145 channel_info_.reset(channel_info); | 135 channel_info_.reset(channel_info); |
146 | 136 |
147 switch (mode_) { | 137 switch (mode_) { |
148 case MODE_SERVER: | 138 case MODE_SERVER: |
149 control_reader_.reset( | 139 control_reader_.reset( |
150 new internal::ServerControlReader(control_pipe.Pass(), this)); | 140 new internal::ServerControlReader(control_pipe.Pass(), this)); |
151 break; | 141 break; |
152 case MODE_CLIENT: | 142 case MODE_CLIENT: |
153 control_reader_.reset( | 143 control_reader_.reset( |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 handles->push_back(wrapped_handle); | 270 handles->push_back(wrapped_handle); |
281 } | 271 } |
282 } | 272 } |
283 | 273 |
284 return MOJO_RESULT_OK; | 274 return MOJO_RESULT_OK; |
285 } | 275 } |
286 | 276 |
287 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 277 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
288 | 278 |
289 } // namespace IPC | 279 } // namespace IPC |
OLD | NEW |