| 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 "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "ipc/ipc_listener.h" | 11 #include "ipc/ipc_listener.h" |
| 12 #include "ipc/ipc_logging.h" | 12 #include "ipc/ipc_logging.h" |
| 13 #include "ipc/ipc_message_attachment_set.h" | 13 #include "ipc/ipc_message_attachment_set.h" |
| 14 #include "ipc/ipc_message_macros.h" | 14 #include "ipc/ipc_message_macros.h" |
| 15 #include "ipc/mojo/client_channel.mojom.h" | 15 #include "ipc/mojo/client_channel.mojom.h" |
| 16 #include "ipc/mojo/ipc_mojo_bootstrap.h" | 16 #include "ipc/mojo/ipc_mojo_bootstrap.h" |
| 17 #include "ipc/mojo/ipc_mojo_handle_attachment.h" | 17 #include "ipc/mojo/ipc_mojo_handle_attachment.h" |
| 18 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
| 19 |
| 20 #if defined(USE_CHROME_EDK) |
| 21 #include "mojo/edk/embedder/embedder.h" |
| 22 #else |
| 18 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 23 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 19 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 24 #endif |
| 20 | 25 |
| 21 #if defined(OS_POSIX) && !defined(OS_NACL) | 26 #if defined(OS_POSIX) && !defined(OS_NACL) |
| 22 #include "ipc/ipc_platform_file_attachment_posix.h" | 27 #include "ipc/ipc_platform_file_attachment_posix.h" |
| 23 #endif | 28 #endif |
| 24 | 29 |
| 30 // TODO(jam): do more tests on using channel on same thread if it supports it ( |
| 31 // i.e. with USE_CHROME_EDK and Windows). Also see message_pipe_dispatcher.cc |
| 32 bool g_use_channel_on_io = true; |
| 33 |
| 25 namespace IPC { | 34 namespace IPC { |
| 26 | 35 |
| 27 namespace { | 36 namespace { |
| 28 | 37 |
| 29 class MojoChannelFactory : public ChannelFactory { | 38 class MojoChannelFactory : public ChannelFactory { |
| 30 public: | 39 public: |
| 31 MojoChannelFactory(scoped_refptr<base::TaskRunner> io_runner, | 40 MojoChannelFactory(scoped_refptr<base::TaskRunner> io_runner, |
| 32 ChannelHandle channel_handle, | 41 ChannelHandle channel_handle, |
| 33 Channel::Mode mode, | 42 Channel::Mode mode, |
| 34 AttachmentBroker* broker) | 43 AttachmentBroker* broker) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 48 | 57 |
| 49 private: | 58 private: |
| 50 scoped_refptr<base::TaskRunner> io_runner_; | 59 scoped_refptr<base::TaskRunner> io_runner_; |
| 51 ChannelHandle channel_handle_; | 60 ChannelHandle channel_handle_; |
| 52 Channel::Mode mode_; | 61 Channel::Mode mode_; |
| 53 AttachmentBroker* broker_; | 62 AttachmentBroker* broker_; |
| 54 }; | 63 }; |
| 55 | 64 |
| 56 //------------------------------------------------------------------------------ | 65 //------------------------------------------------------------------------------ |
| 57 | 66 |
| 58 class ClientChannelMojo : public ChannelMojo, public ClientChannel { | 67 class ClientChannelMojo |
| 68 : public ChannelMojo |
| 69 #if !defined(USE_CHROME_EDK) |
| 70 , public ClientChannel |
| 71 #endif |
| 72 { |
| 59 public: | 73 public: |
| 60 ClientChannelMojo(scoped_refptr<base::TaskRunner> io_runner, | 74 ClientChannelMojo(scoped_refptr<base::TaskRunner> io_runner, |
| 61 const ChannelHandle& handle, | 75 const ChannelHandle& handle, |
| 62 Listener* listener, | 76 Listener* listener, |
| 63 AttachmentBroker* broker); | 77 AttachmentBroker* broker) |
| 64 ~ClientChannelMojo() override; | 78 : ChannelMojo(io_runner, handle, Channel::MODE_CLIENT, listener, broker), |
| 79 #if !defined(USE_CHROME_EDK) |
| 80 binding_(this), |
| 81 #endif |
| 82 weak_factory_(this) { |
| 83 } |
| 84 ~ClientChannelMojo() override {} |
| 65 // MojoBootstrap::Delegate implementation | 85 // MojoBootstrap::Delegate implementation |
| 66 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle) override; | 86 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle, |
| 87 int32 peer_pid) override { |
| 88 #if defined(USE_CHROME_EDK) |
| 89 InitMessageReader( |
| 90 mojo::embedder::CreateMessagePipe(handle.Pass()), peer_pid); |
| 91 #else |
| 92 CreateMessagingPipe(handle.Pass(), base::Bind(&ClientChannelMojo::BindPipe, |
| 93 weak_factory_.GetWeakPtr())); |
| 94 #endif |
| 95 } |
| 67 | 96 |
| 97 #if !defined(USE_CHROME_EDK) |
| 68 // ClientChannel implementation | 98 // ClientChannel implementation |
| 69 void Init( | 99 void Init( |
| 70 mojo::ScopedMessagePipeHandle pipe, | 100 mojo::ScopedMessagePipeHandle pipe, |
| 71 int32_t peer_pid, | 101 int32_t peer_pid, |
| 72 const mojo::Callback<void(int32_t)>& callback) override; | 102 const mojo::Callback<void(int32_t)>& callback) override { |
| 103 InitMessageReader(pipe.Pass(), static_cast<base::ProcessId>(peer_pid)); |
| 104 callback.Run(GetSelfPID()); |
| 105 } |
| 106 #endif |
| 73 | 107 |
| 74 private: | 108 private: |
| 75 void BindPipe(mojo::ScopedMessagePipeHandle handle); | 109 #if !defined(USE_CHROME_EDK) |
| 76 void OnConnectionError(); | 110 void BindPipe(mojo::ScopedMessagePipeHandle handle) { |
| 111 // binding_.Bind(handle.Pass()); |
| 112 } |
| 113 void OnConnectionError() { |
| 114 listener()->OnChannelError(); |
| 115 } |
| 77 | 116 |
| 78 mojo::Binding<ClientChannel> binding_; | 117 mojo::Binding<ClientChannel> binding_; |
| 118 #endif |
| 79 base::WeakPtrFactory<ClientChannelMojo> weak_factory_; | 119 base::WeakPtrFactory<ClientChannelMojo> weak_factory_; |
| 80 | 120 |
| 81 DISALLOW_COPY_AND_ASSIGN(ClientChannelMojo); | 121 DISALLOW_COPY_AND_ASSIGN(ClientChannelMojo); |
| 82 }; | 122 }; |
| 83 | 123 |
| 84 ClientChannelMojo::ClientChannelMojo(scoped_refptr<base::TaskRunner> io_runner, | |
| 85 const ChannelHandle& handle, | |
| 86 Listener* listener, | |
| 87 AttachmentBroker* broker) | |
| 88 : ChannelMojo(io_runner, handle, Channel::MODE_CLIENT, listener, broker), | |
| 89 binding_(this), | |
| 90 weak_factory_(this) { | |
| 91 } | |
| 92 | |
| 93 ClientChannelMojo::~ClientChannelMojo() { | |
| 94 } | |
| 95 | |
| 96 void ClientChannelMojo::OnPipeAvailable( | |
| 97 mojo::embedder::ScopedPlatformHandle handle) { | |
| 98 CreateMessagingPipe(handle.Pass(), base::Bind(&ClientChannelMojo::BindPipe, | |
| 99 weak_factory_.GetWeakPtr())); | |
| 100 } | |
| 101 | |
| 102 void ClientChannelMojo::Init( | |
| 103 mojo::ScopedMessagePipeHandle pipe, | |
| 104 int32_t peer_pid, | |
| 105 const mojo::Callback<void(int32_t)>& callback) { | |
| 106 InitMessageReader(pipe.Pass(), static_cast<base::ProcessId>(peer_pid)); | |
| 107 callback.Run(GetSelfPID()); | |
| 108 } | |
| 109 | |
| 110 void ClientChannelMojo::BindPipe(mojo::ScopedMessagePipeHandle handle) { | |
| 111 binding_.Bind(handle.Pass()); | |
| 112 } | |
| 113 | |
| 114 void ClientChannelMojo::OnConnectionError() { | |
| 115 listener()->OnChannelError(); | |
| 116 } | |
| 117 | |
| 118 //------------------------------------------------------------------------------ | 124 //------------------------------------------------------------------------------ |
| 119 | 125 |
| 120 class ServerChannelMojo : public ChannelMojo { | 126 class ServerChannelMojo : public ChannelMojo { |
| 121 public: | 127 public: |
| 122 ServerChannelMojo(scoped_refptr<base::TaskRunner> io_runner, | 128 ServerChannelMojo(scoped_refptr<base::TaskRunner> io_runner, |
| 123 const ChannelHandle& handle, | 129 const ChannelHandle& handle, |
| 124 Listener* listener, | 130 Listener* listener, |
| 125 AttachmentBroker* broker); | 131 AttachmentBroker* broker) |
| 126 ~ServerChannelMojo() override; | 132 : ChannelMojo(io_runner, handle, Channel::MODE_SERVER, listener, broker), |
| 133 weak_factory_(this) { |
| 134 } |
| 135 ~ServerChannelMojo() override { |
| 136 Close(); |
| 137 } |
| 127 | 138 |
| 128 // MojoBootstrap::Delegate implementation | 139 // MojoBootstrap::Delegate implementation |
| 129 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle) override; | 140 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle, |
| 141 int32 peer_pid) override { |
| 142 #if defined(USE_CHROME_EDK) |
| 143 message_pipe_ = mojo::embedder::CreateMessagePipe(handle.Pass()); |
| 144 if (!message_pipe_.is_valid()) { |
| 145 LOG(WARNING) << "mojo::CreateMessagePipe failed: "; |
| 146 listener()->OnChannelError(); |
| 147 return; |
| 148 } |
| 149 InitMessageReader(message_pipe_.Pass(), peer_pid); |
| 150 #else |
| 151 mojo::ScopedMessagePipeHandle peer; |
| 152 MojoResult create_result = |
| 153 mojo::CreateMessagePipe(nullptr, &message_pipe_, &peer); |
| 154 if (create_result != MOJO_RESULT_OK) { |
| 155 LOG(WARNING) << "mojo::CreateMessagePipe failed: " << create_result; |
| 156 listener()->OnChannelError(); |
| 157 return; |
| 158 } |
| 159 CreateMessagingPipe( |
| 160 handle.Pass(), |
| 161 base::Bind(&ServerChannelMojo::InitClientChannel, |
| 162 weak_factory_.GetWeakPtr(), base::Passed(&peer))); |
| 163 #endif |
| 164 } |
| 130 // Channel override | 165 // Channel override |
| 131 void Close() override; | 166 void Close() override { |
| 167 #if !defined(USE_CHROME_EDK) |
| 168 client_channel_.reset(); |
| 169 #endif |
| 170 message_pipe_.reset(); |
| 171 ChannelMojo::Close(); |
| 172 } |
| 132 | 173 |
| 133 private: | 174 private: |
| 175 #if !defined(USE_CHROME_EDK) |
| 134 void InitClientChannel(mojo::ScopedMessagePipeHandle peer_handle, | 176 void InitClientChannel(mojo::ScopedMessagePipeHandle peer_handle, |
| 135 mojo::ScopedMessagePipeHandle handle); | 177 mojo::ScopedMessagePipeHandle handle) { |
| 136 void OnConnectionError(); | 178 client_channel_.Bind( |
| 179 mojo::InterfacePtrInfo<ClientChannel>(handle.Pass(), 0u)); |
| 180 client_channel_.set_connection_error_handler(base::Bind( |
| 181 &ServerChannelMojo::OnConnectionError, base::Unretained(this))); |
| 182 client_channel_->Init( |
| 183 peer_handle.Pass(), static_cast<int32_t>(GetSelfPID()), |
| 184 base::Bind(&ServerChannelMojo::ClientChannelWasInitialized, |
| 185 base::Unretained(this))); |
| 186 } |
| 187 #endif |
| 188 void OnConnectionError() { |
| 189 listener()->OnChannelError(); |
| 190 } |
| 137 | 191 |
| 192 #if !defined(USE_CHROME_EDK) |
| 138 // ClientChannelClient implementation | 193 // ClientChannelClient implementation |
| 139 void ClientChannelWasInitialized(int32_t peer_pid); | 194 void ClientChannelWasInitialized(int32_t peer_pid) { |
| 195 InitMessageReader(message_pipe_.Pass(), peer_pid); |
| 196 } |
| 140 | 197 |
| 141 mojo::InterfacePtr<ClientChannel> client_channel_; | 198 mojo::InterfacePtr<ClientChannel> client_channel_; |
| 199 #endif |
| 142 mojo::ScopedMessagePipeHandle message_pipe_; | 200 mojo::ScopedMessagePipeHandle message_pipe_; |
| 143 base::WeakPtrFactory<ServerChannelMojo> weak_factory_; | 201 base::WeakPtrFactory<ServerChannelMojo> weak_factory_; |
| 144 | 202 |
| 145 DISALLOW_COPY_AND_ASSIGN(ServerChannelMojo); | 203 DISALLOW_COPY_AND_ASSIGN(ServerChannelMojo); |
| 146 }; | 204 }; |
| 147 | 205 |
| 148 ServerChannelMojo::ServerChannelMojo(scoped_refptr<base::TaskRunner> io_runner, | |
| 149 const ChannelHandle& handle, | |
| 150 Listener* listener, | |
| 151 AttachmentBroker* broker) | |
| 152 : ChannelMojo(io_runner, handle, Channel::MODE_SERVER, listener, broker), | |
| 153 weak_factory_(this) { | |
| 154 } | |
| 155 | |
| 156 ServerChannelMojo::~ServerChannelMojo() { | |
| 157 Close(); | |
| 158 } | |
| 159 | |
| 160 void ServerChannelMojo::OnPipeAvailable( | |
| 161 mojo::embedder::ScopedPlatformHandle handle) { | |
| 162 mojo::ScopedMessagePipeHandle peer; | |
| 163 MojoResult create_result = | |
| 164 mojo::CreateMessagePipe(nullptr, &message_pipe_, &peer); | |
| 165 if (create_result != MOJO_RESULT_OK) { | |
| 166 LOG(WARNING) << "mojo::CreateMessagePipe failed: " << create_result; | |
| 167 listener()->OnChannelError(); | |
| 168 return; | |
| 169 } | |
| 170 CreateMessagingPipe( | |
| 171 handle.Pass(), | |
| 172 base::Bind(&ServerChannelMojo::InitClientChannel, | |
| 173 weak_factory_.GetWeakPtr(), base::Passed(&peer))); | |
| 174 } | |
| 175 | |
| 176 void ServerChannelMojo::Close() { | |
| 177 client_channel_.reset(); | |
| 178 message_pipe_.reset(); | |
| 179 ChannelMojo::Close(); | |
| 180 } | |
| 181 | |
| 182 void ServerChannelMojo::InitClientChannel( | |
| 183 mojo::ScopedMessagePipeHandle peer_handle, | |
| 184 mojo::ScopedMessagePipeHandle handle) { | |
| 185 client_channel_.Bind( | |
| 186 mojo::InterfacePtrInfo<ClientChannel>(handle.Pass(), 0u)); | |
| 187 client_channel_.set_connection_error_handler(base::Bind( | |
| 188 &ServerChannelMojo::OnConnectionError, base::Unretained(this))); | |
| 189 client_channel_->Init( | |
| 190 peer_handle.Pass(), static_cast<int32_t>(GetSelfPID()), | |
| 191 base::Bind(&ServerChannelMojo::ClientChannelWasInitialized, | |
| 192 base::Unretained(this))); | |
| 193 } | |
| 194 | |
| 195 void ServerChannelMojo::OnConnectionError() { | |
| 196 listener()->OnChannelError(); | |
| 197 } | |
| 198 | |
| 199 void ServerChannelMojo::ClientChannelWasInitialized(int32_t peer_pid) { | |
| 200 InitMessageReader(message_pipe_.Pass(), peer_pid); | |
| 201 } | |
| 202 | |
| 203 #if defined(OS_POSIX) && !defined(OS_NACL) | 206 #if defined(OS_POSIX) && !defined(OS_NACL) |
| 204 | 207 |
| 205 base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { | 208 base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { |
| 206 return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile()) | 209 return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile()) |
| 207 : base::ScopedFD(dup(attachment->file())); | 210 : base::ScopedFD(dup(attachment->file())); |
| 208 } | 211 } |
| 209 | 212 |
| 210 #endif | 213 #endif |
| 211 | 214 |
| 212 } // namespace | 215 } // namespace |
| 213 | 216 |
| 217 #if !defined(USE_CHROME_EDK) |
| 214 //------------------------------------------------------------------------------ | 218 //------------------------------------------------------------------------------ |
| 215 | 219 |
| 216 ChannelMojo::ChannelInfoDeleter::ChannelInfoDeleter( | 220 ChannelMojo::ChannelInfoDeleter::ChannelInfoDeleter( |
| 217 scoped_refptr<base::TaskRunner> io_runner) | 221 scoped_refptr<base::TaskRunner> io_runner) |
| 218 : io_runner(io_runner) { | 222 : io_runner(io_runner) { |
| 219 } | 223 } |
| 220 | 224 |
| 221 ChannelMojo::ChannelInfoDeleter::~ChannelInfoDeleter() { | 225 ChannelMojo::ChannelInfoDeleter::~ChannelInfoDeleter() { |
| 222 } | 226 } |
| 223 | 227 |
| 224 void ChannelMojo::ChannelInfoDeleter::operator()( | 228 void ChannelMojo::ChannelInfoDeleter::operator()( |
| 225 mojo::embedder::ChannelInfo* ptr) const { | 229 mojo::embedder::ChannelInfo* ptr) const { |
| 226 if (base::ThreadTaskRunnerHandle::Get() == io_runner) { | 230 if (base::ThreadTaskRunnerHandle::Get() == io_runner) { |
| 227 mojo::embedder::DestroyChannelOnIOThread(ptr); | 231 mojo::embedder::DestroyChannelOnIOThread(ptr); |
| 228 } else { | 232 } else { |
| 229 io_runner->PostTask( | 233 io_runner->PostTask( |
| 230 FROM_HERE, base::Bind(&mojo::embedder::DestroyChannelOnIOThread, ptr)); | 234 FROM_HERE, base::Bind(&mojo::embedder::DestroyChannelOnIOThread, ptr)); |
| 231 } | 235 } |
| 232 } | 236 } |
| 233 | 237 #endif |
| 234 //------------------------------------------------------------------------------ | 238 //------------------------------------------------------------------------------ |
| 235 | 239 |
| 236 // static | 240 // static |
| 237 bool ChannelMojo::ShouldBeUsed() { | 241 bool ChannelMojo::ShouldBeUsed() { |
| 238 // TODO(rockot): Investigate performance bottlenecks and hopefully reenable | 242 // TODO(rockot): Investigate performance bottlenecks and hopefully reenable |
| 239 // this at some point. http://crbug.com/500019 | 243 // this at some point. http://crbug.com/500019 |
| 240 return false; | 244 return false; |
| 241 } | 245 } |
| 242 | 246 |
| 243 // static | 247 // static |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 } | 283 } |
| 280 | 284 |
| 281 ChannelMojo::ChannelMojo(scoped_refptr<base::TaskRunner> io_runner, | 285 ChannelMojo::ChannelMojo(scoped_refptr<base::TaskRunner> io_runner, |
| 282 const ChannelHandle& handle, | 286 const ChannelHandle& handle, |
| 283 Mode mode, | 287 Mode mode, |
| 284 Listener* listener, | 288 Listener* listener, |
| 285 AttachmentBroker* broker) | 289 AttachmentBroker* broker) |
| 286 : listener_(listener), | 290 : listener_(listener), |
| 287 peer_pid_(base::kNullProcessId), | 291 peer_pid_(base::kNullProcessId), |
| 288 io_runner_(io_runner), | 292 io_runner_(io_runner), |
| 293 #if !defined(USE_CHROME_EDK) |
| 289 channel_info_(nullptr, ChannelInfoDeleter(nullptr)), | 294 channel_info_(nullptr, ChannelInfoDeleter(nullptr)), |
| 295 #endif |
| 290 waiting_connect_(true), | 296 waiting_connect_(true), |
| 291 weak_factory_(this) { | 297 weak_factory_(this) { |
| 292 // Create MojoBootstrap after all members are set as it touches | 298 // Create MojoBootstrap after all members are set as it touches |
| 293 // ChannelMojo from a different thread. | 299 // ChannelMojo from a different thread. |
| 294 bootstrap_ = MojoBootstrap::Create(handle, mode, this, broker); | 300 bootstrap_ = MojoBootstrap::Create(handle, mode, this, broker); |
| 295 if (io_runner == base::MessageLoop::current()->task_runner()) { | 301 if (g_use_channel_on_io || |
| 302 io_runner == base::MessageLoop::current()->task_runner()) { |
| 296 InitOnIOThread(); | 303 InitOnIOThread(); |
| 297 } else { | 304 } else { |
| 298 io_runner->PostTask(FROM_HERE, base::Bind(&ChannelMojo::InitOnIOThread, | 305 io_runner->PostTask(FROM_HERE, base::Bind(&ChannelMojo::InitOnIOThread, |
| 299 base::Unretained(this))); | 306 base::Unretained(this))); |
| 300 } | 307 } |
| 301 } | 308 } |
| 302 | 309 |
| 303 ChannelMojo::~ChannelMojo() { | 310 ChannelMojo::~ChannelMojo() { |
| 304 Close(); | 311 Close(); |
| 305 } | 312 } |
| 306 | 313 |
| 307 void ChannelMojo::InitOnIOThread() { | 314 void ChannelMojo::InitOnIOThread() { |
| 308 ipc_support_.reset( | 315 ipc_support_.reset( |
| 309 new ScopedIPCSupport(base::MessageLoop::current()->task_runner())); | 316 new ScopedIPCSupport(base::MessageLoop::current()->task_runner())); |
| 310 } | 317 } |
| 311 | 318 |
| 319 #if !defined(USE_CHROME_EDK) |
| 312 void ChannelMojo::CreateMessagingPipe( | 320 void ChannelMojo::CreateMessagingPipe( |
| 313 mojo::embedder::ScopedPlatformHandle handle, | 321 mojo::embedder::ScopedPlatformHandle handle, |
| 314 const CreateMessagingPipeCallback& callback) { | 322 const CreateMessagingPipeCallback& callback) { |
| 315 auto return_callback = base::Bind(&ChannelMojo::OnMessagingPipeCreated, | 323 auto return_callback = base::Bind(&ChannelMojo::OnMessagingPipeCreated, |
| 316 weak_factory_.GetWeakPtr(), callback); | 324 weak_factory_.GetWeakPtr(), callback); |
| 317 if (base::ThreadTaskRunnerHandle::Get() == io_runner_) { | 325 if (g_use_channel_on_io || |
| 326 base::ThreadTaskRunnerHandle::Get() == io_runner_) { |
| 318 CreateMessagingPipeOnIOThread( | 327 CreateMessagingPipeOnIOThread( |
| 319 handle.Pass(), base::ThreadTaskRunnerHandle::Get(), return_callback); | 328 handle.Pass(), base::ThreadTaskRunnerHandle::Get(), return_callback); |
| 320 } else { | 329 } else { |
| 321 io_runner_->PostTask( | 330 io_runner_->PostTask( |
| 322 FROM_HERE, | 331 FROM_HERE, |
| 323 base::Bind(&ChannelMojo::CreateMessagingPipeOnIOThread, | 332 base::Bind(&ChannelMojo::CreateMessagingPipeOnIOThread, |
| 324 base::Passed(&handle), base::ThreadTaskRunnerHandle::Get(), | 333 base::Passed(&handle), base::ThreadTaskRunnerHandle::Get(), |
| 325 return_callback)); | 334 return_callback)); |
| 326 } | 335 } |
| 327 } | 336 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 344 | 353 |
| 345 void ChannelMojo::OnMessagingPipeCreated( | 354 void ChannelMojo::OnMessagingPipeCreated( |
| 346 const CreateMessagingPipeCallback& callback, | 355 const CreateMessagingPipeCallback& callback, |
| 347 mojo::ScopedMessagePipeHandle handle, | 356 mojo::ScopedMessagePipeHandle handle, |
| 348 mojo::embedder::ChannelInfo* channel_info) { | 357 mojo::embedder::ChannelInfo* channel_info) { |
| 349 DCHECK(!channel_info_.get()); | 358 DCHECK(!channel_info_.get()); |
| 350 channel_info_ = scoped_ptr<mojo::embedder::ChannelInfo, ChannelInfoDeleter>( | 359 channel_info_ = scoped_ptr<mojo::embedder::ChannelInfo, ChannelInfoDeleter>( |
| 351 channel_info, ChannelInfoDeleter(io_runner_)); | 360 channel_info, ChannelInfoDeleter(io_runner_)); |
| 352 callback.Run(handle.Pass()); | 361 callback.Run(handle.Pass()); |
| 353 } | 362 } |
| 363 #endif |
| 354 | 364 |
| 355 bool ChannelMojo::Connect() { | 365 bool ChannelMojo::Connect() { |
| 356 DCHECK(!message_reader_); | 366 DCHECK(!message_reader_); |
| 357 return bootstrap_->Connect(); | 367 return bootstrap_->Connect(); |
| 358 } | 368 } |
| 359 | 369 |
| 360 void ChannelMojo::Close() { | 370 void ChannelMojo::Close() { |
| 361 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> to_be_deleted; | 371 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> to_be_deleted; |
| 362 | 372 |
| 363 { | 373 { |
| 364 // |message_reader_| has to be cleared inside the lock, | 374 // |message_reader_| has to be cleared inside the lock, |
| 365 // but the instance has to be deleted outside. | 375 // but the instance has to be deleted outside. |
| 366 base::AutoLock l(lock_); | 376 base::AutoLock l(lock_); |
| 367 to_be_deleted = message_reader_.Pass(); | 377 to_be_deleted = message_reader_.Pass(); |
| 368 // We might Close() before we Connect(). | 378 // We might Close() before we Connect(). |
| 369 waiting_connect_ = false; | 379 waiting_connect_ = false; |
| 370 } | 380 } |
| 371 | 381 |
| 382 #if !defined(USE_CHROME_EDK) |
| 372 channel_info_.reset(); | 383 channel_info_.reset(); |
| 384 #endif |
| 373 ipc_support_.reset(); | 385 ipc_support_.reset(); |
| 374 to_be_deleted.reset(); | 386 to_be_deleted.reset(); |
| 375 } | 387 } |
| 376 | 388 |
| 377 void ChannelMojo::OnBootstrapError() { | 389 void ChannelMojo::OnBootstrapError() { |
| 378 listener_->OnChannelError(); | 390 listener_->OnChannelError(); |
| 379 } | 391 } |
| 380 | 392 |
| 381 namespace { | 393 namespace { |
| 382 | 394 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 if (!ok) { | 564 if (!ok) { |
| 553 LOG(ERROR) << "Failed to add new Mojo handle."; | 565 LOG(ERROR) << "Failed to add new Mojo handle."; |
| 554 return MOJO_RESULT_UNKNOWN; | 566 return MOJO_RESULT_UNKNOWN; |
| 555 } | 567 } |
| 556 } | 568 } |
| 557 | 569 |
| 558 return MOJO_RESULT_OK; | 570 return MOJO_RESULT_OK; |
| 559 } | 571 } |
| 560 | 572 |
| 561 } // namespace IPC | 573 } // namespace IPC |
| OLD | NEW |