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

Side by Side Diff: ipc/ipc_sync_channel_unittest.cc

Issue 645623006: Standardize usage of virtual/override/final in ipc/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 channel_created_(new WaitableEvent(false, false)), 51 channel_created_(new WaitableEvent(false, false)),
52 channel_name_(channel_name), 52 channel_name_(channel_name),
53 mode_(mode), 53 mode_(mode),
54 ipc_thread_((channel_name + "_ipc").c_str()), 54 ipc_thread_((channel_name + "_ipc").c_str()),
55 listener_thread_((channel_name + "_listener").c_str()), 55 listener_thread_((channel_name + "_listener").c_str()),
56 overrided_thread_(NULL), 56 overrided_thread_(NULL),
57 shutdown_event_(true, false), 57 shutdown_event_(true, false),
58 is_shutdown_(false) { 58 is_shutdown_(false) {
59 } 59 }
60 60
61 virtual ~Worker() { 61 ~Worker() override {
62 // Shutdown() must be called before destruction. 62 // Shutdown() must be called before destruction.
63 CHECK(is_shutdown_); 63 CHECK(is_shutdown_);
64 } 64 }
65 void AddRef() { } 65 void AddRef() { }
66 void Release() { } 66 void Release() { }
67 virtual bool Send(Message* msg) override { return channel_->Send(msg); } 67 bool Send(Message* msg) override { return channel_->Send(msg); }
68 void WaitForChannelCreation() { channel_created_->Wait(); } 68 void WaitForChannelCreation() { channel_created_->Wait(); }
69 void CloseChannel() { 69 void CloseChannel() {
70 DCHECK(base::MessageLoop::current() == ListenerThread()->message_loop()); 70 DCHECK(base::MessageLoop::current() == ListenerThread()->message_loop());
71 channel_->Close(); 71 channel_->Close();
72 } 72 }
73 void Start() { 73 void Start() {
74 StartThread(&listener_thread_, base::MessageLoop::TYPE_DEFAULT); 74 StartThread(&listener_thread_, base::MessageLoop::TYPE_DEFAULT);
75 ListenerThread()->message_loop()->PostTask( 75 ListenerThread()->message_loop()->PostTask(
76 FROM_HERE, base::Bind(&Worker::OnStart, this)); 76 FROM_HERE, base::Bind(&Worker::OnStart, this));
77 } 77 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 listener_thread_.message_loop()->PostTask( 193 listener_thread_.message_loop()->PostTask(
194 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown2, this, 194 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown2, this,
195 listener_event)); 195 listener_event));
196 } 196 }
197 197
198 void OnListenerThreadShutdown2(WaitableEvent* listener_event) { 198 void OnListenerThreadShutdown2(WaitableEvent* listener_event) {
199 base::RunLoop().RunUntilIdle(); 199 base::RunLoop().RunUntilIdle();
200 listener_event->Signal(); 200 listener_event->Signal();
201 } 201 }
202 202
203 virtual bool OnMessageReceived(const Message& message) override { 203 bool OnMessageReceived(const Message& message) override {
204 IPC_BEGIN_MESSAGE_MAP(Worker, message) 204 IPC_BEGIN_MESSAGE_MAP(Worker, message)
205 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_Double, OnDoubleDelay) 205 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_Double, OnDoubleDelay)
206 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_AnswerToLife, 206 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_AnswerToLife,
207 OnAnswerDelay) 207 OnAnswerDelay)
208 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelNestedTestMsg_String, 208 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelNestedTestMsg_String,
209 OnNestedTestMsg) 209 OnNestedTestMsg)
210 IPC_END_MESSAGE_MAP() 210 IPC_END_MESSAGE_MAP()
211 return true; 211 return true;
212 } 212 }
213 213
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 base::MessageLoop message_loop_; 267 base::MessageLoop message_loop_;
268 }; 268 };
269 269
270 //------------------------------------------------------------------------------ 270 //------------------------------------------------------------------------------
271 271
272 class SimpleServer : public Worker { 272 class SimpleServer : public Worker {
273 public: 273 public:
274 explicit SimpleServer(bool pump_during_send) 274 explicit SimpleServer(bool pump_during_send)
275 : Worker(Channel::MODE_SERVER, "simpler_server"), 275 : Worker(Channel::MODE_SERVER, "simpler_server"),
276 pump_during_send_(pump_during_send) { } 276 pump_during_send_(pump_during_send) { }
277 virtual void Run() override { 277 void Run() override {
278 SendAnswerToLife(pump_during_send_, true); 278 SendAnswerToLife(pump_during_send_, true);
279 Done(); 279 Done();
280 } 280 }
281 281
282 bool pump_during_send_; 282 bool pump_during_send_;
283 }; 283 };
284 284
285 class SimpleClient : public Worker { 285 class SimpleClient : public Worker {
286 public: 286 public:
287 SimpleClient() : Worker(Channel::MODE_CLIENT, "simple_client") { } 287 SimpleClient() : Worker(Channel::MODE_CLIENT, "simple_client") { }
288 288
289 virtual void OnAnswer(int* answer) override { 289 void OnAnswer(int* answer) override {
290 *answer = 42; 290 *answer = 42;
291 Done(); 291 Done();
292 } 292 }
293 }; 293 };
294 294
295 void Simple(bool pump_during_send) { 295 void Simple(bool pump_during_send) {
296 std::vector<Worker*> workers; 296 std::vector<Worker*> workers;
297 workers.push_back(new SimpleServer(pump_during_send)); 297 workers.push_back(new SimpleServer(pump_during_send));
298 workers.push_back(new SimpleClient()); 298 workers.push_back(new SimpleClient());
299 RunTest(workers); 299 RunTest(workers);
300 } 300 }
301 301
302 // Tests basic synchronous call 302 // Tests basic synchronous call
303 TEST_F(IPCSyncChannelTest, Simple) { 303 TEST_F(IPCSyncChannelTest, Simple) {
304 Simple(false); 304 Simple(false);
305 Simple(true); 305 Simple(true);
306 } 306 }
307 307
308 //------------------------------------------------------------------------------ 308 //------------------------------------------------------------------------------
309 309
310 // Worker classes which override how the sync channel is created to use the 310 // Worker classes which override how the sync channel is created to use the
311 // two-step initialization (calling the lightweight constructor and then 311 // two-step initialization (calling the lightweight constructor and then
312 // ChannelProxy::Init separately) process. 312 // ChannelProxy::Init separately) process.
313 class TwoStepServer : public Worker { 313 class TwoStepServer : public Worker {
314 public: 314 public:
315 explicit TwoStepServer(bool create_pipe_now) 315 explicit TwoStepServer(bool create_pipe_now)
316 : Worker(Channel::MODE_SERVER, "simpler_server"), 316 : Worker(Channel::MODE_SERVER, "simpler_server"),
317 create_pipe_now_(create_pipe_now) { } 317 create_pipe_now_(create_pipe_now) { }
318 318
319 virtual void Run() override { 319 void Run() override {
320 SendAnswerToLife(false, true); 320 SendAnswerToLife(false, true);
321 Done(); 321 Done();
322 } 322 }
323 323
324 virtual SyncChannel* CreateChannel() override { 324 SyncChannel* CreateChannel() override {
325 SyncChannel* channel = 325 SyncChannel* channel =
326 SyncChannel::Create(channel_name(), mode(), this, 326 SyncChannel::Create(channel_name(), mode(), this,
327 ipc_thread().message_loop_proxy().get(), 327 ipc_thread().message_loop_proxy().get(),
328 create_pipe_now_, 328 create_pipe_now_,
329 shutdown_event()).release(); 329 shutdown_event()).release();
330 return channel; 330 return channel;
331 } 331 }
332 332
333 bool create_pipe_now_; 333 bool create_pipe_now_;
334 }; 334 };
335 335
336 class TwoStepClient : public Worker { 336 class TwoStepClient : public Worker {
337 public: 337 public:
338 TwoStepClient(bool create_pipe_now) 338 TwoStepClient(bool create_pipe_now)
339 : Worker(Channel::MODE_CLIENT, "simple_client"), 339 : Worker(Channel::MODE_CLIENT, "simple_client"),
340 create_pipe_now_(create_pipe_now) { } 340 create_pipe_now_(create_pipe_now) { }
341 341
342 virtual void OnAnswer(int* answer) override { 342 void OnAnswer(int* answer) override {
343 *answer = 42; 343 *answer = 42;
344 Done(); 344 Done();
345 } 345 }
346 346
347 virtual SyncChannel* CreateChannel() override { 347 SyncChannel* CreateChannel() override {
348 SyncChannel* channel = 348 SyncChannel* channel =
349 SyncChannel::Create(channel_name(), mode(), this, 349 SyncChannel::Create(channel_name(), mode(), this,
350 ipc_thread().message_loop_proxy().get(), 350 ipc_thread().message_loop_proxy().get(),
351 create_pipe_now_, 351 create_pipe_now_,
352 shutdown_event()).release(); 352 shutdown_event()).release();
353 return channel; 353 return channel;
354 } 354 }
355 355
356 bool create_pipe_now_; 356 bool create_pipe_now_;
357 }; 357 };
(...skipping 13 matching lines...) Expand all
371 TwoStep(true, false); 371 TwoStep(true, false);
372 TwoStep(true, true); 372 TwoStep(true, true);
373 } 373 }
374 374
375 //------------------------------------------------------------------------------ 375 //------------------------------------------------------------------------------
376 376
377 class DelayClient : public Worker { 377 class DelayClient : public Worker {
378 public: 378 public:
379 DelayClient() : Worker(Channel::MODE_CLIENT, "delay_client") { } 379 DelayClient() : Worker(Channel::MODE_CLIENT, "delay_client") { }
380 380
381 virtual void OnAnswerDelay(Message* reply_msg) override { 381 void OnAnswerDelay(Message* reply_msg) override {
382 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42); 382 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42);
383 Send(reply_msg); 383 Send(reply_msg);
384 Done(); 384 Done();
385 } 385 }
386 }; 386 };
387 387
388 void DelayReply(bool pump_during_send) { 388 void DelayReply(bool pump_during_send) {
389 std::vector<Worker*> workers; 389 std::vector<Worker*> workers;
390 workers.push_back(new SimpleServer(pump_during_send)); 390 workers.push_back(new SimpleServer(pump_during_send));
391 workers.push_back(new DelayClient()); 391 workers.push_back(new DelayClient());
392 RunTest(workers); 392 RunTest(workers);
393 } 393 }
394 394
395 // Tests that asynchronous replies work 395 // Tests that asynchronous replies work
396 TEST_F(IPCSyncChannelTest, DelayReply) { 396 TEST_F(IPCSyncChannelTest, DelayReply) {
397 DelayReply(false); 397 DelayReply(false);
398 DelayReply(true); 398 DelayReply(true);
399 } 399 }
400 400
401 //------------------------------------------------------------------------------ 401 //------------------------------------------------------------------------------
402 402
403 class NoHangServer : public Worker { 403 class NoHangServer : public Worker {
404 public: 404 public:
405 NoHangServer(WaitableEvent* got_first_reply, bool pump_during_send) 405 NoHangServer(WaitableEvent* got_first_reply, bool pump_during_send)
406 : Worker(Channel::MODE_SERVER, "no_hang_server"), 406 : Worker(Channel::MODE_SERVER, "no_hang_server"),
407 got_first_reply_(got_first_reply), 407 got_first_reply_(got_first_reply),
408 pump_during_send_(pump_during_send) { } 408 pump_during_send_(pump_during_send) { }
409 virtual void Run() override { 409 void Run() override {
410 SendAnswerToLife(pump_during_send_, true); 410 SendAnswerToLife(pump_during_send_, true);
411 got_first_reply_->Signal(); 411 got_first_reply_->Signal();
412 412
413 SendAnswerToLife(pump_during_send_, false); 413 SendAnswerToLife(pump_during_send_, false);
414 Done(); 414 Done();
415 } 415 }
416 416
417 WaitableEvent* got_first_reply_; 417 WaitableEvent* got_first_reply_;
418 bool pump_during_send_; 418 bool pump_during_send_;
419 }; 419 };
420 420
421 class NoHangClient : public Worker { 421 class NoHangClient : public Worker {
422 public: 422 public:
423 explicit NoHangClient(WaitableEvent* got_first_reply) 423 explicit NoHangClient(WaitableEvent* got_first_reply)
424 : Worker(Channel::MODE_CLIENT, "no_hang_client"), 424 : Worker(Channel::MODE_CLIENT, "no_hang_client"),
425 got_first_reply_(got_first_reply) { } 425 got_first_reply_(got_first_reply) { }
426 426
427 virtual void OnAnswerDelay(Message* reply_msg) override { 427 void OnAnswerDelay(Message* reply_msg) override {
428 // Use the DELAY_REPLY macro so that we can force the reply to be sent 428 // Use the DELAY_REPLY macro so that we can force the reply to be sent
429 // before this function returns (when the channel will be reset). 429 // before this function returns (when the channel will be reset).
430 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42); 430 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42);
431 Send(reply_msg); 431 Send(reply_msg);
432 got_first_reply_->Wait(); 432 got_first_reply_->Wait();
433 CloseChannel(); 433 CloseChannel();
434 Done(); 434 Done();
435 } 435 }
436 436
437 WaitableEvent* got_first_reply_; 437 WaitableEvent* got_first_reply_;
(...skipping 14 matching lines...) Expand all
452 } 452 }
453 453
454 //------------------------------------------------------------------------------ 454 //------------------------------------------------------------------------------
455 455
456 class UnblockServer : public Worker { 456 class UnblockServer : public Worker {
457 public: 457 public:
458 UnblockServer(bool pump_during_send, bool delete_during_send) 458 UnblockServer(bool pump_during_send, bool delete_during_send)
459 : Worker(Channel::MODE_SERVER, "unblock_server"), 459 : Worker(Channel::MODE_SERVER, "unblock_server"),
460 pump_during_send_(pump_during_send), 460 pump_during_send_(pump_during_send),
461 delete_during_send_(delete_during_send) { } 461 delete_during_send_(delete_during_send) { }
462 virtual void Run() override { 462 void Run() override {
463 if (delete_during_send_) { 463 if (delete_during_send_) {
464 // Use custom code since race conditions mean the answer may or may not be 464 // Use custom code since race conditions mean the answer may or may not be
465 // available. 465 // available.
466 int answer = 0; 466 int answer = 0;
467 SyncMessage* msg = new SyncChannelTestMsg_AnswerToLife(&answer); 467 SyncMessage* msg = new SyncChannelTestMsg_AnswerToLife(&answer);
468 if (pump_during_send_) 468 if (pump_during_send_)
469 msg->EnableMessagePumping(); 469 msg->EnableMessagePumping();
470 Send(msg); 470 Send(msg);
471 } else { 471 } else {
472 SendAnswerToLife(pump_during_send_, true); 472 SendAnswerToLife(pump_during_send_, true);
473 } 473 }
474 Done(); 474 Done();
475 } 475 }
476 476
477 virtual void OnDoubleDelay(int in, Message* reply_msg) override { 477 void OnDoubleDelay(int in, Message* reply_msg) override {
478 SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, in * 2); 478 SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, in * 2);
479 Send(reply_msg); 479 Send(reply_msg);
480 if (delete_during_send_) 480 if (delete_during_send_)
481 ResetChannel(); 481 ResetChannel();
482 } 482 }
483 483
484 bool pump_during_send_; 484 bool pump_during_send_;
485 bool delete_during_send_; 485 bool delete_during_send_;
486 }; 486 };
487 487
488 class UnblockClient : public Worker { 488 class UnblockClient : public Worker {
489 public: 489 public:
490 explicit UnblockClient(bool pump_during_send) 490 explicit UnblockClient(bool pump_during_send)
491 : Worker(Channel::MODE_CLIENT, "unblock_client"), 491 : Worker(Channel::MODE_CLIENT, "unblock_client"),
492 pump_during_send_(pump_during_send) { } 492 pump_during_send_(pump_during_send) { }
493 493
494 virtual void OnAnswer(int* answer) override { 494 void OnAnswer(int* answer) override {
495 SendDouble(pump_during_send_, true); 495 SendDouble(pump_during_send_, true);
496 *answer = 42; 496 *answer = 42;
497 Done(); 497 Done();
498 } 498 }
499 499
500 bool pump_during_send_; 500 bool pump_during_send_;
501 }; 501 };
502 502
503 void Unblock(bool server_pump, bool client_pump, bool delete_during_send) { 503 void Unblock(bool server_pump, bool client_pump, bool delete_during_send) {
504 std::vector<Worker*> workers; 504 std::vector<Worker*> workers;
(...skipping 21 matching lines...) Expand all
526 } 526 }
527 527
528 //------------------------------------------------------------------------------ 528 //------------------------------------------------------------------------------
529 529
530 class RecursiveServer : public Worker { 530 class RecursiveServer : public Worker {
531 public: 531 public:
532 RecursiveServer(bool expected_send_result, bool pump_first, bool pump_second) 532 RecursiveServer(bool expected_send_result, bool pump_first, bool pump_second)
533 : Worker(Channel::MODE_SERVER, "recursive_server"), 533 : Worker(Channel::MODE_SERVER, "recursive_server"),
534 expected_send_result_(expected_send_result), 534 expected_send_result_(expected_send_result),
535 pump_first_(pump_first), pump_second_(pump_second) {} 535 pump_first_(pump_first), pump_second_(pump_second) {}
536 virtual void Run() override { 536 void Run() override {
537 SendDouble(pump_first_, expected_send_result_); 537 SendDouble(pump_first_, expected_send_result_);
538 Done(); 538 Done();
539 } 539 }
540 540
541 virtual void OnDouble(int in, int* out) override { 541 void OnDouble(int in, int* out) override {
542 *out = in * 2; 542 *out = in * 2;
543 SendAnswerToLife(pump_second_, expected_send_result_); 543 SendAnswerToLife(pump_second_, expected_send_result_);
544 } 544 }
545 545
546 bool expected_send_result_, pump_first_, pump_second_; 546 bool expected_send_result_, pump_first_, pump_second_;
547 }; 547 };
548 548
549 class RecursiveClient : public Worker { 549 class RecursiveClient : public Worker {
550 public: 550 public:
551 RecursiveClient(bool pump_during_send, bool close_channel) 551 RecursiveClient(bool pump_during_send, bool close_channel)
552 : Worker(Channel::MODE_CLIENT, "recursive_client"), 552 : Worker(Channel::MODE_CLIENT, "recursive_client"),
553 pump_during_send_(pump_during_send), close_channel_(close_channel) {} 553 pump_during_send_(pump_during_send), close_channel_(close_channel) {}
554 554
555 virtual void OnDoubleDelay(int in, Message* reply_msg) override { 555 void OnDoubleDelay(int in, Message* reply_msg) override {
556 SendDouble(pump_during_send_, !close_channel_); 556 SendDouble(pump_during_send_, !close_channel_);
557 if (close_channel_) { 557 if (close_channel_) {
558 delete reply_msg; 558 delete reply_msg;
559 } else { 559 } else {
560 SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, in * 2); 560 SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, in * 2);
561 Send(reply_msg); 561 Send(reply_msg);
562 } 562 }
563 Done(); 563 Done();
564 } 564 }
565 565
566 virtual void OnAnswerDelay(Message* reply_msg) override { 566 void OnAnswerDelay(Message* reply_msg) override {
567 if (close_channel_) { 567 if (close_channel_) {
568 delete reply_msg; 568 delete reply_msg;
569 CloseChannel(); 569 CloseChannel();
570 } else { 570 } else {
571 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42); 571 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42);
572 Send(reply_msg); 572 Send(reply_msg);
573 } 573 }
574 } 574 }
575 575
576 bool pump_during_send_, close_channel_; 576 bool pump_during_send_, close_channel_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 } 622 }
623 623
624 //------------------------------------------------------------------------------ 624 //------------------------------------------------------------------------------
625 625
626 class MultipleServer1 : public Worker { 626 class MultipleServer1 : public Worker {
627 public: 627 public:
628 explicit MultipleServer1(bool pump_during_send) 628 explicit MultipleServer1(bool pump_during_send)
629 : Worker("test_channel1", Channel::MODE_SERVER), 629 : Worker("test_channel1", Channel::MODE_SERVER),
630 pump_during_send_(pump_during_send) { } 630 pump_during_send_(pump_during_send) { }
631 631
632 virtual void Run() override { 632 void Run() override {
633 SendDouble(pump_during_send_, true); 633 SendDouble(pump_during_send_, true);
634 Done(); 634 Done();
635 } 635 }
636 636
637 bool pump_during_send_; 637 bool pump_during_send_;
638 }; 638 };
639 639
640 class MultipleClient1 : public Worker { 640 class MultipleClient1 : public Worker {
641 public: 641 public:
642 MultipleClient1(WaitableEvent* client1_msg_received, 642 MultipleClient1(WaitableEvent* client1_msg_received,
643 WaitableEvent* client1_can_reply) : 643 WaitableEvent* client1_can_reply) :
644 Worker("test_channel1", Channel::MODE_CLIENT), 644 Worker("test_channel1", Channel::MODE_CLIENT),
645 client1_msg_received_(client1_msg_received), 645 client1_msg_received_(client1_msg_received),
646 client1_can_reply_(client1_can_reply) { } 646 client1_can_reply_(client1_can_reply) { }
647 647
648 virtual void OnDouble(int in, int* out) override { 648 void OnDouble(int in, int* out) override {
649 client1_msg_received_->Signal(); 649 client1_msg_received_->Signal();
650 *out = in * 2; 650 *out = in * 2;
651 client1_can_reply_->Wait(); 651 client1_can_reply_->Wait();
652 Done(); 652 Done();
653 } 653 }
654 654
655 private: 655 private:
656 WaitableEvent *client1_msg_received_, *client1_can_reply_; 656 WaitableEvent *client1_msg_received_, *client1_can_reply_;
657 }; 657 };
658 658
659 class MultipleServer2 : public Worker { 659 class MultipleServer2 : public Worker {
660 public: 660 public:
661 MultipleServer2() : Worker("test_channel2", Channel::MODE_SERVER) { } 661 MultipleServer2() : Worker("test_channel2", Channel::MODE_SERVER) { }
662 662
663 virtual void OnAnswer(int* result) override { 663 void OnAnswer(int* result) override {
664 *result = 42; 664 *result = 42;
665 Done(); 665 Done();
666 } 666 }
667 }; 667 };
668 668
669 class MultipleClient2 : public Worker { 669 class MultipleClient2 : public Worker {
670 public: 670 public:
671 MultipleClient2( 671 MultipleClient2(
672 WaitableEvent* client1_msg_received, WaitableEvent* client1_can_reply, 672 WaitableEvent* client1_msg_received, WaitableEvent* client1_can_reply,
673 bool pump_during_send) 673 bool pump_during_send)
674 : Worker("test_channel2", Channel::MODE_CLIENT), 674 : Worker("test_channel2", Channel::MODE_CLIENT),
675 client1_msg_received_(client1_msg_received), 675 client1_msg_received_(client1_msg_received),
676 client1_can_reply_(client1_can_reply), 676 client1_can_reply_(client1_can_reply),
677 pump_during_send_(pump_during_send) { } 677 pump_during_send_(pump_during_send) { }
678 678
679 virtual void Run() override { 679 void Run() override {
680 client1_msg_received_->Wait(); 680 client1_msg_received_->Wait();
681 SendAnswerToLife(pump_during_send_, true); 681 SendAnswerToLife(pump_during_send_, true);
682 client1_can_reply_->Signal(); 682 client1_can_reply_->Signal();
683 Done(); 683 Done();
684 } 684 }
685 685
686 private: 686 private:
687 WaitableEvent *client1_msg_received_, *client1_can_reply_; 687 WaitableEvent *client1_msg_received_, *client1_can_reply_;
688 bool pump_during_send_; 688 bool pump_during_send_;
689 }; 689 };
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 class QueuedReplyServer : public Worker { 739 class QueuedReplyServer : public Worker {
740 public: 740 public:
741 QueuedReplyServer(base::Thread* listener_thread, 741 QueuedReplyServer(base::Thread* listener_thread,
742 const std::string& channel_name, 742 const std::string& channel_name,
743 const std::string& reply_text) 743 const std::string& reply_text)
744 : Worker(channel_name, Channel::MODE_SERVER), 744 : Worker(channel_name, Channel::MODE_SERVER),
745 reply_text_(reply_text) { 745 reply_text_(reply_text) {
746 Worker::OverrideThread(listener_thread); 746 Worker::OverrideThread(listener_thread);
747 } 747 }
748 748
749 virtual void OnNestedTestMsg(Message* reply_msg) override { 749 void OnNestedTestMsg(Message* reply_msg) override {
750 VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_; 750 VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_;
751 SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_); 751 SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_);
752 Send(reply_msg); 752 Send(reply_msg);
753 Done(); 753 Done();
754 } 754 }
755 755
756 private: 756 private:
757 std::string reply_text_; 757 std::string reply_text_;
758 }; 758 };
759 759
760 // The QueuedReplyClient class provides functionality to test the case where 760 // The QueuedReplyClient class provides functionality to test the case where
761 // multiple sync channels are in use on the same thread and they make nested 761 // multiple sync channels are in use on the same thread and they make nested
762 // sync calls, i.e. while the first channel waits for a response it makes a 762 // sync calls, i.e. while the first channel waits for a response it makes a
763 // sync call on another channel. 763 // sync call on another channel.
764 // The callstack should unwind correctly, i.e. the outermost call should 764 // The callstack should unwind correctly, i.e. the outermost call should
765 // complete first, and so on. 765 // complete first, and so on.
766 class QueuedReplyClient : public Worker { 766 class QueuedReplyClient : public Worker {
767 public: 767 public:
768 QueuedReplyClient(base::Thread* listener_thread, 768 QueuedReplyClient(base::Thread* listener_thread,
769 const std::string& channel_name, 769 const std::string& channel_name,
770 const std::string& expected_text, 770 const std::string& expected_text,
771 bool pump_during_send) 771 bool pump_during_send)
772 : Worker(channel_name, Channel::MODE_CLIENT), 772 : Worker(channel_name, Channel::MODE_CLIENT),
773 pump_during_send_(pump_during_send), 773 pump_during_send_(pump_during_send),
774 expected_text_(expected_text) { 774 expected_text_(expected_text) {
775 Worker::OverrideThread(listener_thread); 775 Worker::OverrideThread(listener_thread);
776 } 776 }
777 777
778 virtual void Run() override { 778 void Run() override {
779 std::string response; 779 std::string response;
780 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response); 780 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response);
781 if (pump_during_send_) 781 if (pump_during_send_)
782 msg->EnableMessagePumping(); 782 msg->EnableMessagePumping();
783 bool result = Send(msg); 783 bool result = Send(msg);
784 DCHECK(result); 784 DCHECK(result);
785 DCHECK_EQ(response, expected_text_); 785 DCHECK_EQ(response, expected_text_);
786 786
787 VLOG(1) << __FUNCTION__ << " Received reply: " << response; 787 VLOG(1) << __FUNCTION__ << " Received reply: " << response;
788 Done(); 788 Done();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 QueuedReply(true); 841 QueuedReply(true);
842 } 842 }
843 843
844 //------------------------------------------------------------------------------ 844 //------------------------------------------------------------------------------
845 845
846 class ChattyClient : public Worker { 846 class ChattyClient : public Worker {
847 public: 847 public:
848 ChattyClient() : 848 ChattyClient() :
849 Worker(Channel::MODE_CLIENT, "chatty_client") { } 849 Worker(Channel::MODE_CLIENT, "chatty_client") { }
850 850
851 virtual void OnAnswer(int* answer) override { 851 void OnAnswer(int* answer) override {
852 // The PostMessage limit is 10k. Send 20% more than that. 852 // The PostMessage limit is 10k. Send 20% more than that.
853 const int kMessageLimit = 10000; 853 const int kMessageLimit = 10000;
854 const int kMessagesToSend = kMessageLimit * 120 / 100; 854 const int kMessagesToSend = kMessageLimit * 120 / 100;
855 for (int i = 0; i < kMessagesToSend; ++i) { 855 for (int i = 0; i < kMessagesToSend; ++i) {
856 if (!SendDouble(false, true)) 856 if (!SendDouble(false, true))
857 break; 857 break;
858 } 858 }
859 *answer = 42; 859 *answer = 42;
860 Done(); 860 Done();
861 } 861 }
(...skipping 26 matching lines...) Expand all
888 888
889 void TimeoutCallback() { 889 void TimeoutCallback() {
890 timeout_occurred = true; 890 timeout_occurred = true;
891 } 891 }
892 892
893 class DoneEventRaceServer : public Worker { 893 class DoneEventRaceServer : public Worker {
894 public: 894 public:
895 DoneEventRaceServer() 895 DoneEventRaceServer()
896 : Worker(Channel::MODE_SERVER, "done_event_race_server") { } 896 : Worker(Channel::MODE_SERVER, "done_event_race_server") { }
897 897
898 virtual void Run() override { 898 void Run() override {
899 base::MessageLoop::current()->PostTask(FROM_HERE, 899 base::MessageLoop::current()->PostTask(FROM_HERE,
900 base::Bind(&NestedCallback, this)); 900 base::Bind(&NestedCallback, this));
901 base::MessageLoop::current()->PostDelayedTask( 901 base::MessageLoop::current()->PostDelayedTask(
902 FROM_HERE, 902 FROM_HERE,
903 base::Bind(&TimeoutCallback), 903 base::Bind(&TimeoutCallback),
904 base::TimeDelta::FromSeconds(9)); 904 base::TimeDelta::FromSeconds(9));
905 // Even though we have a timeout on the Send, it will succeed since for this 905 // Even though we have a timeout on the Send, it will succeed since for this
906 // bug, the reply message comes back and is deserialized, however the done 906 // bug, the reply message comes back and is deserialized, however the done
907 // event wasn't set. So we indirectly use the timeout task to notice if a 907 // event wasn't set. So we indirectly use the timeout task to notice if a
908 // timeout occurred. 908 // timeout occurred.
(...skipping 18 matching lines...) Expand all
927 class TestSyncMessageFilter : public SyncMessageFilter { 927 class TestSyncMessageFilter : public SyncMessageFilter {
928 public: 928 public:
929 TestSyncMessageFilter(base::WaitableEvent* shutdown_event, 929 TestSyncMessageFilter(base::WaitableEvent* shutdown_event,
930 Worker* worker, 930 Worker* worker,
931 scoped_refptr<base::MessageLoopProxy> message_loop) 931 scoped_refptr<base::MessageLoopProxy> message_loop)
932 : SyncMessageFilter(shutdown_event), 932 : SyncMessageFilter(shutdown_event),
933 worker_(worker), 933 worker_(worker),
934 message_loop_(message_loop) { 934 message_loop_(message_loop) {
935 } 935 }
936 936
937 virtual void OnFilterAdded(Sender* sender) override { 937 void OnFilterAdded(Sender* sender) override {
938 SyncMessageFilter::OnFilterAdded(sender); 938 SyncMessageFilter::OnFilterAdded(sender);
939 message_loop_->PostTask( 939 message_loop_->PostTask(
940 FROM_HERE, 940 FROM_HERE,
941 base::Bind(&TestSyncMessageFilter::SendMessageOnHelperThread, this)); 941 base::Bind(&TestSyncMessageFilter::SendMessageOnHelperThread, this));
942 } 942 }
943 943
944 void SendMessageOnHelperThread() { 944 void SendMessageOnHelperThread() {
945 int answer = 0; 945 int answer = 0;
946 bool result = Send(new SyncChannelTestMsg_AnswerToLife(&answer)); 946 bool result = Send(new SyncChannelTestMsg_AnswerToLife(&answer));
947 DCHECK(result); 947 DCHECK(result);
948 DCHECK_EQ(answer, 42); 948 DCHECK_EQ(answer, 42);
949 949
950 worker_->Done(); 950 worker_->Done();
951 } 951 }
952 952
953 private: 953 private:
954 virtual ~TestSyncMessageFilter() {} 954 ~TestSyncMessageFilter() override {}
955 955
956 Worker* worker_; 956 Worker* worker_;
957 scoped_refptr<base::MessageLoopProxy> message_loop_; 957 scoped_refptr<base::MessageLoopProxy> message_loop_;
958 }; 958 };
959 959
960 class SyncMessageFilterServer : public Worker { 960 class SyncMessageFilterServer : public Worker {
961 public: 961 public:
962 SyncMessageFilterServer() 962 SyncMessageFilterServer()
963 : Worker(Channel::MODE_SERVER, "sync_message_filter_server"), 963 : Worker(Channel::MODE_SERVER, "sync_message_filter_server"),
964 thread_("helper_thread") { 964 thread_("helper_thread") {
965 base::Thread::Options options; 965 base::Thread::Options options;
966 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; 966 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT;
967 thread_.StartWithOptions(options); 967 thread_.StartWithOptions(options);
968 filter_ = new TestSyncMessageFilter(shutdown_event(), this, 968 filter_ = new TestSyncMessageFilter(shutdown_event(), this,
969 thread_.message_loop_proxy()); 969 thread_.message_loop_proxy());
970 } 970 }
971 971
972 virtual void Run() override { 972 void Run() override { channel()->AddFilter(filter_.get()); }
973 channel()->AddFilter(filter_.get());
974 }
975 973
976 base::Thread thread_; 974 base::Thread thread_;
977 scoped_refptr<TestSyncMessageFilter> filter_; 975 scoped_refptr<TestSyncMessageFilter> filter_;
978 }; 976 };
979 977
980 // This class provides functionality to test the case that a Send on the sync 978 // This class provides functionality to test the case that a Send on the sync
981 // channel does not crash after the channel has been closed. 979 // channel does not crash after the channel has been closed.
982 class ServerSendAfterClose : public Worker { 980 class ServerSendAfterClose : public Worker {
983 public: 981 public:
984 ServerSendAfterClose() 982 ServerSendAfterClose()
985 : Worker(Channel::MODE_SERVER, "simpler_server"), 983 : Worker(Channel::MODE_SERVER, "simpler_server"),
986 send_result_(true) { 984 send_result_(true) {
987 } 985 }
988 986
989 bool SendDummy() { 987 bool SendDummy() {
990 ListenerThread()->message_loop()->PostTask( 988 ListenerThread()->message_loop()->PostTask(
991 FROM_HERE, base::Bind(base::IgnoreResult(&ServerSendAfterClose::Send), 989 FROM_HERE, base::Bind(base::IgnoreResult(&ServerSendAfterClose::Send),
992 this, new SyncChannelTestMsg_NoArgs)); 990 this, new SyncChannelTestMsg_NoArgs));
993 return true; 991 return true;
994 } 992 }
995 993
996 bool send_result() const { 994 bool send_result() const {
997 return send_result_; 995 return send_result_;
998 } 996 }
999 997
1000 private: 998 private:
1001 virtual void Run() override { 999 void Run() override {
1002 CloseChannel(); 1000 CloseChannel();
1003 Done(); 1001 Done();
1004 } 1002 }
1005 1003
1006 virtual bool Send(Message* msg) override { 1004 bool Send(Message* msg) override {
1007 send_result_ = Worker::Send(msg); 1005 send_result_ = Worker::Send(msg);
1008 Done(); 1006 Done();
1009 return send_result_; 1007 return send_result_;
1010 } 1008 }
1011 1009
1012 bool send_result_; 1010 bool send_result_;
1013 }; 1011 };
1014 1012
1015 // Tests basic synchronous call 1013 // Tests basic synchronous call
1016 TEST_F(IPCSyncChannelTest, SyncMessageFilter) { 1014 TEST_F(IPCSyncChannelTest, SyncMessageFilter) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 } 1056 }
1059 1057
1060 void OnPingTTL(int ping, int* out) { 1058 void OnPingTTL(int ping, int* out) {
1061 *out = ping; 1059 *out = ping;
1062 wait_event_->Wait(); 1060 wait_event_->Wait();
1063 } 1061 }
1064 1062
1065 base::Thread* ListenerThread() { return Worker::ListenerThread(); } 1063 base::Thread* ListenerThread() { return Worker::ListenerThread(); }
1066 1064
1067 private: 1065 private:
1068 virtual bool OnMessageReceived(const Message& message) override { 1066 bool OnMessageReceived(const Message& message) override {
1069 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchServer, message) 1067 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchServer, message)
1070 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1068 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1071 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_PingTTL, OnPingTTL) 1069 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_PingTTL, OnPingTTL)
1072 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done) 1070 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done)
1073 IPC_END_MESSAGE_MAP() 1071 IPC_END_MESSAGE_MAP()
1074 return true; 1072 return true;
1075 } 1073 }
1076 1074
1077 void OnPingSent() { 1075 void OnPingSent() {
1078 sent_ping_event_->Signal(); 1076 sent_ping_event_->Signal();
(...skipping 12 matching lines...) Expand all
1091 1089
1092 base::Thread* ListenerThread() { return Worker::ListenerThread(); } 1090 base::Thread* ListenerThread() { return Worker::ListenerThread(); }
1093 1091
1094 void OnDoPingTTL(int ping) { 1092 void OnDoPingTTL(int ping) {
1095 int value = 0; 1093 int value = 0;
1096 Send(new SyncChannelTestMsg_PingTTL(ping, &value)); 1094 Send(new SyncChannelTestMsg_PingTTL(ping, &value));
1097 signal_event_->Signal(); 1095 signal_event_->Signal();
1098 } 1096 }
1099 1097
1100 private: 1098 private:
1101 virtual bool OnMessageReceived(const Message& message) override { 1099 bool OnMessageReceived(const Message& message) override {
1102 IPC_BEGIN_MESSAGE_MAP(NonRestrictedDispatchServer, message) 1100 IPC_BEGIN_MESSAGE_MAP(NonRestrictedDispatchServer, message)
1103 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1101 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1104 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done) 1102 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done)
1105 IPC_END_MESSAGE_MAP() 1103 IPC_END_MESSAGE_MAP()
1106 return true; 1104 return true;
1107 } 1105 }
1108 1106
1109 void OnNoArgs() { } 1107 void OnNoArgs() { }
1110 WaitableEvent* signal_event_; 1108 WaitableEvent* signal_event_;
1111 }; 1109 };
1112 1110
1113 class RestrictedDispatchClient : public Worker { 1111 class RestrictedDispatchClient : public Worker {
1114 public: 1112 public:
1115 RestrictedDispatchClient(WaitableEvent* sent_ping_event, 1113 RestrictedDispatchClient(WaitableEvent* sent_ping_event,
1116 RestrictedDispatchServer* server, 1114 RestrictedDispatchServer* server,
1117 NonRestrictedDispatchServer* server2, 1115 NonRestrictedDispatchServer* server2,
1118 int* success) 1116 int* success)
1119 : Worker("restricted_channel", Channel::MODE_CLIENT), 1117 : Worker("restricted_channel", Channel::MODE_CLIENT),
1120 ping_(0), 1118 ping_(0),
1121 server_(server), 1119 server_(server),
1122 server2_(server2), 1120 server2_(server2),
1123 success_(success), 1121 success_(success),
1124 sent_ping_event_(sent_ping_event) {} 1122 sent_ping_event_(sent_ping_event) {}
1125 1123
1126 virtual void Run() override { 1124 void Run() override {
1127 // Incoming messages from our channel should only be dispatched when we 1125 // Incoming messages from our channel should only be dispatched when we
1128 // send a message on that same channel. 1126 // send a message on that same channel.
1129 channel()->SetRestrictDispatchChannelGroup(1); 1127 channel()->SetRestrictDispatchChannelGroup(1);
1130 1128
1131 server_->ListenerThread()->message_loop()->PostTask( 1129 server_->ListenerThread()->message_loop()->PostTask(
1132 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1)); 1130 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1));
1133 sent_ping_event_->Wait(); 1131 sent_ping_event_->Wait();
1134 Send(new SyncChannelTestMsg_NoArgs); 1132 Send(new SyncChannelTestMsg_NoArgs);
1135 if (ping_ == 1) 1133 if (ping_ == 1)
1136 ++*success_; 1134 ++*success_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 else 1178 else
1181 LOG(ERROR) << "Send failed to dispatch message from unrestricted channel"; 1179 LOG(ERROR) << "Send failed to dispatch message from unrestricted channel";
1182 1180
1183 non_restricted_channel_->Send(new SyncChannelTestMsg_Done); 1181 non_restricted_channel_->Send(new SyncChannelTestMsg_Done);
1184 non_restricted_channel_.reset(); 1182 non_restricted_channel_.reset();
1185 Send(new SyncChannelTestMsg_Done); 1183 Send(new SyncChannelTestMsg_Done);
1186 Done(); 1184 Done();
1187 } 1185 }
1188 1186
1189 private: 1187 private:
1190 virtual bool OnMessageReceived(const Message& message) override { 1188 bool OnMessageReceived(const Message& message) override {
1191 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchClient, message) 1189 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchClient, message)
1192 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Ping, OnPing) 1190 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Ping, OnPing)
1193 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_PingTTL, OnPingTTL) 1191 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_PingTTL, OnPingTTL)
1194 IPC_END_MESSAGE_MAP() 1192 IPC_END_MESSAGE_MAP()
1195 return true; 1193 return true;
1196 } 1194 }
1197 1195
1198 void OnPing(int ping) { 1196 void OnPing(int ping) {
1199 ping_ = ping; 1197 ping_ = ping;
1200 } 1198 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 events_(events), 1272 events_(events),
1275 peer_(peer) { } 1273 peer_(peer) { }
1276 1274
1277 void OnDoServerTask() { 1275 void OnDoServerTask() {
1278 events_[3]->Signal(); 1276 events_[3]->Signal();
1279 events_[2]->Wait(); 1277 events_[2]->Wait();
1280 events_[0]->Signal(); 1278 events_[0]->Signal();
1281 SendMessageToClient(); 1279 SendMessageToClient();
1282 } 1280 }
1283 1281
1284 virtual void Run() override { 1282 void Run() override {
1285 channel()->SetRestrictDispatchChannelGroup(1); 1283 channel()->SetRestrictDispatchChannelGroup(1);
1286 server_ready_event_->Signal(); 1284 server_ready_event_->Signal();
1287 } 1285 }
1288 1286
1289 base::Thread* ListenerThread() { return Worker::ListenerThread(); } 1287 base::Thread* ListenerThread() { return Worker::ListenerThread(); }
1290 1288
1291 private: 1289 private:
1292 virtual bool OnMessageReceived(const Message& message) override { 1290 bool OnMessageReceived(const Message& message) override {
1293 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockServer, message) 1291 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockServer, message)
1294 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1292 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1295 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done) 1293 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done)
1296 IPC_END_MESSAGE_MAP() 1294 IPC_END_MESSAGE_MAP()
1297 return true; 1295 return true;
1298 } 1296 }
1299 1297
1300 void OnNoArgs() { 1298 void OnNoArgs() {
1301 if (server_num_ == 1) { 1299 if (server_num_ == 1) {
1302 DCHECK(peer_ != NULL); 1300 DCHECK(peer_ != NULL);
(...skipping 19 matching lines...) Expand all
1322 RestrictedDispatchDeadlockClient2(RestrictedDispatchDeadlockServer* server, 1320 RestrictedDispatchDeadlockClient2(RestrictedDispatchDeadlockServer* server,
1323 WaitableEvent* server_ready_event, 1321 WaitableEvent* server_ready_event,
1324 WaitableEvent** events) 1322 WaitableEvent** events)
1325 : Worker("channel2", Channel::MODE_CLIENT), 1323 : Worker("channel2", Channel::MODE_CLIENT),
1326 server_ready_event_(server_ready_event), 1324 server_ready_event_(server_ready_event),
1327 events_(events), 1325 events_(events),
1328 received_msg_(false), 1326 received_msg_(false),
1329 received_noarg_reply_(false), 1327 received_noarg_reply_(false),
1330 done_issued_(false) {} 1328 done_issued_(false) {}
1331 1329
1332 virtual void Run() override { 1330 void Run() override { server_ready_event_->Wait(); }
1333 server_ready_event_->Wait();
1334 }
1335 1331
1336 void OnDoClient2Task() { 1332 void OnDoClient2Task() {
1337 events_[3]->Wait(); 1333 events_[3]->Wait();
1338 events_[1]->Signal(); 1334 events_[1]->Signal();
1339 events_[2]->Signal(); 1335 events_[2]->Signal();
1340 DCHECK(received_msg_ == false); 1336 DCHECK(received_msg_ == false);
1341 1337
1342 Message* message = new SyncChannelTestMsg_NoArgs; 1338 Message* message = new SyncChannelTestMsg_NoArgs;
1343 message->set_unblock(true); 1339 message->set_unblock(true);
1344 Send(message); 1340 Send(message);
1345 received_noarg_reply_ = true; 1341 received_noarg_reply_ = true;
1346 } 1342 }
1347 1343
1348 base::Thread* ListenerThread() { return Worker::ListenerThread(); } 1344 base::Thread* ListenerThread() { return Worker::ListenerThread(); }
1349 private: 1345 private:
1350 virtual bool OnMessageReceived(const Message& message) override { 1346 bool OnMessageReceived(const Message& message) override {
1351 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockClient2, message) 1347 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockClient2, message)
1352 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1348 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1353 IPC_END_MESSAGE_MAP() 1349 IPC_END_MESSAGE_MAP()
1354 return true; 1350 return true;
1355 } 1351 }
1356 1352
1357 void OnNoArgs() { 1353 void OnNoArgs() {
1358 received_msg_ = true; 1354 received_msg_ = true;
1359 PossiblyDone(); 1355 PossiblyDone();
1360 } 1356 }
(...skipping 22 matching lines...) Expand all
1383 WaitableEvent** events) 1379 WaitableEvent** events)
1384 : Worker("channel1", Channel::MODE_CLIENT), 1380 : Worker("channel1", Channel::MODE_CLIENT),
1385 server_(server), 1381 server_(server),
1386 peer_(peer), 1382 peer_(peer),
1387 server_ready_event_(server_ready_event), 1383 server_ready_event_(server_ready_event),
1388 events_(events), 1384 events_(events),
1389 received_msg_(false), 1385 received_msg_(false),
1390 received_noarg_reply_(false), 1386 received_noarg_reply_(false),
1391 done_issued_(false) {} 1387 done_issued_(false) {}
1392 1388
1393 virtual void Run() override { 1389 void Run() override {
1394 server_ready_event_->Wait(); 1390 server_ready_event_->Wait();
1395 server_->ListenerThread()->message_loop()->PostTask( 1391 server_->ListenerThread()->message_loop()->PostTask(
1396 FROM_HERE, 1392 FROM_HERE,
1397 base::Bind(&RestrictedDispatchDeadlockServer::OnDoServerTask, server_)); 1393 base::Bind(&RestrictedDispatchDeadlockServer::OnDoServerTask, server_));
1398 peer_->ListenerThread()->message_loop()->PostTask( 1394 peer_->ListenerThread()->message_loop()->PostTask(
1399 FROM_HERE, 1395 FROM_HERE,
1400 base::Bind(&RestrictedDispatchDeadlockClient2::OnDoClient2Task, peer_)); 1396 base::Bind(&RestrictedDispatchDeadlockClient2::OnDoClient2Task, peer_));
1401 events_[0]->Wait(); 1397 events_[0]->Wait();
1402 events_[1]->Wait(); 1398 events_[1]->Wait();
1403 DCHECK(received_msg_ == false); 1399 DCHECK(received_msg_ == false);
1404 1400
1405 Message* message = new SyncChannelTestMsg_NoArgs; 1401 Message* message = new SyncChannelTestMsg_NoArgs;
1406 message->set_unblock(true); 1402 message->set_unblock(true);
1407 Send(message); 1403 Send(message);
1408 received_noarg_reply_ = true; 1404 received_noarg_reply_ = true;
1409 PossiblyDone(); 1405 PossiblyDone();
1410 } 1406 }
1411 1407
1412 private: 1408 private:
1413 virtual bool OnMessageReceived(const Message& message) override { 1409 bool OnMessageReceived(const Message& message) override {
1414 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockClient1, message) 1410 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockClient1, message)
1415 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1411 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1416 IPC_END_MESSAGE_MAP() 1412 IPC_END_MESSAGE_MAP()
1417 return true; 1413 return true;
1418 } 1414 }
1419 1415
1420 void OnNoArgs() { 1416 void OnNoArgs() {
1421 received_msg_ = true; 1417 received_msg_ = true;
1422 PossiblyDone(); 1418 PossiblyDone();
1423 } 1419 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 } 1512 }
1517 1513
1518 void OnDone() { 1514 void OnDone() {
1519 if (is_first()) 1515 if (is_first())
1520 return; 1516 return;
1521 other_channel_->Send(new SyncChannelTestMsg_Done); 1517 other_channel_->Send(new SyncChannelTestMsg_Done);
1522 other_channel_.reset(); 1518 other_channel_.reset();
1523 Done(); 1519 Done();
1524 } 1520 }
1525 1521
1526 virtual void Run() override { 1522 void Run() override {
1527 channel()->SetRestrictDispatchChannelGroup(group_); 1523 channel()->SetRestrictDispatchChannelGroup(group_);
1528 if (is_first()) 1524 if (is_first())
1529 event1_->Signal(); 1525 event1_->Signal();
1530 event2_->Wait(); 1526 event2_->Wait();
1531 other_channel_ = 1527 other_channel_ =
1532 SyncChannel::Create(other_channel_name_, 1528 SyncChannel::Create(other_channel_name_,
1533 IPC::Channel::MODE_CLIENT, 1529 IPC::Channel::MODE_CLIENT,
1534 this, 1530 this,
1535 ipc_thread().message_loop_proxy().get(), 1531 ipc_thread().message_loop_proxy().get(),
1536 true, 1532 true,
(...skipping 12 matching lines...) Expand all
1549 OnPingTTL(5, &value); 1545 OnPingTTL(5, &value);
1550 *success_ += (value == 5); 1546 *success_ += (value == 5);
1551 other_channel_->Send(new SyncChannelTestMsg_Done); 1547 other_channel_->Send(new SyncChannelTestMsg_Done);
1552 other_channel_.reset(); 1548 other_channel_.reset();
1553 Done(); 1549 Done();
1554 } 1550 }
1555 1551
1556 bool is_first() { return !!success_; } 1552 bool is_first() { return !!success_; }
1557 1553
1558 private: 1554 private:
1559 virtual bool OnMessageReceived(const Message& message) override { 1555 bool OnMessageReceived(const Message& message) override {
1560 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchPipeWorker, message) 1556 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchPipeWorker, message)
1561 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_PingTTL, OnPingTTL) 1557 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_PingTTL, OnPingTTL)
1562 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, OnDone) 1558 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, OnDone)
1563 IPC_END_MESSAGE_MAP() 1559 IPC_END_MESSAGE_MAP()
1564 return true; 1560 return true;
1565 } 1561 }
1566 1562
1567 scoped_ptr<SyncChannel> other_channel_; 1563 scoped_ptr<SyncChannel> other_channel_;
1568 WaitableEvent* event1_; 1564 WaitableEvent* event1_;
1569 WaitableEvent* event2_; 1565 WaitableEvent* event2_;
(...skipping 30 matching lines...) Expand all
1600 // during which it will dispatch a message comming from Client, at which point 1596 // during which it will dispatch a message comming from Client, at which point
1601 // it will send another message to Server2. While sending that second message it 1597 // it will send another message to Server2. While sending that second message it
1602 // will receive a reply from Server1 with the unblock flag. 1598 // will receive a reply from Server1 with the unblock flag.
1603 1599
1604 class ReentrantReplyServer1 : public Worker { 1600 class ReentrantReplyServer1 : public Worker {
1605 public: 1601 public:
1606 ReentrantReplyServer1(WaitableEvent* server_ready) 1602 ReentrantReplyServer1(WaitableEvent* server_ready)
1607 : Worker("reentrant_reply1", Channel::MODE_SERVER), 1603 : Worker("reentrant_reply1", Channel::MODE_SERVER),
1608 server_ready_(server_ready) { } 1604 server_ready_(server_ready) { }
1609 1605
1610 virtual void Run() override { 1606 void Run() override {
1611 server2_channel_ = 1607 server2_channel_ =
1612 SyncChannel::Create("reentrant_reply2", 1608 SyncChannel::Create("reentrant_reply2",
1613 IPC::Channel::MODE_CLIENT, 1609 IPC::Channel::MODE_CLIENT,
1614 this, 1610 this,
1615 ipc_thread().message_loop_proxy().get(), 1611 ipc_thread().message_loop_proxy().get(),
1616 true, 1612 true,
1617 shutdown_event()); 1613 shutdown_event());
1618 server_ready_->Signal(); 1614 server_ready_->Signal();
1619 Message* msg = new SyncChannelTestMsg_Reentrant1(); 1615 Message* msg = new SyncChannelTestMsg_Reentrant1();
1620 server2_channel_->Send(msg); 1616 server2_channel_->Send(msg);
1621 server2_channel_.reset(); 1617 server2_channel_.reset();
1622 Done(); 1618 Done();
1623 } 1619 }
1624 1620
1625 private: 1621 private:
1626 virtual bool OnMessageReceived(const Message& message) override { 1622 bool OnMessageReceived(const Message& message) override {
1627 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message) 1623 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message)
1628 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant2, OnReentrant2) 1624 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant2, OnReentrant2)
1629 IPC_REPLY_HANDLER(OnReply) 1625 IPC_REPLY_HANDLER(OnReply)
1630 IPC_END_MESSAGE_MAP() 1626 IPC_END_MESSAGE_MAP()
1631 return true; 1627 return true;
1632 } 1628 }
1633 1629
1634 void OnReentrant2() { 1630 void OnReentrant2() {
1635 Message* msg = new SyncChannelTestMsg_Reentrant3(); 1631 Message* msg = new SyncChannelTestMsg_Reentrant3();
1636 server2_channel_->Send(msg); 1632 server2_channel_->Send(msg);
1637 } 1633 }
1638 1634
1639 void OnReply(const Message& message) { 1635 void OnReply(const Message& message) {
1640 // If we get here, the Send() will never receive the reply (thus would 1636 // If we get here, the Send() will never receive the reply (thus would
1641 // hang), so abort instead. 1637 // hang), so abort instead.
1642 LOG(FATAL) << "Reply message was dispatched"; 1638 LOG(FATAL) << "Reply message was dispatched";
1643 } 1639 }
1644 1640
1645 WaitableEvent* server_ready_; 1641 WaitableEvent* server_ready_;
1646 scoped_ptr<SyncChannel> server2_channel_; 1642 scoped_ptr<SyncChannel> server2_channel_;
1647 }; 1643 };
1648 1644
1649 class ReentrantReplyServer2 : public Worker { 1645 class ReentrantReplyServer2 : public Worker {
1650 public: 1646 public:
1651 ReentrantReplyServer2() 1647 ReentrantReplyServer2()
1652 : Worker("reentrant_reply2", Channel::MODE_SERVER), 1648 : Worker("reentrant_reply2", Channel::MODE_SERVER),
1653 reply_(NULL) { } 1649 reply_(NULL) { }
1654 1650
1655 private: 1651 private:
1656 virtual bool OnMessageReceived(const Message& message) override { 1652 bool OnMessageReceived(const Message& message) override {
1657 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer2, message) 1653 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer2, message)
1658 IPC_MESSAGE_HANDLER_DELAY_REPLY( 1654 IPC_MESSAGE_HANDLER_DELAY_REPLY(
1659 SyncChannelTestMsg_Reentrant1, OnReentrant1) 1655 SyncChannelTestMsg_Reentrant1, OnReentrant1)
1660 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant3, OnReentrant3) 1656 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant3, OnReentrant3)
1661 IPC_END_MESSAGE_MAP() 1657 IPC_END_MESSAGE_MAP()
1662 return true; 1658 return true;
1663 } 1659 }
1664 1660
1665 void OnReentrant1(Message* reply) { 1661 void OnReentrant1(Message* reply) {
1666 DCHECK(!reply_); 1662 DCHECK(!reply_);
(...skipping 11 matching lines...) Expand all
1678 1674
1679 Message* reply_; 1675 Message* reply_;
1680 }; 1676 };
1681 1677
1682 class ReentrantReplyClient : public Worker { 1678 class ReentrantReplyClient : public Worker {
1683 public: 1679 public:
1684 ReentrantReplyClient(WaitableEvent* server_ready) 1680 ReentrantReplyClient(WaitableEvent* server_ready)
1685 : Worker("reentrant_reply1", Channel::MODE_CLIENT), 1681 : Worker("reentrant_reply1", Channel::MODE_CLIENT),
1686 server_ready_(server_ready) { } 1682 server_ready_(server_ready) { }
1687 1683
1688 virtual void Run() override { 1684 void Run() override {
1689 server_ready_->Wait(); 1685 server_ready_->Wait();
1690 Send(new SyncChannelTestMsg_Reentrant2()); 1686 Send(new SyncChannelTestMsg_Reentrant2());
1691 Done(); 1687 Done();
1692 } 1688 }
1693 1689
1694 private: 1690 private:
1695 WaitableEvent* server_ready_; 1691 WaitableEvent* server_ready_;
1696 }; 1692 };
1697 1693
1698 TEST_F(IPCSyncChannelTest, ReentrantReply) { 1694 TEST_F(IPCSyncChannelTest, ReentrantReply) {
(...skipping 12 matching lines...) Expand all
1711 class VerifiedServer : public Worker { 1707 class VerifiedServer : public Worker {
1712 public: 1708 public:
1713 VerifiedServer(base::Thread* listener_thread, 1709 VerifiedServer(base::Thread* listener_thread,
1714 const std::string& channel_name, 1710 const std::string& channel_name,
1715 const std::string& reply_text) 1711 const std::string& reply_text)
1716 : Worker(channel_name, Channel::MODE_SERVER), 1712 : Worker(channel_name, Channel::MODE_SERVER),
1717 reply_text_(reply_text) { 1713 reply_text_(reply_text) {
1718 Worker::OverrideThread(listener_thread); 1714 Worker::OverrideThread(listener_thread);
1719 } 1715 }
1720 1716
1721 virtual void OnNestedTestMsg(Message* reply_msg) override { 1717 void OnNestedTestMsg(Message* reply_msg) override {
1722 VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_; 1718 VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_;
1723 SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_); 1719 SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_);
1724 Send(reply_msg); 1720 Send(reply_msg);
1725 ASSERT_EQ(channel()->GetPeerPID(), base::GetCurrentProcId()); 1721 ASSERT_EQ(channel()->GetPeerPID(), base::GetCurrentProcId());
1726 Done(); 1722 Done();
1727 } 1723 }
1728 1724
1729 private: 1725 private:
1730 std::string reply_text_; 1726 std::string reply_text_;
1731 }; 1727 };
1732 1728
1733 class VerifiedClient : public Worker { 1729 class VerifiedClient : public Worker {
1734 public: 1730 public:
1735 VerifiedClient(base::Thread* listener_thread, 1731 VerifiedClient(base::Thread* listener_thread,
1736 const std::string& channel_name, 1732 const std::string& channel_name,
1737 const std::string& expected_text) 1733 const std::string& expected_text)
1738 : Worker(channel_name, Channel::MODE_CLIENT), 1734 : Worker(channel_name, Channel::MODE_CLIENT),
1739 expected_text_(expected_text) { 1735 expected_text_(expected_text) {
1740 Worker::OverrideThread(listener_thread); 1736 Worker::OverrideThread(listener_thread);
1741 } 1737 }
1742 1738
1743 virtual void Run() override { 1739 void Run() override {
1744 std::string response; 1740 std::string response;
1745 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response); 1741 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response);
1746 bool result = Send(msg); 1742 bool result = Send(msg);
1747 DCHECK(result); 1743 DCHECK(result);
1748 DCHECK_EQ(response, expected_text_); 1744 DCHECK_EQ(response, expected_text_);
1749 // expected_text_ is only used in the above DCHECK. This line suppresses the 1745 // expected_text_ is only used in the above DCHECK. This line suppresses the
1750 // "unused private field" warning in release builds. 1746 // "unused private field" warning in release builds.
1751 (void)expected_text_; 1747 (void)expected_text_;
1752 1748
1753 VLOG(1) << __FUNCTION__ << " Received reply: " << response; 1749 VLOG(1) << __FUNCTION__ << " Received reply: " << response;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 } 1782 }
1787 1783
1788 // Windows needs to send an out-of-band secret to verify the client end of the 1784 // Windows needs to send an out-of-band secret to verify the client end of the
1789 // channel. Test that we still connect correctly in that case. 1785 // channel. Test that we still connect correctly in that case.
1790 TEST_F(IPCSyncChannelTest, Verified) { 1786 TEST_F(IPCSyncChannelTest, Verified) {
1791 Verified(); 1787 Verified();
1792 } 1788 }
1793 1789
1794 } // namespace 1790 } // namespace
1795 } // namespace IPC 1791 } // namespace IPC
OLDNEW
« ipc/ipc_send_fds_test.cc ('K') | « ipc/ipc_sync_channel.h ('k') | ipc/ipc_sync_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698