backport_1081874.patch 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Thu, 4 Oct 2018 14:57:02 -0700
  4. Subject: fix: data race on NodeChannel destruction
  5. [1081874] [High] [CVE-2020-6575]: Double free on NodeChannel
  6. Backport https://chromium.googlesource.com/chromium/src/+/5e61913985df0cc621bf72f7fa75e76759ffde15.
  7. diff --git a/mojo/core/BUILD.gn b/mojo/core/BUILD.gn
  8. index e6fcb96256f6fdb867a362588547a7829f28efe8..6282eed9158c691a9ca49d1ec9a57cedc4392741 100644
  9. --- a/mojo/core/BUILD.gn
  10. +++ b/mojo/core/BUILD.gn
  11. @@ -18,6 +18,7 @@ component("embedder_internal") {
  12. ":test_sources",
  13. "//mojo:*",
  14. "//mojo/core/embedder",
  15. + "//mojo/core/test:test_support",
  16. ]
  17. }
  18. @@ -57,6 +58,7 @@ template("core_impl_source_set") {
  19. "handle_table.h",
  20. "invitation_dispatcher.h",
  21. "message_pipe_dispatcher.h",
  22. + "node_channel.h",
  23. "node_controller.h",
  24. "options_validation.h",
  25. "platform_handle_dispatcher.h",
  26. @@ -86,7 +88,6 @@ template("core_impl_source_set") {
  27. "invitation_dispatcher.cc",
  28. "message_pipe_dispatcher.cc",
  29. "node_channel.cc",
  30. - "node_channel.h",
  31. "node_controller.cc",
  32. "platform_handle_dispatcher.cc",
  33. "platform_handle_in_transit.cc",
  34. @@ -289,6 +290,7 @@ source_set("test_sources") {
  35. "handle_table_unittest.cc",
  36. "message_pipe_unittest.cc",
  37. "message_unittest.cc",
  38. + "node_channel_unittest.cc",
  39. "options_validation_unittest.cc",
  40. "platform_handle_dispatcher_unittest.cc",
  41. "quota_unittest.cc",
  42. @@ -387,6 +389,7 @@ fuzzer_test("mojo_core_node_channel_fuzzer") {
  43. deps = [
  44. ":core_impl_for_fuzzers",
  45. "//base",
  46. + "//mojo/core/test:test_support",
  47. "//mojo/public/cpp/platform",
  48. ]
  49. }
  50. diff --git a/mojo/core/embedder/embedder.cc b/mojo/core/embedder/embedder.cc
  51. index ec68e37d09888f672759f79961e3e6e4d18f0c5c..f70c73be4df529cce09cb503dfce28f2a04e7e1a 100644
  52. --- a/mojo/core/embedder/embedder.cc
  53. +++ b/mojo/core/embedder/embedder.cc
  54. @@ -35,7 +35,7 @@ void SetDefaultProcessErrorCallback(ProcessErrorCallback callback) {
  55. Core::Get()->SetDefaultProcessErrorCallback(std::move(callback));
  56. }
  57. -scoped_refptr<base::TaskRunner> GetIOTaskRunner() {
  58. +scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() {
  59. return Core::Get()->GetNodeController()->io_task_runner();
  60. }
  61. diff --git a/mojo/core/embedder/embedder.h b/mojo/core/embedder/embedder.h
  62. index 5d65400987728940a296ba2a84d40158f52d6d34..96dc44c0a78e0e6cb6e5aa511bd2fd4f1252cf16 100644
  63. --- a/mojo/core/embedder/embedder.h
  64. +++ b/mojo/core/embedder/embedder.h
  65. @@ -13,7 +13,7 @@
  66. #include "base/component_export.h"
  67. #include "base/memory/ref_counted.h"
  68. #include "base/process/process_handle.h"
  69. -#include "base/task_runner.h"
  70. +#include "base/single_thread_task_runner.h"
  71. #include "build/build_config.h"
  72. #include "mojo/core/embedder/configuration.h"
  73. @@ -42,9 +42,10 @@ void SetDefaultProcessErrorCallback(ProcessErrorCallback callback);
  74. // Initialialization/shutdown for interprocess communication (IPC) -------------
  75. -// Retrieves the TaskRunner used for IPC I/O, as set by ScopedIPCSupport.
  76. +// Retrieves the SequencedTaskRunner used for IPC I/O, as set by
  77. +// ScopedIPCSupport.
  78. COMPONENT_EXPORT(MOJO_CORE_EMBEDDER)
  79. -scoped_refptr<base::TaskRunner> GetIOTaskRunner();
  80. +scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner();
  81. } // namespace core
  82. } // namespace mojo
  83. diff --git a/mojo/core/node_channel.cc b/mojo/core/node_channel.cc
  84. index e898b044286e019b5e423b941502030ce3094582..061ea1026e95d1b1f80a762ce377aebdd97e1b42 100644
  85. --- a/mojo/core/node_channel.cc
  86. +++ b/mojo/core/node_channel.cc
  87. @@ -228,7 +228,7 @@ void NodeChannel::NotifyBadMessage(const std::string& error) {
  88. }
  89. void NodeChannel::SetRemoteProcessHandle(ScopedProcessHandle process_handle) {
  90. - DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
  91. + DCHECK(owning_task_runner()->RunsTasksInCurrentSequence());
  92. {
  93. base::AutoLock lock(channel_lock_);
  94. if (channel_)
  95. @@ -253,7 +253,7 @@ ScopedProcessHandle NodeChannel::CloneRemoteProcessHandle() {
  96. }
  97. void NodeChannel::SetRemoteNodeName(const ports::NodeName& name) {
  98. - DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
  99. + DCHECK(owning_task_runner()->RunsTasksInCurrentSequence());
  100. remote_node_name_ = name;
  101. }
  102. @@ -468,15 +468,15 @@ NodeChannel::NodeChannel(
  103. Channel::HandlePolicy channel_handle_policy,
  104. scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
  105. const ProcessErrorCallback& process_error_callback)
  106. - : delegate_(delegate),
  107. - io_task_runner_(io_task_runner),
  108. + : base::RefCountedDeleteOnSequence<NodeChannel>(io_task_runner),
  109. + delegate_(delegate),
  110. process_error_callback_(process_error_callback)
  111. #if !defined(OS_NACL_SFI)
  112. ,
  113. channel_(Channel::Create(this,
  114. std::move(connection_params),
  115. channel_handle_policy,
  116. - io_task_runner_))
  117. + std::move(io_task_runner)))
  118. #endif
  119. {
  120. }
  121. @@ -499,15 +499,10 @@ void NodeChannel::CreateAndBindLocalBrokerHost(
  122. void NodeChannel::OnChannelMessage(const void* payload,
  123. size_t payload_size,
  124. std::vector<PlatformHandle> handles) {
  125. - DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
  126. + DCHECK(owning_task_runner()->RunsTasksInCurrentSequence());
  127. RequestContext request_context(RequestContext::Source::SYSTEM);
  128. - // Ensure this NodeChannel stays alive through the extent of this method. The
  129. - // delegate may have the only other reference to this object and it may choose
  130. - // to drop it here in response to, e.g., a malformed message.
  131. - scoped_refptr<NodeChannel> keepalive = this;
  132. -
  133. if (payload_size <= sizeof(Header)) {
  134. delegate_->OnChannelError(remote_node_name_, this);
  135. return;
  136. @@ -739,7 +734,7 @@ void NodeChannel::OnChannelMessage(const void* payload,
  137. }
  138. void NodeChannel::OnChannelError(Channel::Error error) {
  139. - DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
  140. + DCHECK(owning_task_runner()->RunsTasksInCurrentSequence());
  141. RequestContext request_context(RequestContext::Source::SYSTEM);
  142. diff --git a/mojo/core/node_channel.h b/mojo/core/node_channel.h
  143. index ea91f927049befa258884b13e7f7966c09518687..04501da0fb6cd36df1b332135282104dd442b41e 100644
  144. --- a/mojo/core/node_channel.h
  145. +++ b/mojo/core/node_channel.h
  146. @@ -11,7 +11,7 @@
  147. #include "base/callback.h"
  148. #include "base/containers/queue.h"
  149. #include "base/macros.h"
  150. -#include "base/memory/ref_counted.h"
  151. +#include "base/memory/ref_counted_delete_on_sequence.h"
  152. #include "base/process/process_handle.h"
  153. #include "base/single_thread_task_runner.h"
  154. #include "base/synchronization/lock.h"
  155. @@ -21,13 +21,15 @@
  156. #include "mojo/core/embedder/process_error_callback.h"
  157. #include "mojo/core/ports/name.h"
  158. #include "mojo/core/scoped_process_handle.h"
  159. +#include "mojo/core/system_impl_export.h"
  160. namespace mojo {
  161. namespace core {
  162. // Wraps a Channel to send and receive Node control messages.
  163. -class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>,
  164. - public Channel::Delegate {
  165. +class MOJO_SYSTEM_IMPL_EXPORT NodeChannel
  166. + : public base::RefCountedDeleteOnSequence<NodeChannel>,
  167. + public Channel::Delegate {
  168. public:
  169. class Delegate {
  170. public:
  171. @@ -92,8 +94,6 @@ class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>,
  172. void** data,
  173. size_t* num_data_bytes);
  174. - Channel* channel() const { return channel_.get(); }
  175. -
  176. // Start receiving messages.
  177. void Start();
  178. @@ -155,7 +155,8 @@ class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>,
  179. #endif
  180. private:
  181. - friend class base::RefCountedThreadSafe<NodeChannel>;
  182. + friend class base::RefCountedDeleteOnSequence<NodeChannel>;
  183. + friend class base::DeleteHelper<NodeChannel>;
  184. using PendingMessageQueue = base::queue<Channel::MessagePtr>;
  185. using PendingRelayMessageQueue =
  186. @@ -181,13 +182,12 @@ class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>,
  187. void WriteChannelMessage(Channel::MessagePtr message);
  188. Delegate* const delegate_;
  189. - const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
  190. const ProcessErrorCallback process_error_callback_;
  191. base::Lock channel_lock_;
  192. - scoped_refptr<Channel> channel_;
  193. + scoped_refptr<Channel> channel_ GUARDED_BY(channel_lock_);
  194. - // Must only be accessed from |io_task_runner_|'s thread.
  195. + // Must only be accessed from the owning task runner's thread.
  196. ports::NodeName remote_node_name_;
  197. base::Lock remote_process_handle_lock_;
  198. diff --git a/mojo/core/node_channel_fuzzer.cc b/mojo/core/node_channel_fuzzer.cc
  199. index 99047c000dbe6be90f1d28b4b6817e608f9853a6..54fe757e0dec8aa138af96aa1a0afe596563c26c 100644
  200. --- a/mojo/core/node_channel_fuzzer.cc
  201. +++ b/mojo/core/node_channel_fuzzer.cc
  202. @@ -14,6 +14,7 @@
  203. #include "mojo/core/connection_params.h"
  204. #include "mojo/core/entrypoints.h"
  205. #include "mojo/core/node_channel.h" // nogncheck
  206. +#include "mojo/core/test/mock_node_channel_delegate.h"
  207. #include "mojo/public/cpp/platform/platform_channel.h"
  208. #if defined(OS_WIN)
  209. @@ -24,60 +25,6 @@ using mojo::core::Channel;
  210. using mojo::core::ConnectionParams;
  211. using mojo::core::ports::NodeName;
  212. -// Implementation of NodeChannel::Delegate which does nothing. All of the
  213. -// interesting NodeChannel control message message parsing is done by
  214. -// NodeChannel by the time any of the delegate methods are invoked, so there's
  215. -// no need for this to do any work.
  216. -class FakeNodeChannelDelegate : public mojo::core::NodeChannel::Delegate {
  217. - public:
  218. - FakeNodeChannelDelegate() = default;
  219. - ~FakeNodeChannelDelegate() override = default;
  220. -
  221. - void OnAcceptInvitee(const NodeName& from_node,
  222. - const NodeName& inviter_name,
  223. - const NodeName& token) override {}
  224. - void OnAcceptInvitation(const NodeName& from_node,
  225. - const NodeName& token,
  226. - const NodeName& invitee_name) override {}
  227. - void OnAddBrokerClient(const NodeName& from_node,
  228. - const NodeName& client_name,
  229. - base::ProcessHandle process_handle) override {}
  230. - void OnBrokerClientAdded(const NodeName& from_node,
  231. - const NodeName& client_name,
  232. - mojo::PlatformHandle broker_channel) override {}
  233. - void OnAcceptBrokerClient(const NodeName& from_node,
  234. - const NodeName& broker_name,
  235. - mojo::PlatformHandle broker_channel) override {}
  236. - void OnEventMessage(const NodeName& from_node,
  237. - Channel::MessagePtr message) override {}
  238. - void OnRequestPortMerge(
  239. - const NodeName& from_node,
  240. - const mojo::core::ports::PortName& connector_port_name,
  241. - const std::string& token) override {}
  242. - void OnRequestIntroduction(const NodeName& from_node,
  243. - const NodeName& name) override {}
  244. - void OnIntroduce(const NodeName& from_node,
  245. - const NodeName& name,
  246. - mojo::PlatformHandle channel_handle) override {}
  247. - void OnBroadcast(const NodeName& from_node,
  248. - Channel::MessagePtr message) override {}
  249. -#if defined(OS_WIN)
  250. - void OnRelayEventMessage(const NodeName& from_node,
  251. - base::ProcessHandle from_process,
  252. - const NodeName& destination,
  253. - Channel::MessagePtr message) override {}
  254. - void OnEventMessageFromRelay(const NodeName& from_node,
  255. - const NodeName& source_node,
  256. - Channel::MessagePtr message) override {}
  257. -#endif
  258. - void OnAcceptPeer(const NodeName& from_node,
  259. - const NodeName& token,
  260. - const NodeName& peer_name,
  261. - const mojo::core::ports::PortName& port_name) override {}
  262. - void OnChannelError(const NodeName& node,
  263. - mojo::core::NodeChannel* channel) override {}
  264. -};
  265. -
  266. // A fake delegate for the sending Channel endpoint. The sending Channel is not
  267. // being fuzzed and won't receive any interesting messages, so this doesn't need
  268. // to do anything.
  269. @@ -109,7 +56,7 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) {
  270. // used to carry messages between processes.
  271. mojo::PlatformChannel channel;
  272. - FakeNodeChannelDelegate receiver_delegate;
  273. + mojo::core::MockNodeChannelDelegate receiver_delegate;
  274. auto receiver = mojo::core::NodeChannel::Create(
  275. &receiver_delegate, ConnectionParams(channel.TakeLocalEndpoint()),
  276. Channel::HandlePolicy::kRejectHandles,
  277. diff --git a/mojo/core/node_channel_unittest.cc b/mojo/core/node_channel_unittest.cc
  278. new file mode 100644
  279. index 0000000000000000000000000000000000000000..13c46f13fea6342316534a7a843debbf7586108d
  280. --- /dev/null
  281. +++ b/mojo/core/node_channel_unittest.cc
  282. @@ -0,0 +1,72 @@
  283. +// Copyright 2020 The Chromium Authors. All rights reserved.
  284. +// Use of this source code is governed by a BSD-style license that can be
  285. +// found in the LICENSE file.
  286. +
  287. +#include "mojo/core/node_channel.h"
  288. +
  289. +#include "base/bind_helpers.h"
  290. +#include "base/memory/scoped_refptr.h"
  291. +#include "base/message_loop/message_pump_type.h"
  292. +#include "base/test/task_environment.h"
  293. +#include "base/threading/thread.h"
  294. +#include "mojo/core/embedder/embedder.h"
  295. +#include "mojo/core/test/mock_node_channel_delegate.h"
  296. +#include "mojo/public/cpp/platform/platform_channel.h"
  297. +#include "mojo/public/cpp/platform/platform_channel_endpoint.h"
  298. +#include "testing/gtest/include/gtest/gtest.h"
  299. +
  300. +namespace mojo {
  301. +namespace core {
  302. +namespace {
  303. +
  304. +using NodeChannelTest = testing::Test;
  305. +using ports::NodeName;
  306. +
  307. +scoped_refptr<NodeChannel> CreateNodeChannel(NodeChannel::Delegate* delegate,
  308. + PlatformChannelEndpoint endpoint) {
  309. + return NodeChannel::Create(delegate, ConnectionParams(std::move(endpoint)),
  310. + Channel::HandlePolicy::kAcceptHandles,
  311. + GetIOTaskRunner(), base::NullCallback());
  312. +}
  313. +
  314. +TEST_F(NodeChannelTest, DestructionIsSafe) {
  315. + // Regression test for https://crbug.com/1081874.
  316. + base::test::TaskEnvironment task_environment;
  317. +
  318. + PlatformChannel channel;
  319. + MockNodeChannelDelegate local_delegate;
  320. + auto local_channel =
  321. + CreateNodeChannel(&local_delegate, channel.TakeLocalEndpoint());
  322. + local_channel->Start();
  323. + MockNodeChannelDelegate remote_delegate;
  324. + auto remote_channel =
  325. + CreateNodeChannel(&remote_delegate, channel.TakeRemoteEndpoint());
  326. + remote_channel->Start();
  327. +
  328. + // Verify end-to-end operation
  329. + const NodeName kRemoteNodeName{123, 456};
  330. + const NodeName kToken{987, 654};
  331. + base::RunLoop loop;
  332. + EXPECT_CALL(local_delegate,
  333. + OnAcceptInvitee(ports::kInvalidNodeName, kRemoteNodeName, kToken))
  334. + .WillRepeatedly([&] { loop.Quit(); });
  335. + remote_channel->AcceptInvitee(kRemoteNodeName, kToken);
  336. + loop.Run();
  337. +
  338. + // Now send another message to the local endpoint but tear it down
  339. + // immediately. This will race with the message being received on the IO
  340. + // thread, and although the corresponding delegate call may or may not
  341. + // dispatch as a result, the race should still be memory-safe.
  342. + remote_channel->AcceptInvitee(kRemoteNodeName, kToken);
  343. +
  344. + base::RunLoop error_loop;
  345. + EXPECT_CALL(remote_delegate, OnChannelError).WillOnce([&] {
  346. + error_loop.Quit();
  347. + });
  348. + local_channel.reset();
  349. + error_loop.Run();
  350. +}
  351. +
  352. +} // namespace
  353. +} // namespace core
  354. +} // namespace mojo
  355. diff --git a/mojo/core/test/BUILD.gn b/mojo/core/test/BUILD.gn
  356. index 1abadfc503d5176d2af1dcecfde153f17488546d..9429c61853059e10ca2430ad79ec8d9a39d90906 100644
  357. --- a/mojo/core/test/BUILD.gn
  358. +++ b/mojo/core/test/BUILD.gn
  359. @@ -7,6 +7,8 @@ import("//third_party/protobuf/proto_library.gni")
  360. static_library("test_support") {
  361. testonly = true
  362. sources = [
  363. + "mock_node_channel_delegate.cc",
  364. + "mock_node_channel_delegate.h",
  365. "mojo_test_base.cc",
  366. "mojo_test_base.h",
  367. "test_utils.h",
  368. @@ -27,8 +29,10 @@ static_library("test_support") {
  369. public_deps = [
  370. "//base",
  371. "//base/test:test_support",
  372. + "//mojo/core:embedder_internal",
  373. "//mojo/core/embedder",
  374. "//mojo/public/cpp/system",
  375. + "//testing/gmock",
  376. "//testing/gtest",
  377. ]
  378. }
  379. diff --git a/mojo/core/test/mock_node_channel_delegate.cc b/mojo/core/test/mock_node_channel_delegate.cc
  380. new file mode 100644
  381. index 0000000000000000000000000000000000000000..d257c3e1dc03857f91e94807328a0dc176f332f4
  382. --- /dev/null
  383. +++ b/mojo/core/test/mock_node_channel_delegate.cc
  384. @@ -0,0 +1,15 @@
  385. +// Copyright 2020 The Chromium Authors. All rights reserved.
  386. +// Use of this source code is governed by a BSD-style license that can be
  387. +// found in the LICENSE file.
  388. +
  389. +#include "mojo/core/test/mock_node_channel_delegate.h"
  390. +
  391. +namespace mojo {
  392. +namespace core {
  393. +
  394. +MockNodeChannelDelegate::MockNodeChannelDelegate() = default;
  395. +
  396. +MockNodeChannelDelegate::~MockNodeChannelDelegate() = default;
  397. +
  398. +} // namespace core
  399. +} // namespace mojo
  400. diff --git a/mojo/core/test/mock_node_channel_delegate.h b/mojo/core/test/mock_node_channel_delegate.h
  401. new file mode 100644
  402. index 0000000000000000000000000000000000000000..06ca96857b9472682d577a802c68a56a7af0aacd
  403. --- /dev/null
  404. +++ b/mojo/core/test/mock_node_channel_delegate.h
  405. @@ -0,0 +1,114 @@
  406. +// Copyright 2020 The Chromium Authors. All rights reserved.
  407. +// Use of this source code is governed by a BSD-style license that can be
  408. +// found in the LICENSE file.
  409. +
  410. +#ifndef MOJO_CORE_TEST_MOCK_NODE_CHANNEL_DELEGATE_H_
  411. +#define MOJO_CORE_TEST_MOCK_NODE_CHANNEL_DELEGATE_H_
  412. +
  413. +#include "build/build_config.h"
  414. +#include "mojo/core/node_channel.h"
  415. +#include "testing/gmock/include/gmock/gmock.h"
  416. +
  417. +namespace mojo {
  418. +namespace core {
  419. +
  420. +// A NodeChannel Delegate implementation which can be used by NodeChannel unit
  421. +// tests and fuzzers.
  422. +class MockNodeChannelDelegate
  423. + : public testing::NiceMock<NodeChannel::Delegate> {
  424. + public:
  425. + using NodeName = ports::NodeName;
  426. + using PortName = ports::PortName;
  427. +
  428. + MockNodeChannelDelegate();
  429. + MockNodeChannelDelegate(const MockNodeChannelDelegate&) = delete;
  430. + MockNodeChannelDelegate& operator=(const MockNodeChannelDelegate&) = delete;
  431. + ~MockNodeChannelDelegate() override;
  432. +
  433. + // testing::NiceMock<NodeChannel::Delegate> implementation:
  434. + MOCK_METHOD(void,
  435. + OnAcceptInvitee,
  436. + (const NodeName& from_node,
  437. + const NodeName& inviter_name,
  438. + const NodeName& token),
  439. + (override));
  440. + MOCK_METHOD(void,
  441. + OnAcceptInvitation,
  442. + (const NodeName& from_node,
  443. + const NodeName& token,
  444. + const NodeName& invitee_name),
  445. + (override));
  446. + MOCK_METHOD(void,
  447. + OnAddBrokerClient,
  448. + (const NodeName& from_node,
  449. + const NodeName& client_name,
  450. + base::ProcessHandle process_handle),
  451. + (override));
  452. + MOCK_METHOD(void,
  453. + OnBrokerClientAdded,
  454. + (const NodeName& from_node,
  455. + const NodeName& client_name,
  456. + PlatformHandle broker_channel),
  457. + (override));
  458. + MOCK_METHOD(void,
  459. + OnAcceptBrokerClient,
  460. + (const NodeName& from_node,
  461. + const NodeName& broker_name,
  462. + PlatformHandle broker_channel),
  463. + (override));
  464. + MOCK_METHOD(void,
  465. + OnEventMessage,
  466. + (const NodeName& from_node, Channel::MessagePtr message),
  467. + (override));
  468. + MOCK_METHOD(void,
  469. + OnRequestPortMerge,
  470. + (const NodeName& from_node,
  471. + const PortName& connector_port_name,
  472. + const std::string& token),
  473. + (override));
  474. + MOCK_METHOD(void,
  475. + OnRequestIntroduction,
  476. + (const NodeName& from_node, const NodeName& name),
  477. + (override));
  478. + MOCK_METHOD(void,
  479. + OnIntroduce,
  480. + (const NodeName& from_node,
  481. + const NodeName& name,
  482. + PlatformHandle channel_handle),
  483. + (override));
  484. + MOCK_METHOD(void,
  485. + OnBroadcast,
  486. + (const NodeName& from_node, Channel::MessagePtr message),
  487. + (override));
  488. +#if defined(OS_WIN)
  489. + MOCK_METHOD(void,
  490. + OnRelayEventMessage,
  491. + (const NodeName& from_node,
  492. + base::ProcessHandle from_process,
  493. + const NodeName& destination,
  494. + Channel::MessagePtr message),
  495. + (override));
  496. + MOCK_METHOD(void,
  497. + OnEventMessageFromRelay,
  498. + (const NodeName& from_node,
  499. + const NodeName& source_node,
  500. + Channel::MessagePtr message),
  501. + (override));
  502. +#endif
  503. + MOCK_METHOD(void,
  504. + OnAcceptPeer,
  505. + (const NodeName& from_node,
  506. + const NodeName& token,
  507. + const NodeName& peer_name,
  508. + const PortName& port_name),
  509. + (override));
  510. + MOCK_METHOD(void,
  511. + OnChannelError,
  512. + (const NodeName& node, NodeChannel* channel),
  513. + (override));
  514. +};
  515. +
  516. +} // namespace core
  517. +} // namespace mojo
  518. +
  519. +#endif // MOJO_CORE_TEST_MOCK_NODE_CHANNEL_DELEGATE_H_