OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_sync_channel.h" | 5 #include "ipc/ipc_sync_channel.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 Send(reply_msg); | 148 Send(reply_msg); |
149 } | 149 } |
150 | 150 |
151 virtual void OnNestedTestMsg(Message* reply_msg) { | 151 virtual void OnNestedTestMsg(Message* reply_msg) { |
152 NOTREACHED(); | 152 NOTREACHED(); |
153 } | 153 } |
154 | 154 |
155 virtual SyncChannel* CreateChannel() { | 155 virtual SyncChannel* CreateChannel() { |
156 scoped_ptr<SyncChannel> channel = SyncChannel::Create( | 156 scoped_ptr<SyncChannel> channel = SyncChannel::Create( |
157 channel_name_, mode_, this, ipc_thread_.task_runner().get(), true, | 157 channel_name_, mode_, this, ipc_thread_.task_runner().get(), true, |
158 &shutdown_event_, nullptr); | 158 &shutdown_event_); |
159 return channel.release(); | 159 return channel.release(); |
160 } | 160 } |
161 | 161 |
162 base::Thread* ListenerThread() { | 162 base::Thread* ListenerThread() { |
163 return overrided_thread_ ? overrided_thread_ : &listener_thread_; | 163 return overrided_thread_ ? overrided_thread_ : &listener_thread_; |
164 } | 164 } |
165 | 165 |
166 const base::Thread& ipc_thread() const { return ipc_thread_; } | 166 const base::Thread& ipc_thread() const { return ipc_thread_; } |
167 | 167 |
168 private: | 168 private: |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 325 |
326 void Run() override { | 326 void Run() override { |
327 SendAnswerToLife(false, true); | 327 SendAnswerToLife(false, true); |
328 Done(); | 328 Done(); |
329 } | 329 } |
330 | 330 |
331 SyncChannel* CreateChannel() override { | 331 SyncChannel* CreateChannel() override { |
332 SyncChannel* channel = | 332 SyncChannel* channel = |
333 SyncChannel::Create(channel_name(), mode(), this, | 333 SyncChannel::Create(channel_name(), mode(), this, |
334 ipc_thread().task_runner().get(), create_pipe_now_, | 334 ipc_thread().task_runner().get(), create_pipe_now_, |
335 shutdown_event(), nullptr).release(); | 335 shutdown_event()) |
| 336 .release(); |
336 return channel; | 337 return channel; |
337 } | 338 } |
338 | 339 |
339 bool create_pipe_now_; | 340 bool create_pipe_now_; |
340 }; | 341 }; |
341 | 342 |
342 class TwoStepClient : public Worker { | 343 class TwoStepClient : public Worker { |
343 public: | 344 public: |
344 TwoStepClient(bool create_pipe_now) | 345 TwoStepClient(bool create_pipe_now) |
345 : Worker(Channel::MODE_CLIENT, "simple_client"), | 346 : Worker(Channel::MODE_CLIENT, "simple_client"), |
346 create_pipe_now_(create_pipe_now) { } | 347 create_pipe_now_(create_pipe_now) { } |
347 | 348 |
348 void OnAnswer(int* answer) override { | 349 void OnAnswer(int* answer) override { |
349 *answer = 42; | 350 *answer = 42; |
350 Done(); | 351 Done(); |
351 } | 352 } |
352 | 353 |
353 SyncChannel* CreateChannel() override { | 354 SyncChannel* CreateChannel() override { |
354 SyncChannel* channel = | 355 SyncChannel* channel = |
355 SyncChannel::Create(channel_name(), mode(), this, | 356 SyncChannel::Create(channel_name(), mode(), this, |
356 ipc_thread().task_runner().get(), create_pipe_now_, | 357 ipc_thread().task_runner().get(), create_pipe_now_, |
357 shutdown_event(), nullptr).release(); | 358 shutdown_event()) |
| 359 .release(); |
358 return channel; | 360 return channel; |
359 } | 361 } |
360 | 362 |
361 bool create_pipe_now_; | 363 bool create_pipe_now_; |
362 }; | 364 }; |
363 | 365 |
364 void TwoStep(bool create_server_pipe_now, bool create_client_pipe_now) { | 366 void TwoStep(bool create_server_pipe_now, bool create_client_pipe_now) { |
365 std::vector<Worker*> workers; | 367 std::vector<Worker*> workers; |
366 workers.push_back(new TwoStepServer(create_server_pipe_now)); | 368 workers.push_back(new TwoStepServer(create_server_pipe_now)); |
367 workers.push_back(new TwoStepClient(create_client_pipe_now)); | 369 workers.push_back(new TwoStepClient(create_client_pipe_now)); |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1)); | 1154 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1)); |
1153 sent_ping_event_->Wait(); | 1155 sent_ping_event_->Wait(); |
1154 Send(new SyncChannelTestMsg_NoArgs); | 1156 Send(new SyncChannelTestMsg_NoArgs); |
1155 if (ping_ == 1) | 1157 if (ping_ == 1) |
1156 ++*success_; | 1158 ++*success_; |
1157 else | 1159 else |
1158 LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; | 1160 LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; |
1159 | 1161 |
1160 non_restricted_channel_ = SyncChannel::Create( | 1162 non_restricted_channel_ = SyncChannel::Create( |
1161 "non_restricted_channel", IPC::Channel::MODE_CLIENT, this, | 1163 "non_restricted_channel", IPC::Channel::MODE_CLIENT, this, |
1162 ipc_thread().task_runner().get(), true, shutdown_event(), nullptr); | 1164 ipc_thread().task_runner().get(), true, shutdown_event()); |
1163 | 1165 |
1164 server_->ListenerThread()->task_runner()->PostTask( | 1166 server_->ListenerThread()->task_runner()->PostTask( |
1165 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 2)); | 1167 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 2)); |
1166 sent_ping_event_->Wait(); | 1168 sent_ping_event_->Wait(); |
1167 // Check that the incoming message is *not* dispatched when sending on the | 1169 // Check that the incoming message is *not* dispatched when sending on the |
1168 // non restricted channel. | 1170 // non restricted channel. |
1169 // TODO(piman): there is a possibility of a false positive race condition | 1171 // TODO(piman): there is a possibility of a false positive race condition |
1170 // here, if the message that was posted on the server-side end of the pipe | 1172 // here, if the message that was posted on the server-side end of the pipe |
1171 // is not visible yet on the client side, but I don't know how to solve this | 1173 // is not visible yet on the client side, but I don't know how to solve this |
1172 // without hooking into the internals of SyncChannel. I haven't seen it in | 1174 // without hooking into the internals of SyncChannel. I haven't seen it in |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 Done(); | 1541 Done(); |
1540 } | 1542 } |
1541 | 1543 |
1542 void Run() override { | 1544 void Run() override { |
1543 channel()->SetRestrictDispatchChannelGroup(group_); | 1545 channel()->SetRestrictDispatchChannelGroup(group_); |
1544 if (is_first()) | 1546 if (is_first()) |
1545 event1_->Signal(); | 1547 event1_->Signal(); |
1546 event2_->Wait(); | 1548 event2_->Wait(); |
1547 other_channel_ = SyncChannel::Create( | 1549 other_channel_ = SyncChannel::Create( |
1548 other_channel_name_, IPC::Channel::MODE_CLIENT, this, | 1550 other_channel_name_, IPC::Channel::MODE_CLIENT, this, |
1549 ipc_thread().task_runner().get(), true, shutdown_event(), nullptr); | 1551 ipc_thread().task_runner().get(), true, shutdown_event()); |
1550 other_channel_->SetRestrictDispatchChannelGroup(group_); | 1552 other_channel_->SetRestrictDispatchChannelGroup(group_); |
1551 if (!is_first()) { | 1553 if (!is_first()) { |
1552 event1_->Signal(); | 1554 event1_->Signal(); |
1553 return; | 1555 return; |
1554 } | 1556 } |
1555 *success_ = 0; | 1557 *success_ = 0; |
1556 int value = 0; | 1558 int value = 0; |
1557 OnPingTTL(3, &value); | 1559 OnPingTTL(3, &value); |
1558 *success_ += (value == 3); | 1560 *success_ += (value == 3); |
1559 OnPingTTL(4, &value); | 1561 OnPingTTL(4, &value); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 | 1623 |
1622 class ReentrantReplyServer1 : public Worker { | 1624 class ReentrantReplyServer1 : public Worker { |
1623 public: | 1625 public: |
1624 ReentrantReplyServer1(WaitableEvent* server_ready) | 1626 ReentrantReplyServer1(WaitableEvent* server_ready) |
1625 : Worker("reentrant_reply1", Channel::MODE_SERVER), | 1627 : Worker("reentrant_reply1", Channel::MODE_SERVER), |
1626 server_ready_(server_ready) { } | 1628 server_ready_(server_ready) { } |
1627 | 1629 |
1628 void Run() override { | 1630 void Run() override { |
1629 server2_channel_ = SyncChannel::Create( | 1631 server2_channel_ = SyncChannel::Create( |
1630 "reentrant_reply2", IPC::Channel::MODE_CLIENT, this, | 1632 "reentrant_reply2", IPC::Channel::MODE_CLIENT, this, |
1631 ipc_thread().task_runner().get(), true, shutdown_event(), nullptr); | 1633 ipc_thread().task_runner().get(), true, shutdown_event()); |
1632 server_ready_->Signal(); | 1634 server_ready_->Signal(); |
1633 Message* msg = new SyncChannelTestMsg_Reentrant1(); | 1635 Message* msg = new SyncChannelTestMsg_Reentrant1(); |
1634 server2_channel_->Send(msg); | 1636 server2_channel_->Send(msg); |
1635 server2_channel_.reset(); | 1637 server2_channel_.reset(); |
1636 Done(); | 1638 Done(); |
1637 } | 1639 } |
1638 | 1640 |
1639 private: | 1641 private: |
1640 bool OnMessageReceived(const Message& message) override { | 1642 bool OnMessageReceived(const Message& message) override { |
1641 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message) | 1643 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 } | 1802 } |
1801 | 1803 |
1802 // Windows needs to send an out-of-band secret to verify the client end of the | 1804 // Windows needs to send an out-of-band secret to verify the client end of the |
1803 // channel. Test that we still connect correctly in that case. | 1805 // channel. Test that we still connect correctly in that case. |
1804 TEST_F(IPCSyncChannelTest, Verified) { | 1806 TEST_F(IPCSyncChannelTest, Verified) { |
1805 Verified(); | 1807 Verified(); |
1806 } | 1808 } |
1807 | 1809 |
1808 } // namespace | 1810 } // namespace |
1809 } // namespace IPC | 1811 } // namespace IPC |
OLD | NEW |