Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: ipc/ipc_channel_mojo.cc

Issue 2493623002: Remove IPC::Endpoint. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_channel_mojo.h ('k') | ipc/ipc_channel_nacl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ipc_channel_mojo.h" 5 #include "ipc/ipc_channel_mojo.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 handle = reinterpret_cast<base::PlatformFile>(platform_handle.value); 228 handle = reinterpret_cast<base::PlatformFile>(platform_handle.value);
229 *attachment = new internal::HandleAttachmentWin( 229 *attachment = new internal::HandleAttachmentWin(
230 handle, internal::HandleAttachmentWin::FROM_WIRE); 230 handle, internal::HandleAttachmentWin::FROM_WIRE);
231 return MOJO_RESULT_OK; 231 return MOJO_RESULT_OK;
232 } 232 }
233 #endif // defined(OS_WIN) 233 #endif // defined(OS_WIN)
234 NOTREACHED(); 234 NOTREACHED();
235 return MOJO_RESULT_UNKNOWN; 235 return MOJO_RESULT_UNKNOWN;
236 } 236 }
237 237
238 base::ProcessId GetSelfPID() {
239 #if defined(OS_LINUX)
240 if (int global_pid = Channel::GetGlobalPid())
241 return global_pid;
242 #endif // OS_LINUX
243 #if defined(OS_NACL)
244 return -1;
245 #else
246 return base::GetCurrentProcId();
247 #endif // defined(OS_NACL)
248 }
249
238 } // namespace 250 } // namespace
239 251
240 //------------------------------------------------------------------------------ 252 //------------------------------------------------------------------------------
241 253
242 // static 254 // static
243 std::unique_ptr<ChannelMojo> ChannelMojo::Create( 255 std::unique_ptr<ChannelMojo> ChannelMojo::Create(
244 mojo::ScopedMessagePipeHandle handle, 256 mojo::ScopedMessagePipeHandle handle,
245 Mode mode, 257 Mode mode,
246 Listener* listener, 258 Listener* listener,
247 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { 259 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // this object, and that would be bad if we are called from Send(). Instead, 375 // this object, and that would be bad if we are called from Send(). Instead,
364 // we return false and hope the caller will close the pipe. If they do not, 376 // we return false and hope the caller will close the pipe. If they do not,
365 // the pipe will still be closed next time OnFileCanReadWithoutBlocking is 377 // the pipe will still be closed next time OnFileCanReadWithoutBlocking is
366 // called. 378 // called.
367 // 379 //
368 // With Mojo, there's no OnFileCanReadWithoutBlocking, but we expect the 380 // With Mojo, there's no OnFileCanReadWithoutBlocking, but we expect the
369 // pipe's connection error handler will be invoked in its place. 381 // pipe's connection error handler will be invoked in its place.
370 return message_reader_->Send(std::move(scoped_message)); 382 return message_reader_->Send(std::move(scoped_message));
371 } 383 }
372 384
373 base::ProcessId ChannelMojo::GetPeerPID() const {
374 if (!message_reader_)
375 return base::kNullProcessId;
376 return message_reader_->GetPeerPid();
377 }
378
379 base::ProcessId ChannelMojo::GetSelfPID() const {
380 #if defined(OS_LINUX)
381 if (int global_pid = GetGlobalPid())
382 return global_pid;
383 #endif // OS_LINUX
384 #if defined(OS_NACL)
385 return -1;
386 #else
387 return base::GetCurrentProcId();
388 #endif // defined(OS_NACL)
389 }
390
391 Channel::AssociatedInterfaceSupport* 385 Channel::AssociatedInterfaceSupport*
392 ChannelMojo::GetAssociatedInterfaceSupport() { return this; } 386 ChannelMojo::GetAssociatedInterfaceSupport() { return this; }
393 387
394 void ChannelMojo::OnPeerPidReceived() { 388 void ChannelMojo::OnPeerPidReceived(int32_t peer_pid) {
395 listener_->OnChannelConnected(static_cast<int32_t>(GetPeerPID())); 389 listener_->OnChannelConnected(peer_pid);
396 } 390 }
397 391
398 void ChannelMojo::OnMessageReceived(const Message& message) { 392 void ChannelMojo::OnMessageReceived(const Message& message) {
399 TRACE_EVENT2("ipc,toplevel", "ChannelMojo::OnMessageReceived", 393 TRACE_EVENT2("ipc,toplevel", "ChannelMojo::OnMessageReceived",
400 "class", IPC_MESSAGE_ID_CLASS(message.type()), 394 "class", IPC_MESSAGE_ID_CLASS(message.type()),
401 "line", IPC_MESSAGE_ID_LINE(message.type())); 395 "line", IPC_MESSAGE_ID_LINE(message.type()));
402 listener_->OnMessageReceived(message); 396 listener_->OnMessageReceived(message);
403 if (message.dispatch_error()) 397 if (message.dispatch_error())
404 listener_->OnBadMessageReceived(message); 398 listener_->OnBadMessageReceived(message);
405 } 399 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 473 }
480 474
481 void ChannelMojo::GetGenericRemoteAssociatedInterface( 475 void ChannelMojo::GetGenericRemoteAssociatedInterface(
482 const std::string& name, 476 const std::string& name,
483 mojo::ScopedInterfaceEndpointHandle handle) { 477 mojo::ScopedInterfaceEndpointHandle handle) {
484 if (message_reader_) 478 if (message_reader_)
485 message_reader_->GetRemoteInterface(name, std::move(handle)); 479 message_reader_->GetRemoteInterface(name, std::move(handle));
486 } 480 }
487 481
488 } // namespace IPC 482 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_mojo.h ('k') | ipc/ipc_channel_nacl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698