| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ipc/ipc_sync_channel.h" | 5 #include "ipc/ipc_sync_channel.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 is_shutdown_(false) { | 58 is_shutdown_(false) { |
| 59 } | 59 } |
| 60 | 60 |
| 61 virtual ~Worker() { | 61 virtual ~Worker() { |
| 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 virtual bool Send(Message* msg) OVERRIDE { return channel_->Send(msg); } |
| 68 bool SendWithTimeout(Message* msg, int timeout_ms) { | |
| 69 return channel_->SendWithTimeout(msg, timeout_ms); | |
| 70 } | |
| 71 void WaitForChannelCreation() { channel_created_->Wait(); } | 68 void WaitForChannelCreation() { channel_created_->Wait(); } |
| 72 void CloseChannel() { | 69 void CloseChannel() { |
| 73 DCHECK(base::MessageLoop::current() == ListenerThread()->message_loop()); | 70 DCHECK(base::MessageLoop::current() == ListenerThread()->message_loop()); |
| 74 channel_->Close(); | 71 channel_->Close(); |
| 75 } | 72 } |
| 76 void Start() { | 73 void Start() { |
| 77 StartThread(&listener_thread_, base::MessageLoop::TYPE_DEFAULT); | 74 StartThread(&listener_thread_, base::MessageLoop::TYPE_DEFAULT); |
| 78 ListenerThread()->message_loop()->PostTask( | 75 ListenerThread()->message_loop()->PostTask( |
| 79 FROM_HERE, base::Bind(&Worker::OnStart, this)); | 76 FROM_HERE, base::Bind(&Worker::OnStart, this)); |
| 80 } | 77 } |
| 81 void Shutdown() { | 78 void Shutdown() { |
| 82 // The IPC thread needs to outlive SyncChannel. We can't do this in | 79 // The IPC thread needs to outlive SyncChannel. We can't do this in |
| 83 // ~Worker(), since that'll reset the vtable pointer (to Worker's), which | 80 // ~Worker(), since that'll reset the vtable pointer (to Worker's), which |
| 84 // may result in a race conditions. See http://crbug.com/25841. | 81 // may result in a race conditions. See http://crbug.com/25841. |
| 85 WaitableEvent listener_done(false, false), ipc_done(false, false); | 82 WaitableEvent listener_done(false, false), ipc_done(false, false); |
| 86 ListenerThread()->message_loop()->PostTask( | 83 ListenerThread()->message_loop()->PostTask( |
| 87 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown1, this, | 84 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown1, this, |
| 88 &listener_done, &ipc_done)); | 85 &listener_done, &ipc_done)); |
| 89 listener_done.Wait(); | 86 listener_done.Wait(); |
| 90 ipc_done.Wait(); | 87 ipc_done.Wait(); |
| 91 ipc_thread_.Stop(); | 88 ipc_thread_.Stop(); |
| 92 listener_thread_.Stop(); | 89 listener_thread_.Stop(); |
| 93 is_shutdown_ = true; | 90 is_shutdown_ = true; |
| 94 } | 91 } |
| 95 void OverrideThread(base::Thread* overrided_thread) { | 92 void OverrideThread(base::Thread* overrided_thread) { |
| 96 DCHECK(overrided_thread_ == NULL); | 93 DCHECK(overrided_thread_ == NULL); |
| 97 overrided_thread_ = overrided_thread; | 94 overrided_thread_ = overrided_thread; |
| 98 } | 95 } |
| 99 bool SendAnswerToLife(bool pump, int timeout, bool succeed) { | 96 bool SendAnswerToLife(bool pump, bool succeed) { |
| 100 int answer = 0; | 97 int answer = 0; |
| 101 SyncMessage* msg = new SyncChannelTestMsg_AnswerToLife(&answer); | 98 SyncMessage* msg = new SyncChannelTestMsg_AnswerToLife(&answer); |
| 102 if (pump) | 99 if (pump) |
| 103 msg->EnableMessagePumping(); | 100 msg->EnableMessagePumping(); |
| 104 bool result = SendWithTimeout(msg, timeout); | 101 bool result = Send(msg); |
| 105 DCHECK_EQ(result, succeed); | 102 DCHECK_EQ(result, succeed); |
| 106 DCHECK_EQ(answer, (succeed ? 42 : 0)); | 103 DCHECK_EQ(answer, (succeed ? 42 : 0)); |
| 107 return result; | 104 return result; |
| 108 } | 105 } |
| 109 bool SendDouble(bool pump, bool succeed) { | 106 bool SendDouble(bool pump, bool succeed) { |
| 110 int answer = 0; | 107 int answer = 0; |
| 111 SyncMessage* msg = new SyncChannelTestMsg_Double(5, &answer); | 108 SyncMessage* msg = new SyncChannelTestMsg_Double(5, &answer); |
| 112 if (pump) | 109 if (pump) |
| 113 msg->EnableMessagePumping(); | 110 msg->EnableMessagePumping(); |
| 114 bool result = Send(msg); | 111 bool result = Send(msg); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 }; | 270 }; |
| 274 | 271 |
| 275 //------------------------------------------------------------------------------ | 272 //------------------------------------------------------------------------------ |
| 276 | 273 |
| 277 class SimpleServer : public Worker { | 274 class SimpleServer : public Worker { |
| 278 public: | 275 public: |
| 279 explicit SimpleServer(bool pump_during_send) | 276 explicit SimpleServer(bool pump_during_send) |
| 280 : Worker(Channel::MODE_SERVER, "simpler_server"), | 277 : Worker(Channel::MODE_SERVER, "simpler_server"), |
| 281 pump_during_send_(pump_during_send) { } | 278 pump_during_send_(pump_during_send) { } |
| 282 virtual void Run() OVERRIDE { | 279 virtual void Run() OVERRIDE { |
| 283 SendAnswerToLife(pump_during_send_, base::kNoTimeout, true); | 280 SendAnswerToLife(pump_during_send_, true); |
| 284 Done(); | 281 Done(); |
| 285 } | 282 } |
| 286 | 283 |
| 287 bool pump_during_send_; | 284 bool pump_during_send_; |
| 288 }; | 285 }; |
| 289 | 286 |
| 290 class SimpleClient : public Worker { | 287 class SimpleClient : public Worker { |
| 291 public: | 288 public: |
| 292 SimpleClient() : Worker(Channel::MODE_CLIENT, "simple_client") { } | 289 SimpleClient() : Worker(Channel::MODE_CLIENT, "simple_client") { } |
| 293 | 290 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 315 // Worker classes which override how the sync channel is created to use the | 312 // Worker classes which override how the sync channel is created to use the |
| 316 // two-step initialization (calling the lightweight constructor and then | 313 // two-step initialization (calling the lightweight constructor and then |
| 317 // ChannelProxy::Init separately) process. | 314 // ChannelProxy::Init separately) process. |
| 318 class TwoStepServer : public Worker { | 315 class TwoStepServer : public Worker { |
| 319 public: | 316 public: |
| 320 explicit TwoStepServer(bool create_pipe_now) | 317 explicit TwoStepServer(bool create_pipe_now) |
| 321 : Worker(Channel::MODE_SERVER, "simpler_server"), | 318 : Worker(Channel::MODE_SERVER, "simpler_server"), |
| 322 create_pipe_now_(create_pipe_now) { } | 319 create_pipe_now_(create_pipe_now) { } |
| 323 | 320 |
| 324 virtual void Run() OVERRIDE { | 321 virtual void Run() OVERRIDE { |
| 325 SendAnswerToLife(false, base::kNoTimeout, true); | 322 SendAnswerToLife(false, true); |
| 326 Done(); | 323 Done(); |
| 327 } | 324 } |
| 328 | 325 |
| 329 virtual SyncChannel* CreateChannel() OVERRIDE { | 326 virtual SyncChannel* CreateChannel() OVERRIDE { |
| 330 SyncChannel* channel = new SyncChannel( | 327 SyncChannel* channel = new SyncChannel( |
| 331 this, ipc_thread().message_loop_proxy().get(), shutdown_event()); | 328 this, ipc_thread().message_loop_proxy().get(), shutdown_event()); |
| 332 channel->Init(channel_name(), mode(), create_pipe_now_); | 329 channel->Init(channel_name(), mode(), create_pipe_now_); |
| 333 return channel; | 330 return channel; |
| 334 } | 331 } |
| 335 | 332 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 398 |
| 402 //------------------------------------------------------------------------------ | 399 //------------------------------------------------------------------------------ |
| 403 | 400 |
| 404 class NoHangServer : public Worker { | 401 class NoHangServer : public Worker { |
| 405 public: | 402 public: |
| 406 NoHangServer(WaitableEvent* got_first_reply, bool pump_during_send) | 403 NoHangServer(WaitableEvent* got_first_reply, bool pump_during_send) |
| 407 : Worker(Channel::MODE_SERVER, "no_hang_server"), | 404 : Worker(Channel::MODE_SERVER, "no_hang_server"), |
| 408 got_first_reply_(got_first_reply), | 405 got_first_reply_(got_first_reply), |
| 409 pump_during_send_(pump_during_send) { } | 406 pump_during_send_(pump_during_send) { } |
| 410 virtual void Run() OVERRIDE { | 407 virtual void Run() OVERRIDE { |
| 411 SendAnswerToLife(pump_during_send_, base::kNoTimeout, true); | 408 SendAnswerToLife(pump_during_send_, true); |
| 412 got_first_reply_->Signal(); | 409 got_first_reply_->Signal(); |
| 413 | 410 |
| 414 SendAnswerToLife(pump_during_send_, base::kNoTimeout, false); | 411 SendAnswerToLife(pump_during_send_, false); |
| 415 Done(); | 412 Done(); |
| 416 } | 413 } |
| 417 | 414 |
| 418 WaitableEvent* got_first_reply_; | 415 WaitableEvent* got_first_reply_; |
| 419 bool pump_during_send_; | 416 bool pump_during_send_; |
| 420 }; | 417 }; |
| 421 | 418 |
| 422 class NoHangClient : public Worker { | 419 class NoHangClient : public Worker { |
| 423 public: | 420 public: |
| 424 explicit NoHangClient(WaitableEvent* got_first_reply) | 421 explicit NoHangClient(WaitableEvent* got_first_reply) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 virtual void Run() OVERRIDE { | 460 virtual void Run() OVERRIDE { |
| 464 if (delete_during_send_) { | 461 if (delete_during_send_) { |
| 465 // Use custom code since race conditions mean the answer may or may not be | 462 // Use custom code since race conditions mean the answer may or may not be |
| 466 // available. | 463 // available. |
| 467 int answer = 0; | 464 int answer = 0; |
| 468 SyncMessage* msg = new SyncChannelTestMsg_AnswerToLife(&answer); | 465 SyncMessage* msg = new SyncChannelTestMsg_AnswerToLife(&answer); |
| 469 if (pump_during_send_) | 466 if (pump_during_send_) |
| 470 msg->EnableMessagePumping(); | 467 msg->EnableMessagePumping(); |
| 471 Send(msg); | 468 Send(msg); |
| 472 } else { | 469 } else { |
| 473 SendAnswerToLife(pump_during_send_, base::kNoTimeout, true); | 470 SendAnswerToLife(pump_during_send_, true); |
| 474 } | 471 } |
| 475 Done(); | 472 Done(); |
| 476 } | 473 } |
| 477 | 474 |
| 478 virtual void OnDoubleDelay(int in, Message* reply_msg) OVERRIDE { | 475 virtual void OnDoubleDelay(int in, Message* reply_msg) OVERRIDE { |
| 479 SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, in * 2); | 476 SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, in * 2); |
| 480 Send(reply_msg); | 477 Send(reply_msg); |
| 481 if (delete_during_send_) | 478 if (delete_during_send_) |
| 482 ResetChannel(); | 479 ResetChannel(); |
| 483 } | 480 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 : Worker(Channel::MODE_SERVER, "recursive_server"), | 531 : Worker(Channel::MODE_SERVER, "recursive_server"), |
| 535 expected_send_result_(expected_send_result), | 532 expected_send_result_(expected_send_result), |
| 536 pump_first_(pump_first), pump_second_(pump_second) {} | 533 pump_first_(pump_first), pump_second_(pump_second) {} |
| 537 virtual void Run() OVERRIDE { | 534 virtual void Run() OVERRIDE { |
| 538 SendDouble(pump_first_, expected_send_result_); | 535 SendDouble(pump_first_, expected_send_result_); |
| 539 Done(); | 536 Done(); |
| 540 } | 537 } |
| 541 | 538 |
| 542 virtual void OnDouble(int in, int* out) OVERRIDE { | 539 virtual void OnDouble(int in, int* out) OVERRIDE { |
| 543 *out = in * 2; | 540 *out = in * 2; |
| 544 SendAnswerToLife(pump_second_, base::kNoTimeout, expected_send_result_); | 541 SendAnswerToLife(pump_second_, expected_send_result_); |
| 545 } | 542 } |
| 546 | 543 |
| 547 bool expected_send_result_, pump_first_, pump_second_; | 544 bool expected_send_result_, pump_first_, pump_second_; |
| 548 }; | 545 }; |
| 549 | 546 |
| 550 class RecursiveClient : public Worker { | 547 class RecursiveClient : public Worker { |
| 551 public: | 548 public: |
| 552 RecursiveClient(bool pump_during_send, bool close_channel) | 549 RecursiveClient(bool pump_during_send, bool close_channel) |
| 553 : Worker(Channel::MODE_CLIENT, "recursive_client"), | 550 : Worker(Channel::MODE_CLIENT, "recursive_client"), |
| 554 pump_during_send_(pump_during_send), close_channel_(close_channel) {} | 551 pump_during_send_(pump_during_send), close_channel_(close_channel) {} |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 MultipleClient2( | 669 MultipleClient2( |
| 673 WaitableEvent* client1_msg_received, WaitableEvent* client1_can_reply, | 670 WaitableEvent* client1_msg_received, WaitableEvent* client1_can_reply, |
| 674 bool pump_during_send) | 671 bool pump_during_send) |
| 675 : Worker("test_channel2", Channel::MODE_CLIENT), | 672 : Worker("test_channel2", Channel::MODE_CLIENT), |
| 676 client1_msg_received_(client1_msg_received), | 673 client1_msg_received_(client1_msg_received), |
| 677 client1_can_reply_(client1_can_reply), | 674 client1_can_reply_(client1_can_reply), |
| 678 pump_during_send_(pump_during_send) { } | 675 pump_during_send_(pump_during_send) { } |
| 679 | 676 |
| 680 virtual void Run() OVERRIDE { | 677 virtual void Run() OVERRIDE { |
| 681 client1_msg_received_->Wait(); | 678 client1_msg_received_->Wait(); |
| 682 SendAnswerToLife(pump_during_send_, base::kNoTimeout, true); | 679 SendAnswerToLife(pump_during_send_, true); |
| 683 client1_can_reply_->Signal(); | 680 client1_can_reply_->Signal(); |
| 684 Done(); | 681 Done(); |
| 685 } | 682 } |
| 686 | 683 |
| 687 private: | 684 private: |
| 688 WaitableEvent *client1_msg_received_, *client1_can_reply_; | 685 WaitableEvent *client1_msg_received_, *client1_can_reply_; |
| 689 bool pump_during_send_; | 686 bool pump_during_send_; |
| 690 }; | 687 }; |
| 691 | 688 |
| 692 void Multiple(bool server_pump, bool client_pump) { | 689 void Multiple(bool server_pump, bool client_pump) { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 // Tests http://b/1093251 - that sending lots of sync messages while | 869 // Tests http://b/1093251 - that sending lots of sync messages while |
| 873 // the receiver is waiting for a sync reply does not overflow the PostMessage | 870 // the receiver is waiting for a sync reply does not overflow the PostMessage |
| 874 // queue. | 871 // queue. |
| 875 TEST_F(IPCSyncChannelTest, ChattyServer) { | 872 TEST_F(IPCSyncChannelTest, ChattyServer) { |
| 876 ChattyServer(false); | 873 ChattyServer(false); |
| 877 ChattyServer(true); | 874 ChattyServer(true); |
| 878 } | 875 } |
| 879 | 876 |
| 880 //------------------------------------------------------------------------------ | 877 //------------------------------------------------------------------------------ |
| 881 | 878 |
| 882 class TimeoutServer : public Worker { | |
| 883 public: | |
| 884 TimeoutServer(int timeout_ms, | |
| 885 std::vector<bool> timeout_seq, | |
| 886 bool pump_during_send) | |
| 887 : Worker(Channel::MODE_SERVER, "timeout_server"), | |
| 888 timeout_ms_(timeout_ms), | |
| 889 timeout_seq_(timeout_seq), | |
| 890 pump_during_send_(pump_during_send) { | |
| 891 } | |
| 892 | |
| 893 virtual void Run() OVERRIDE { | |
| 894 for (std::vector<bool>::const_iterator iter = timeout_seq_.begin(); | |
| 895 iter != timeout_seq_.end(); ++iter) { | |
| 896 SendAnswerToLife(pump_during_send_, timeout_ms_, !*iter); | |
| 897 } | |
| 898 Done(); | |
| 899 } | |
| 900 | |
| 901 private: | |
| 902 int timeout_ms_; | |
| 903 std::vector<bool> timeout_seq_; | |
| 904 bool pump_during_send_; | |
| 905 }; | |
| 906 | |
| 907 class UnresponsiveClient : public Worker { | |
| 908 public: | |
| 909 explicit UnresponsiveClient(std::vector<bool> timeout_seq) | |
| 910 : Worker(Channel::MODE_CLIENT, "unresponsive_client"), | |
| 911 timeout_seq_(timeout_seq) { | |
| 912 } | |
| 913 | |
| 914 virtual void OnAnswerDelay(Message* reply_msg) OVERRIDE { | |
| 915 DCHECK(!timeout_seq_.empty()); | |
| 916 if (!timeout_seq_[0]) { | |
| 917 SyncChannelTestMsg_AnswerToLife::WriteReplyParams(reply_msg, 42); | |
| 918 Send(reply_msg); | |
| 919 } else { | |
| 920 // Don't reply. | |
| 921 delete reply_msg; | |
| 922 } | |
| 923 timeout_seq_.erase(timeout_seq_.begin()); | |
| 924 if (timeout_seq_.empty()) | |
| 925 Done(); | |
| 926 } | |
| 927 | |
| 928 private: | |
| 929 // Whether we should time-out or respond to the various messages we receive. | |
| 930 std::vector<bool> timeout_seq_; | |
| 931 }; | |
| 932 | |
| 933 void SendWithTimeoutOK(bool pump_during_send) { | |
| 934 std::vector<Worker*> workers; | |
| 935 std::vector<bool> timeout_seq; | |
| 936 timeout_seq.push_back(false); | |
| 937 timeout_seq.push_back(false); | |
| 938 timeout_seq.push_back(false); | |
| 939 workers.push_back(new TimeoutServer(5000, timeout_seq, pump_during_send)); | |
| 940 workers.push_back(new SimpleClient()); | |
| 941 RunTest(workers); | |
| 942 } | |
| 943 | |
| 944 void SendWithTimeoutTimeout(bool pump_during_send) { | |
| 945 std::vector<Worker*> workers; | |
| 946 std::vector<bool> timeout_seq; | |
| 947 timeout_seq.push_back(true); | |
| 948 timeout_seq.push_back(false); | |
| 949 timeout_seq.push_back(false); | |
| 950 workers.push_back(new TimeoutServer(100, timeout_seq, pump_during_send)); | |
| 951 workers.push_back(new UnresponsiveClient(timeout_seq)); | |
| 952 RunTest(workers); | |
| 953 } | |
| 954 | |
| 955 void SendWithTimeoutMixedOKAndTimeout(bool pump_during_send) { | |
| 956 std::vector<Worker*> workers; | |
| 957 std::vector<bool> timeout_seq; | |
| 958 timeout_seq.push_back(true); | |
| 959 timeout_seq.push_back(false); | |
| 960 timeout_seq.push_back(false); | |
| 961 timeout_seq.push_back(true); | |
| 962 timeout_seq.push_back(false); | |
| 963 workers.push_back(new TimeoutServer(100, timeout_seq, pump_during_send)); | |
| 964 workers.push_back(new UnresponsiveClient(timeout_seq)); | |
| 965 RunTest(workers); | |
| 966 } | |
| 967 | |
| 968 // Tests that SendWithTimeout does not time-out if the response comes back fast | |
| 969 // enough. | |
| 970 TEST_F(IPCSyncChannelTest, SendWithTimeoutOK) { | |
| 971 SendWithTimeoutOK(false); | |
| 972 SendWithTimeoutOK(true); | |
| 973 } | |
| 974 | |
| 975 // Tests that SendWithTimeout does time-out. | |
| 976 TEST_F(IPCSyncChannelTest, SendWithTimeoutTimeout) { | |
| 977 SendWithTimeoutTimeout(false); | |
| 978 SendWithTimeoutTimeout(true); | |
| 979 } | |
| 980 | |
| 981 // Sends some message that time-out and some that succeed. | |
| 982 TEST_F(IPCSyncChannelTest, SendWithTimeoutMixedOKAndTimeout) { | |
| 983 SendWithTimeoutMixedOKAndTimeout(false); | |
| 984 SendWithTimeoutMixedOKAndTimeout(true); | |
| 985 } | |
| 986 | |
| 987 //------------------------------------------------------------------------------ | |
| 988 | |
| 989 void NestedCallback(Worker* server) { | 879 void NestedCallback(Worker* server) { |
| 990 // Sleep a bit so that we wake up after the reply has been received. | 880 // Sleep a bit so that we wake up after the reply has been received. |
| 991 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(250)); | 881 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(250)); |
| 992 server->SendAnswerToLife(true, base::kNoTimeout, true); | 882 server->SendAnswerToLife(true, true); |
| 993 } | 883 } |
| 994 | 884 |
| 995 bool timeout_occurred = false; | 885 bool timeout_occurred = false; |
| 996 | 886 |
| 997 void TimeoutCallback() { | 887 void TimeoutCallback() { |
| 998 timeout_occurred = true; | 888 timeout_occurred = true; |
| 999 } | 889 } |
| 1000 | 890 |
| 1001 class DoneEventRaceServer : public Worker { | 891 class DoneEventRaceServer : public Worker { |
| 1002 public: | 892 public: |
| 1003 DoneEventRaceServer() | 893 DoneEventRaceServer() |
| 1004 : Worker(Channel::MODE_SERVER, "done_event_race_server") { } | 894 : Worker(Channel::MODE_SERVER, "done_event_race_server") { } |
| 1005 | 895 |
| 1006 virtual void Run() OVERRIDE { | 896 virtual void Run() OVERRIDE { |
| 1007 base::MessageLoop::current()->PostTask(FROM_HERE, | 897 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 1008 base::Bind(&NestedCallback, this)); | 898 base::Bind(&NestedCallback, this)); |
| 1009 base::MessageLoop::current()->PostDelayedTask( | 899 base::MessageLoop::current()->PostDelayedTask( |
| 1010 FROM_HERE, | 900 FROM_HERE, |
| 1011 base::Bind(&TimeoutCallback), | 901 base::Bind(&TimeoutCallback), |
| 1012 base::TimeDelta::FromSeconds(9)); | 902 base::TimeDelta::FromSeconds(9)); |
| 1013 // Even though we have a timeout on the Send, it will succeed since for this | 903 // Even though we have a timeout on the Send, it will succeed since for this |
| 1014 // bug, the reply message comes back and is deserialized, however the done | 904 // bug, the reply message comes back and is deserialized, however the done |
| 1015 // event wasn't set. So we indirectly use the timeout task to notice if a | 905 // event wasn't set. So we indirectly use the timeout task to notice if a |
| 1016 // timeout occurred. | 906 // timeout occurred. |
| 1017 SendAnswerToLife(true, 10000, true); | 907 SendAnswerToLife(true, true); |
| 1018 DCHECK(!timeout_occurred); | 908 DCHECK(!timeout_occurred); |
| 1019 Done(); | 909 Done(); |
| 1020 } | 910 } |
| 1021 }; | 911 }; |
| 1022 | 912 |
| 1023 // Tests http://b/1474092 - that if after the done_event is set but before | 913 // Tests http://b/1474092 - that if after the done_event is set but before |
| 1024 // OnObjectSignaled is called another message is sent out, then after its | 914 // OnObjectSignaled is called another message is sent out, then after its |
| 1025 // reply comes back OnObjectSignaled will be called for the first message. | 915 // reply comes back OnObjectSignaled will be called for the first message. |
| 1026 TEST_F(IPCSyncChannelTest, DoneEventRace) { | 916 TEST_F(IPCSyncChannelTest, DoneEventRace) { |
| 1027 std::vector<Worker*> workers; | 917 std::vector<Worker*> workers; |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1894 } | 1784 } |
| 1895 | 1785 |
| 1896 // Windows needs to send an out-of-band secret to verify the client end of the | 1786 // Windows needs to send an out-of-band secret to verify the client end of the |
| 1897 // channel. Test that we still connect correctly in that case. | 1787 // channel. Test that we still connect correctly in that case. |
| 1898 TEST_F(IPCSyncChannelTest, Verified) { | 1788 TEST_F(IPCSyncChannelTest, Verified) { |
| 1899 Verified(); | 1789 Verified(); |
| 1900 } | 1790 } |
| 1901 | 1791 |
| 1902 } // namespace | 1792 } // namespace |
| 1903 } // namespace IPC | 1793 } // namespace IPC |
| OLD | NEW |