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

Side by Side Diff: ipc/ipc_sync_channel_unittest.cc

Issue 666493005: 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
« no previous file with comments | « ipc/ipc_sync_channel.h ('k') | ipc/ipc_sync_message.h » ('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 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 {
973 channel()->AddFilter(filter_.get()); 973 channel()->AddFilter(filter_.get());
974 } 974 }
975 975
976 base::Thread thread_; 976 base::Thread thread_;
977 scoped_refptr<TestSyncMessageFilter> filter_; 977 scoped_refptr<TestSyncMessageFilter> filter_;
978 }; 978 };
979 979
980 // This class provides functionality to test the case that a Send on the sync 980 // 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. 981 // channel does not crash after the channel has been closed.
982 class ServerSendAfterClose : public Worker { 982 class ServerSendAfterClose : public Worker {
983 public: 983 public:
984 ServerSendAfterClose() 984 ServerSendAfterClose()
985 : Worker(Channel::MODE_SERVER, "simpler_server"), 985 : Worker(Channel::MODE_SERVER, "simpler_server"),
986 send_result_(true) { 986 send_result_(true) {
987 } 987 }
988 988
989 bool SendDummy() { 989 bool SendDummy() {
990 ListenerThread()->message_loop()->PostTask( 990 ListenerThread()->message_loop()->PostTask(
991 FROM_HERE, base::Bind(base::IgnoreResult(&ServerSendAfterClose::Send), 991 FROM_HERE, base::Bind(base::IgnoreResult(&ServerSendAfterClose::Send),
992 this, new SyncChannelTestMsg_NoArgs)); 992 this, new SyncChannelTestMsg_NoArgs));
993 return true; 993 return true;
994 } 994 }
995 995
996 bool send_result() const { 996 bool send_result() const {
997 return send_result_; 997 return send_result_;
998 } 998 }
999 999
1000 private: 1000 private:
1001 virtual void Run() override { 1001 void Run() override {
1002 CloseChannel(); 1002 CloseChannel();
1003 Done(); 1003 Done();
1004 } 1004 }
1005 1005
1006 virtual bool Send(Message* msg) override { 1006 bool Send(Message* msg) override {
1007 send_result_ = Worker::Send(msg); 1007 send_result_ = Worker::Send(msg);
1008 Done(); 1008 Done();
1009 return send_result_; 1009 return send_result_;
1010 } 1010 }
1011 1011
1012 bool send_result_; 1012 bool send_result_;
1013 }; 1013 };
1014 1014
1015 // Tests basic synchronous call 1015 // Tests basic synchronous call
1016 TEST_F(IPCSyncChannelTest, SyncMessageFilter) { 1016 TEST_F(IPCSyncChannelTest, SyncMessageFilter) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 } 1058 }
1059 1059
1060 void OnPingTTL(int ping, int* out) { 1060 void OnPingTTL(int ping, int* out) {
1061 *out = ping; 1061 *out = ping;
1062 wait_event_->Wait(); 1062 wait_event_->Wait();
1063 } 1063 }
1064 1064
1065 base::Thread* ListenerThread() { return Worker::ListenerThread(); } 1065 base::Thread* ListenerThread() { return Worker::ListenerThread(); }
1066 1066
1067 private: 1067 private:
1068 virtual bool OnMessageReceived(const Message& message) override { 1068 bool OnMessageReceived(const Message& message) override {
1069 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchServer, message) 1069 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchServer, message)
1070 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1070 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1071 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_PingTTL, OnPingTTL) 1071 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_PingTTL, OnPingTTL)
1072 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done) 1072 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done)
1073 IPC_END_MESSAGE_MAP() 1073 IPC_END_MESSAGE_MAP()
1074 return true; 1074 return true;
1075 } 1075 }
1076 1076
1077 void OnPingSent() { 1077 void OnPingSent() {
1078 sent_ping_event_->Signal(); 1078 sent_ping_event_->Signal();
(...skipping 12 matching lines...) Expand all
1091 1091
1092 base::Thread* ListenerThread() { return Worker::ListenerThread(); } 1092 base::Thread* ListenerThread() { return Worker::ListenerThread(); }
1093 1093
1094 void OnDoPingTTL(int ping) { 1094 void OnDoPingTTL(int ping) {
1095 int value = 0; 1095 int value = 0;
1096 Send(new SyncChannelTestMsg_PingTTL(ping, &value)); 1096 Send(new SyncChannelTestMsg_PingTTL(ping, &value));
1097 signal_event_->Signal(); 1097 signal_event_->Signal();
1098 } 1098 }
1099 1099
1100 private: 1100 private:
1101 virtual bool OnMessageReceived(const Message& message) override { 1101 bool OnMessageReceived(const Message& message) override {
1102 IPC_BEGIN_MESSAGE_MAP(NonRestrictedDispatchServer, message) 1102 IPC_BEGIN_MESSAGE_MAP(NonRestrictedDispatchServer, message)
1103 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1103 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1104 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done) 1104 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done)
1105 IPC_END_MESSAGE_MAP() 1105 IPC_END_MESSAGE_MAP()
1106 return true; 1106 return true;
1107 } 1107 }
1108 1108
1109 void OnNoArgs() { } 1109 void OnNoArgs() { }
1110 WaitableEvent* signal_event_; 1110 WaitableEvent* signal_event_;
1111 }; 1111 };
1112 1112
1113 class RestrictedDispatchClient : public Worker { 1113 class RestrictedDispatchClient : public Worker {
1114 public: 1114 public:
1115 RestrictedDispatchClient(WaitableEvent* sent_ping_event, 1115 RestrictedDispatchClient(WaitableEvent* sent_ping_event,
1116 RestrictedDispatchServer* server, 1116 RestrictedDispatchServer* server,
1117 NonRestrictedDispatchServer* server2, 1117 NonRestrictedDispatchServer* server2,
1118 int* success) 1118 int* success)
1119 : Worker("restricted_channel", Channel::MODE_CLIENT), 1119 : Worker("restricted_channel", Channel::MODE_CLIENT),
1120 ping_(0), 1120 ping_(0),
1121 server_(server), 1121 server_(server),
1122 server2_(server2), 1122 server2_(server2),
1123 success_(success), 1123 success_(success),
1124 sent_ping_event_(sent_ping_event) {} 1124 sent_ping_event_(sent_ping_event) {}
1125 1125
1126 virtual void Run() override { 1126 void Run() override {
1127 // Incoming messages from our channel should only be dispatched when we 1127 // Incoming messages from our channel should only be dispatched when we
1128 // send a message on that same channel. 1128 // send a message on that same channel.
1129 channel()->SetRestrictDispatchChannelGroup(1); 1129 channel()->SetRestrictDispatchChannelGroup(1);
1130 1130
1131 server_->ListenerThread()->message_loop()->PostTask( 1131 server_->ListenerThread()->message_loop()->PostTask(
1132 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1)); 1132 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1));
1133 sent_ping_event_->Wait(); 1133 sent_ping_event_->Wait();
1134 Send(new SyncChannelTestMsg_NoArgs); 1134 Send(new SyncChannelTestMsg_NoArgs);
1135 if (ping_ == 1) 1135 if (ping_ == 1)
1136 ++*success_; 1136 ++*success_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 else 1180 else
1181 LOG(ERROR) << "Send failed to dispatch message from unrestricted channel"; 1181 LOG(ERROR) << "Send failed to dispatch message from unrestricted channel";
1182 1182
1183 non_restricted_channel_->Send(new SyncChannelTestMsg_Done); 1183 non_restricted_channel_->Send(new SyncChannelTestMsg_Done);
1184 non_restricted_channel_.reset(); 1184 non_restricted_channel_.reset();
1185 Send(new SyncChannelTestMsg_Done); 1185 Send(new SyncChannelTestMsg_Done);
1186 Done(); 1186 Done();
1187 } 1187 }
1188 1188
1189 private: 1189 private:
1190 virtual bool OnMessageReceived(const Message& message) override { 1190 bool OnMessageReceived(const Message& message) override {
1191 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchClient, message) 1191 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchClient, message)
1192 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Ping, OnPing) 1192 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Ping, OnPing)
1193 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_PingTTL, OnPingTTL) 1193 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_PingTTL, OnPingTTL)
1194 IPC_END_MESSAGE_MAP() 1194 IPC_END_MESSAGE_MAP()
1195 return true; 1195 return true;
1196 } 1196 }
1197 1197
1198 void OnPing(int ping) { 1198 void OnPing(int ping) {
1199 ping_ = ping; 1199 ping_ = ping;
1200 } 1200 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 events_(events), 1274 events_(events),
1275 peer_(peer) { } 1275 peer_(peer) { }
1276 1276
1277 void OnDoServerTask() { 1277 void OnDoServerTask() {
1278 events_[3]->Signal(); 1278 events_[3]->Signal();
1279 events_[2]->Wait(); 1279 events_[2]->Wait();
1280 events_[0]->Signal(); 1280 events_[0]->Signal();
1281 SendMessageToClient(); 1281 SendMessageToClient();
1282 } 1282 }
1283 1283
1284 virtual void Run() override { 1284 void Run() override {
1285 channel()->SetRestrictDispatchChannelGroup(1); 1285 channel()->SetRestrictDispatchChannelGroup(1);
1286 server_ready_event_->Signal(); 1286 server_ready_event_->Signal();
1287 } 1287 }
1288 1288
1289 base::Thread* ListenerThread() { return Worker::ListenerThread(); } 1289 base::Thread* ListenerThread() { return Worker::ListenerThread(); }
1290 1290
1291 private: 1291 private:
1292 virtual bool OnMessageReceived(const Message& message) override { 1292 bool OnMessageReceived(const Message& message) override {
1293 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockServer, message) 1293 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockServer, message)
1294 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1294 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1295 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done) 1295 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, Done)
1296 IPC_END_MESSAGE_MAP() 1296 IPC_END_MESSAGE_MAP()
1297 return true; 1297 return true;
1298 } 1298 }
1299 1299
1300 void OnNoArgs() { 1300 void OnNoArgs() {
1301 if (server_num_ == 1) { 1301 if (server_num_ == 1) {
1302 DCHECK(peer_ != NULL); 1302 DCHECK(peer_ != NULL);
(...skipping 19 matching lines...) Expand all
1322 RestrictedDispatchDeadlockClient2(RestrictedDispatchDeadlockServer* server, 1322 RestrictedDispatchDeadlockClient2(RestrictedDispatchDeadlockServer* server,
1323 WaitableEvent* server_ready_event, 1323 WaitableEvent* server_ready_event,
1324 WaitableEvent** events) 1324 WaitableEvent** events)
1325 : Worker("channel2", Channel::MODE_CLIENT), 1325 : Worker("channel2", Channel::MODE_CLIENT),
1326 server_ready_event_(server_ready_event), 1326 server_ready_event_(server_ready_event),
1327 events_(events), 1327 events_(events),
1328 received_msg_(false), 1328 received_msg_(false),
1329 received_noarg_reply_(false), 1329 received_noarg_reply_(false),
1330 done_issued_(false) {} 1330 done_issued_(false) {}
1331 1331
1332 virtual void Run() override { 1332 void Run() override {
1333 server_ready_event_->Wait(); 1333 server_ready_event_->Wait();
1334 } 1334 }
1335 1335
1336 void OnDoClient2Task() { 1336 void OnDoClient2Task() {
1337 events_[3]->Wait(); 1337 events_[3]->Wait();
1338 events_[1]->Signal(); 1338 events_[1]->Signal();
1339 events_[2]->Signal(); 1339 events_[2]->Signal();
1340 DCHECK(received_msg_ == false); 1340 DCHECK(received_msg_ == false);
1341 1341
1342 Message* message = new SyncChannelTestMsg_NoArgs; 1342 Message* message = new SyncChannelTestMsg_NoArgs;
1343 message->set_unblock(true); 1343 message->set_unblock(true);
1344 Send(message); 1344 Send(message);
1345 received_noarg_reply_ = true; 1345 received_noarg_reply_ = true;
1346 } 1346 }
1347 1347
1348 base::Thread* ListenerThread() { return Worker::ListenerThread(); } 1348 base::Thread* ListenerThread() { return Worker::ListenerThread(); }
1349 private: 1349 private:
1350 virtual bool OnMessageReceived(const Message& message) override { 1350 bool OnMessageReceived(const Message& message) override {
1351 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockClient2, message) 1351 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockClient2, message)
1352 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1352 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1353 IPC_END_MESSAGE_MAP() 1353 IPC_END_MESSAGE_MAP()
1354 return true; 1354 return true;
1355 } 1355 }
1356 1356
1357 void OnNoArgs() { 1357 void OnNoArgs() {
1358 received_msg_ = true; 1358 received_msg_ = true;
1359 PossiblyDone(); 1359 PossiblyDone();
1360 } 1360 }
(...skipping 22 matching lines...) Expand all
1383 WaitableEvent** events) 1383 WaitableEvent** events)
1384 : Worker("channel1", Channel::MODE_CLIENT), 1384 : Worker("channel1", Channel::MODE_CLIENT),
1385 server_(server), 1385 server_(server),
1386 peer_(peer), 1386 peer_(peer),
1387 server_ready_event_(server_ready_event), 1387 server_ready_event_(server_ready_event),
1388 events_(events), 1388 events_(events),
1389 received_msg_(false), 1389 received_msg_(false),
1390 received_noarg_reply_(false), 1390 received_noarg_reply_(false),
1391 done_issued_(false) {} 1391 done_issued_(false) {}
1392 1392
1393 virtual void Run() override { 1393 void Run() override {
1394 server_ready_event_->Wait(); 1394 server_ready_event_->Wait();
1395 server_->ListenerThread()->message_loop()->PostTask( 1395 server_->ListenerThread()->message_loop()->PostTask(
1396 FROM_HERE, 1396 FROM_HERE,
1397 base::Bind(&RestrictedDispatchDeadlockServer::OnDoServerTask, server_)); 1397 base::Bind(&RestrictedDispatchDeadlockServer::OnDoServerTask, server_));
1398 peer_->ListenerThread()->message_loop()->PostTask( 1398 peer_->ListenerThread()->message_loop()->PostTask(
1399 FROM_HERE, 1399 FROM_HERE,
1400 base::Bind(&RestrictedDispatchDeadlockClient2::OnDoClient2Task, peer_)); 1400 base::Bind(&RestrictedDispatchDeadlockClient2::OnDoClient2Task, peer_));
1401 events_[0]->Wait(); 1401 events_[0]->Wait();
1402 events_[1]->Wait(); 1402 events_[1]->Wait();
1403 DCHECK(received_msg_ == false); 1403 DCHECK(received_msg_ == false);
1404 1404
1405 Message* message = new SyncChannelTestMsg_NoArgs; 1405 Message* message = new SyncChannelTestMsg_NoArgs;
1406 message->set_unblock(true); 1406 message->set_unblock(true);
1407 Send(message); 1407 Send(message);
1408 received_noarg_reply_ = true; 1408 received_noarg_reply_ = true;
1409 PossiblyDone(); 1409 PossiblyDone();
1410 } 1410 }
1411 1411
1412 private: 1412 private:
1413 virtual bool OnMessageReceived(const Message& message) override { 1413 bool OnMessageReceived(const Message& message) override {
1414 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockClient1, message) 1414 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchDeadlockClient1, message)
1415 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs) 1415 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_NoArgs, OnNoArgs)
1416 IPC_END_MESSAGE_MAP() 1416 IPC_END_MESSAGE_MAP()
1417 return true; 1417 return true;
1418 } 1418 }
1419 1419
1420 void OnNoArgs() { 1420 void OnNoArgs() {
1421 received_msg_ = true; 1421 received_msg_ = true;
1422 PossiblyDone(); 1422 PossiblyDone();
1423 } 1423 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 } 1516 }
1517 1517
1518 void OnDone() { 1518 void OnDone() {
1519 if (is_first()) 1519 if (is_first())
1520 return; 1520 return;
1521 other_channel_->Send(new SyncChannelTestMsg_Done); 1521 other_channel_->Send(new SyncChannelTestMsg_Done);
1522 other_channel_.reset(); 1522 other_channel_.reset();
1523 Done(); 1523 Done();
1524 } 1524 }
1525 1525
1526 virtual void Run() override { 1526 void Run() override {
1527 channel()->SetRestrictDispatchChannelGroup(group_); 1527 channel()->SetRestrictDispatchChannelGroup(group_);
1528 if (is_first()) 1528 if (is_first())
1529 event1_->Signal(); 1529 event1_->Signal();
1530 event2_->Wait(); 1530 event2_->Wait();
1531 other_channel_ = 1531 other_channel_ =
1532 SyncChannel::Create(other_channel_name_, 1532 SyncChannel::Create(other_channel_name_,
1533 IPC::Channel::MODE_CLIENT, 1533 IPC::Channel::MODE_CLIENT,
1534 this, 1534 this,
1535 ipc_thread().message_loop_proxy().get(), 1535 ipc_thread().message_loop_proxy().get(),
1536 true, 1536 true,
(...skipping 12 matching lines...) Expand all
1549 OnPingTTL(5, &value); 1549 OnPingTTL(5, &value);
1550 *success_ += (value == 5); 1550 *success_ += (value == 5);
1551 other_channel_->Send(new SyncChannelTestMsg_Done); 1551 other_channel_->Send(new SyncChannelTestMsg_Done);
1552 other_channel_.reset(); 1552 other_channel_.reset();
1553 Done(); 1553 Done();
1554 } 1554 }
1555 1555
1556 bool is_first() { return !!success_; } 1556 bool is_first() { return !!success_; }
1557 1557
1558 private: 1558 private:
1559 virtual bool OnMessageReceived(const Message& message) override { 1559 bool OnMessageReceived(const Message& message) override {
1560 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchPipeWorker, message) 1560 IPC_BEGIN_MESSAGE_MAP(RestrictedDispatchPipeWorker, message)
1561 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_PingTTL, OnPingTTL) 1561 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_PingTTL, OnPingTTL)
1562 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, OnDone) 1562 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Done, OnDone)
1563 IPC_END_MESSAGE_MAP() 1563 IPC_END_MESSAGE_MAP()
1564 return true; 1564 return true;
1565 } 1565 }
1566 1566
1567 scoped_ptr<SyncChannel> other_channel_; 1567 scoped_ptr<SyncChannel> other_channel_;
1568 WaitableEvent* event1_; 1568 WaitableEvent* event1_;
1569 WaitableEvent* event2_; 1569 WaitableEvent* event2_;
(...skipping 30 matching lines...) Expand all
1600 // during which it will dispatch a message comming from Client, at which point 1600 // 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 1601 // it will send another message to Server2. While sending that second message it
1602 // will receive a reply from Server1 with the unblock flag. 1602 // will receive a reply from Server1 with the unblock flag.
1603 1603
1604 class ReentrantReplyServer1 : public Worker { 1604 class ReentrantReplyServer1 : public Worker {
1605 public: 1605 public:
1606 ReentrantReplyServer1(WaitableEvent* server_ready) 1606 ReentrantReplyServer1(WaitableEvent* server_ready)
1607 : Worker("reentrant_reply1", Channel::MODE_SERVER), 1607 : Worker("reentrant_reply1", Channel::MODE_SERVER),
1608 server_ready_(server_ready) { } 1608 server_ready_(server_ready) { }
1609 1609
1610 virtual void Run() override { 1610 void Run() override {
1611 server2_channel_ = 1611 server2_channel_ =
1612 SyncChannel::Create("reentrant_reply2", 1612 SyncChannel::Create("reentrant_reply2",
1613 IPC::Channel::MODE_CLIENT, 1613 IPC::Channel::MODE_CLIENT,
1614 this, 1614 this,
1615 ipc_thread().message_loop_proxy().get(), 1615 ipc_thread().message_loop_proxy().get(),
1616 true, 1616 true,
1617 shutdown_event()); 1617 shutdown_event());
1618 server_ready_->Signal(); 1618 server_ready_->Signal();
1619 Message* msg = new SyncChannelTestMsg_Reentrant1(); 1619 Message* msg = new SyncChannelTestMsg_Reentrant1();
1620 server2_channel_->Send(msg); 1620 server2_channel_->Send(msg);
1621 server2_channel_.reset(); 1621 server2_channel_.reset();
1622 Done(); 1622 Done();
1623 } 1623 }
1624 1624
1625 private: 1625 private:
1626 virtual bool OnMessageReceived(const Message& message) override { 1626 bool OnMessageReceived(const Message& message) override {
1627 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message) 1627 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message)
1628 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant2, OnReentrant2) 1628 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant2, OnReentrant2)
1629 IPC_REPLY_HANDLER(OnReply) 1629 IPC_REPLY_HANDLER(OnReply)
1630 IPC_END_MESSAGE_MAP() 1630 IPC_END_MESSAGE_MAP()
1631 return true; 1631 return true;
1632 } 1632 }
1633 1633
1634 void OnReentrant2() { 1634 void OnReentrant2() {
1635 Message* msg = new SyncChannelTestMsg_Reentrant3(); 1635 Message* msg = new SyncChannelTestMsg_Reentrant3();
1636 server2_channel_->Send(msg); 1636 server2_channel_->Send(msg);
1637 } 1637 }
1638 1638
1639 void OnReply(const Message& message) { 1639 void OnReply(const Message& message) {
1640 // If we get here, the Send() will never receive the reply (thus would 1640 // If we get here, the Send() will never receive the reply (thus would
1641 // hang), so abort instead. 1641 // hang), so abort instead.
1642 LOG(FATAL) << "Reply message was dispatched"; 1642 LOG(FATAL) << "Reply message was dispatched";
1643 } 1643 }
1644 1644
1645 WaitableEvent* server_ready_; 1645 WaitableEvent* server_ready_;
1646 scoped_ptr<SyncChannel> server2_channel_; 1646 scoped_ptr<SyncChannel> server2_channel_;
1647 }; 1647 };
1648 1648
1649 class ReentrantReplyServer2 : public Worker { 1649 class ReentrantReplyServer2 : public Worker {
1650 public: 1650 public:
1651 ReentrantReplyServer2() 1651 ReentrantReplyServer2()
1652 : Worker("reentrant_reply2", Channel::MODE_SERVER), 1652 : Worker("reentrant_reply2", Channel::MODE_SERVER),
1653 reply_(NULL) { } 1653 reply_(NULL) { }
1654 1654
1655 private: 1655 private:
1656 virtual bool OnMessageReceived(const Message& message) override { 1656 bool OnMessageReceived(const Message& message) override {
1657 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer2, message) 1657 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer2, message)
1658 IPC_MESSAGE_HANDLER_DELAY_REPLY( 1658 IPC_MESSAGE_HANDLER_DELAY_REPLY(
1659 SyncChannelTestMsg_Reentrant1, OnReentrant1) 1659 SyncChannelTestMsg_Reentrant1, OnReentrant1)
1660 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant3, OnReentrant3) 1660 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant3, OnReentrant3)
1661 IPC_END_MESSAGE_MAP() 1661 IPC_END_MESSAGE_MAP()
1662 return true; 1662 return true;
1663 } 1663 }
1664 1664
1665 void OnReentrant1(Message* reply) { 1665 void OnReentrant1(Message* reply) {
1666 DCHECK(!reply_); 1666 DCHECK(!reply_);
(...skipping 11 matching lines...) Expand all
1678 1678
1679 Message* reply_; 1679 Message* reply_;
1680 }; 1680 };
1681 1681
1682 class ReentrantReplyClient : public Worker { 1682 class ReentrantReplyClient : public Worker {
1683 public: 1683 public:
1684 ReentrantReplyClient(WaitableEvent* server_ready) 1684 ReentrantReplyClient(WaitableEvent* server_ready)
1685 : Worker("reentrant_reply1", Channel::MODE_CLIENT), 1685 : Worker("reentrant_reply1", Channel::MODE_CLIENT),
1686 server_ready_(server_ready) { } 1686 server_ready_(server_ready) { }
1687 1687
1688 virtual void Run() override { 1688 void Run() override {
1689 server_ready_->Wait(); 1689 server_ready_->Wait();
1690 Send(new SyncChannelTestMsg_Reentrant2()); 1690 Send(new SyncChannelTestMsg_Reentrant2());
1691 Done(); 1691 Done();
1692 } 1692 }
1693 1693
1694 private: 1694 private:
1695 WaitableEvent* server_ready_; 1695 WaitableEvent* server_ready_;
1696 }; 1696 };
1697 1697
1698 TEST_F(IPCSyncChannelTest, ReentrantReply) { 1698 TEST_F(IPCSyncChannelTest, ReentrantReply) {
(...skipping 12 matching lines...) Expand all
1711 class VerifiedServer : public Worker { 1711 class VerifiedServer : public Worker {
1712 public: 1712 public:
1713 VerifiedServer(base::Thread* listener_thread, 1713 VerifiedServer(base::Thread* listener_thread,
1714 const std::string& channel_name, 1714 const std::string& channel_name,
1715 const std::string& reply_text) 1715 const std::string& reply_text)
1716 : Worker(channel_name, Channel::MODE_SERVER), 1716 : Worker(channel_name, Channel::MODE_SERVER),
1717 reply_text_(reply_text) { 1717 reply_text_(reply_text) {
1718 Worker::OverrideThread(listener_thread); 1718 Worker::OverrideThread(listener_thread);
1719 } 1719 }
1720 1720
1721 virtual void OnNestedTestMsg(Message* reply_msg) override { 1721 void OnNestedTestMsg(Message* reply_msg) override {
1722 VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_; 1722 VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_;
1723 SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_); 1723 SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_);
1724 Send(reply_msg); 1724 Send(reply_msg);
1725 ASSERT_EQ(channel()->GetPeerPID(), base::GetCurrentProcId()); 1725 ASSERT_EQ(channel()->GetPeerPID(), base::GetCurrentProcId());
1726 Done(); 1726 Done();
1727 } 1727 }
1728 1728
1729 private: 1729 private:
1730 std::string reply_text_; 1730 std::string reply_text_;
1731 }; 1731 };
1732 1732
1733 class VerifiedClient : public Worker { 1733 class VerifiedClient : public Worker {
1734 public: 1734 public:
1735 VerifiedClient(base::Thread* listener_thread, 1735 VerifiedClient(base::Thread* listener_thread,
1736 const std::string& channel_name, 1736 const std::string& channel_name,
1737 const std::string& expected_text) 1737 const std::string& expected_text)
1738 : Worker(channel_name, Channel::MODE_CLIENT), 1738 : Worker(channel_name, Channel::MODE_CLIENT),
1739 expected_text_(expected_text) { 1739 expected_text_(expected_text) {
1740 Worker::OverrideThread(listener_thread); 1740 Worker::OverrideThread(listener_thread);
1741 } 1741 }
1742 1742
1743 virtual void Run() override { 1743 void Run() override {
1744 std::string response; 1744 std::string response;
1745 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response); 1745 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response);
1746 bool result = Send(msg); 1746 bool result = Send(msg);
1747 DCHECK(result); 1747 DCHECK(result);
1748 DCHECK_EQ(response, expected_text_); 1748 DCHECK_EQ(response, expected_text_);
1749 // expected_text_ is only used in the above DCHECK. This line suppresses the 1749 // expected_text_ is only used in the above DCHECK. This line suppresses the
1750 // "unused private field" warning in release builds. 1750 // "unused private field" warning in release builds.
1751 (void)expected_text_; 1751 (void)expected_text_;
1752 1752
1753 VLOG(1) << __FUNCTION__ << " Received reply: " << response; 1753 VLOG(1) << __FUNCTION__ << " Received reply: " << response;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 } 1786 }
1787 1787
1788 // Windows needs to send an out-of-band secret to verify the client end of the 1788 // 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. 1789 // channel. Test that we still connect correctly in that case.
1790 TEST_F(IPCSyncChannelTest, Verified) { 1790 TEST_F(IPCSyncChannelTest, Verified) {
1791 Verified(); 1791 Verified();
1792 } 1792 }
1793 1793
1794 } // namespace 1794 } // namespace
1795 } // namespace IPC 1795 } // namespace IPC
OLDNEW
« no previous file with comments | « 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