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

Side by Side Diff: ipc/ipc_sync_channel_unittest.cc

Issue 1185133006: IPC: Make ChannelReader inherit from SupportsAttachmentBrokering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from tsepez. Created 5 years, 6 months 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_sync_channel.cc ('k') | ipc/ipc_test_base.cc » ('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 (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/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_); 158 &shutdown_event_, nullptr);
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 320
321 void Run() override { 321 void Run() override {
322 SendAnswerToLife(false, true); 322 SendAnswerToLife(false, true);
323 Done(); 323 Done();
324 } 324 }
325 325
326 SyncChannel* CreateChannel() override { 326 SyncChannel* CreateChannel() override {
327 SyncChannel* channel = 327 SyncChannel* channel =
328 SyncChannel::Create(channel_name(), mode(), this, 328 SyncChannel::Create(channel_name(), mode(), this,
329 ipc_thread().task_runner().get(), create_pipe_now_, 329 ipc_thread().task_runner().get(), create_pipe_now_,
330 shutdown_event()).release(); 330 shutdown_event(), nullptr).release();
331 return channel; 331 return channel;
332 } 332 }
333 333
334 bool create_pipe_now_; 334 bool create_pipe_now_;
335 }; 335 };
336 336
337 class TwoStepClient : public Worker { 337 class TwoStepClient : public Worker {
338 public: 338 public:
339 TwoStepClient(bool create_pipe_now) 339 TwoStepClient(bool create_pipe_now)
340 : Worker(Channel::MODE_CLIENT, "simple_client"), 340 : Worker(Channel::MODE_CLIENT, "simple_client"),
341 create_pipe_now_(create_pipe_now) { } 341 create_pipe_now_(create_pipe_now) { }
342 342
343 void OnAnswer(int* answer) override { 343 void OnAnswer(int* answer) override {
344 *answer = 42; 344 *answer = 42;
345 Done(); 345 Done();
346 } 346 }
347 347
348 SyncChannel* CreateChannel() override { 348 SyncChannel* CreateChannel() override {
349 SyncChannel* channel = 349 SyncChannel* channel =
350 SyncChannel::Create(channel_name(), mode(), this, 350 SyncChannel::Create(channel_name(), mode(), this,
351 ipc_thread().task_runner().get(), create_pipe_now_, 351 ipc_thread().task_runner().get(), create_pipe_now_,
352 shutdown_event()).release(); 352 shutdown_event(), nullptr).release();
353 return channel; 353 return channel;
354 } 354 }
355 355
356 bool create_pipe_now_; 356 bool create_pipe_now_;
357 }; 357 };
358 358
359 void TwoStep(bool create_server_pipe_now, bool create_client_pipe_now) { 359 void TwoStep(bool create_server_pipe_now, bool create_client_pipe_now) {
360 std::vector<Worker*> workers; 360 std::vector<Worker*> workers;
361 workers.push_back(new TwoStepServer(create_server_pipe_now)); 361 workers.push_back(new TwoStepServer(create_server_pipe_now));
362 workers.push_back(new TwoStepClient(create_client_pipe_now)); 362 workers.push_back(new TwoStepClient(create_client_pipe_now));
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1)); 1131 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1));
1132 sent_ping_event_->Wait(); 1132 sent_ping_event_->Wait();
1133 Send(new SyncChannelTestMsg_NoArgs); 1133 Send(new SyncChannelTestMsg_NoArgs);
1134 if (ping_ == 1) 1134 if (ping_ == 1)
1135 ++*success_; 1135 ++*success_;
1136 else 1136 else
1137 LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; 1137 LOG(ERROR) << "Send failed to dispatch incoming message on same channel";
1138 1138
1139 non_restricted_channel_ = SyncChannel::Create( 1139 non_restricted_channel_ = SyncChannel::Create(
1140 "non_restricted_channel", IPC::Channel::MODE_CLIENT, this, 1140 "non_restricted_channel", IPC::Channel::MODE_CLIENT, this,
1141 ipc_thread().task_runner().get(), true, shutdown_event()); 1141 ipc_thread().task_runner().get(), true, shutdown_event(), nullptr);
1142 1142
1143 server_->ListenerThread()->task_runner()->PostTask( 1143 server_->ListenerThread()->task_runner()->PostTask(
1144 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 2)); 1144 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 2));
1145 sent_ping_event_->Wait(); 1145 sent_ping_event_->Wait();
1146 // Check that the incoming message is *not* dispatched when sending on the 1146 // Check that the incoming message is *not* dispatched when sending on the
1147 // non restricted channel. 1147 // non restricted channel.
1148 // TODO(piman): there is a possibility of a false positive race condition 1148 // TODO(piman): there is a possibility of a false positive race condition
1149 // here, if the message that was posted on the server-side end of the pipe 1149 // here, if the message that was posted on the server-side end of the pipe
1150 // is not visible yet on the client side, but I don't know how to solve this 1150 // is not visible yet on the client side, but I don't know how to solve this
1151 // without hooking into the internals of SyncChannel. I haven't seen it in 1151 // 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
1518 Done(); 1518 Done();
1519 } 1519 }
1520 1520
1521 void Run() override { 1521 void Run() override {
1522 channel()->SetRestrictDispatchChannelGroup(group_); 1522 channel()->SetRestrictDispatchChannelGroup(group_);
1523 if (is_first()) 1523 if (is_first())
1524 event1_->Signal(); 1524 event1_->Signal();
1525 event2_->Wait(); 1525 event2_->Wait();
1526 other_channel_ = SyncChannel::Create( 1526 other_channel_ = SyncChannel::Create(
1527 other_channel_name_, IPC::Channel::MODE_CLIENT, this, 1527 other_channel_name_, IPC::Channel::MODE_CLIENT, this,
1528 ipc_thread().task_runner().get(), true, shutdown_event()); 1528 ipc_thread().task_runner().get(), true, shutdown_event(), nullptr);
1529 other_channel_->SetRestrictDispatchChannelGroup(group_); 1529 other_channel_->SetRestrictDispatchChannelGroup(group_);
1530 if (!is_first()) { 1530 if (!is_first()) {
1531 event1_->Signal(); 1531 event1_->Signal();
1532 return; 1532 return;
1533 } 1533 }
1534 *success_ = 0; 1534 *success_ = 0;
1535 int value = 0; 1535 int value = 0;
1536 OnPingTTL(3, &value); 1536 OnPingTTL(3, &value);
1537 *success_ += (value == 3); 1537 *success_ += (value == 3);
1538 OnPingTTL(4, &value); 1538 OnPingTTL(4, &value);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 1594
1595 class ReentrantReplyServer1 : public Worker { 1595 class ReentrantReplyServer1 : public Worker {
1596 public: 1596 public:
1597 ReentrantReplyServer1(WaitableEvent* server_ready) 1597 ReentrantReplyServer1(WaitableEvent* server_ready)
1598 : Worker("reentrant_reply1", Channel::MODE_SERVER), 1598 : Worker("reentrant_reply1", Channel::MODE_SERVER),
1599 server_ready_(server_ready) { } 1599 server_ready_(server_ready) { }
1600 1600
1601 void Run() override { 1601 void Run() override {
1602 server2_channel_ = SyncChannel::Create( 1602 server2_channel_ = SyncChannel::Create(
1603 "reentrant_reply2", IPC::Channel::MODE_CLIENT, this, 1603 "reentrant_reply2", IPC::Channel::MODE_CLIENT, this,
1604 ipc_thread().task_runner().get(), true, shutdown_event()); 1604 ipc_thread().task_runner().get(), true, shutdown_event(), nullptr);
1605 server_ready_->Signal(); 1605 server_ready_->Signal();
1606 Message* msg = new SyncChannelTestMsg_Reentrant1(); 1606 Message* msg = new SyncChannelTestMsg_Reentrant1();
1607 server2_channel_->Send(msg); 1607 server2_channel_->Send(msg);
1608 server2_channel_.reset(); 1608 server2_channel_.reset();
1609 Done(); 1609 Done();
1610 } 1610 }
1611 1611
1612 private: 1612 private:
1613 bool OnMessageReceived(const Message& message) override { 1613 bool OnMessageReceived(const Message& message) override {
1614 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message) 1614 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 } 1773 }
1774 1774
1775 // Windows needs to send an out-of-band secret to verify the client end of the 1775 // Windows needs to send an out-of-band secret to verify the client end of the
1776 // channel. Test that we still connect correctly in that case. 1776 // channel. Test that we still connect correctly in that case.
1777 TEST_F(IPCSyncChannelTest, Verified) { 1777 TEST_F(IPCSyncChannelTest, Verified) {
1778 Verified(); 1778 Verified();
1779 } 1779 }
1780 1780
1781 } // namespace 1781 } // namespace
1782 } // namespace IPC 1782 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_sync_channel.cc ('k') | ipc/ipc_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698