ipc_channel_common.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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
  3. // found in the LICENSE file.
  4. #include "base/threading/thread_task_runner_handle.h"
  5. #include "build/build_config.h"
  6. #include "ipc/ipc_channel.h"
  7. #include "ipc/ipc_channel_mojo.h"
  8. #include "mojo/public/cpp/bindings/lib/message_quota_checker.h"
  9. #include "mojo/public/cpp/system/message_pipe.h"
  10. namespace IPC {
  11. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  12. namespace {
  13. int g_global_pid = 0;
  14. }
  15. // static
  16. void Channel::SetGlobalPid(int pid) {
  17. g_global_pid = pid;
  18. }
  19. // static
  20. int Channel::GetGlobalPid() {
  21. return g_global_pid;
  22. }
  23. #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  24. // static
  25. std::unique_ptr<Channel> Channel::CreateClient(
  26. const IPC::ChannelHandle& channel_handle,
  27. Listener* listener,
  28. const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
  29. #if BUILDFLAG(IS_NACL)
  30. return Channel::Create(channel_handle, Channel::MODE_CLIENT, listener);
  31. #else
  32. DCHECK(channel_handle.is_mojo_channel_handle());
  33. return ChannelMojo::Create(
  34. mojo::ScopedMessagePipeHandle(channel_handle.mojo_handle),
  35. Channel::MODE_CLIENT, listener, ipc_task_runner,
  36. base::ThreadTaskRunnerHandle::Get(),
  37. mojo::internal::MessageQuotaChecker::MaybeCreate());
  38. #endif
  39. }
  40. // static
  41. std::unique_ptr<Channel> Channel::CreateServer(
  42. const IPC::ChannelHandle& channel_handle,
  43. Listener* listener,
  44. const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
  45. #if BUILDFLAG(IS_NACL)
  46. return Channel::Create(channel_handle, Channel::MODE_SERVER, listener);
  47. #else
  48. DCHECK(channel_handle.is_mojo_channel_handle());
  49. return ChannelMojo::Create(
  50. mojo::ScopedMessagePipeHandle(channel_handle.mojo_handle),
  51. Channel::MODE_SERVER, listener, ipc_task_runner,
  52. base::ThreadTaskRunnerHandle::Get(),
  53. mojo::internal::MessageQuotaChecker::MaybeCreate());
  54. #endif
  55. }
  56. Channel::~Channel() = default;
  57. Channel::AssociatedInterfaceSupport* Channel::GetAssociatedInterfaceSupport() {
  58. return nullptr;
  59. }
  60. void Channel::Pause() { NOTREACHED(); }
  61. void Channel::Unpause(bool flush) { NOTREACHED(); }
  62. void Channel::Flush() { NOTREACHED(); }
  63. void Channel::WillConnect() {
  64. did_start_connect_ = true;
  65. }
  66. } // namespace IPC