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" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | |
15 #include "base/process/process_handle.h" | 15 #include "base/process/process_handle.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/thread_task_runner_handle.h" |
19 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
20 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
21 #include "ipc/ipc_listener.h" | 23 #include "ipc/ipc_listener.h" |
22 #include "ipc/ipc_message.h" | 24 #include "ipc/ipc_message.h" |
23 #include "ipc/ipc_sender.h" | 25 #include "ipc/ipc_sender.h" |
24 #include "ipc/ipc_sync_message_filter.h" | 26 #include "ipc/ipc_sync_message_filter.h" |
25 #include "ipc/ipc_sync_message_unittest.h" | 27 #include "ipc/ipc_sync_message_unittest.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
27 | 29 |
28 using base::WaitableEvent; | 30 using base::WaitableEvent; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void AddRef() { } | 67 void AddRef() { } |
66 void Release() { } | 68 void Release() { } |
67 bool Send(Message* msg) override { return channel_->Send(msg); } | 69 bool Send(Message* msg) override { return channel_->Send(msg); } |
68 void WaitForChannelCreation() { channel_created_->Wait(); } | 70 void WaitForChannelCreation() { channel_created_->Wait(); } |
69 void CloseChannel() { | 71 void CloseChannel() { |
70 DCHECK(base::MessageLoop::current() == ListenerThread()->message_loop()); | 72 DCHECK(base::MessageLoop::current() == ListenerThread()->message_loop()); |
71 channel_->Close(); | 73 channel_->Close(); |
72 } | 74 } |
73 void Start() { | 75 void Start() { |
74 StartThread(&listener_thread_, base::MessageLoop::TYPE_DEFAULT); | 76 StartThread(&listener_thread_, base::MessageLoop::TYPE_DEFAULT); |
75 ListenerThread()->message_loop()->PostTask( | 77 ListenerThread()->task_runner()->PostTask( |
76 FROM_HERE, base::Bind(&Worker::OnStart, this)); | 78 FROM_HERE, base::Bind(&Worker::OnStart, this)); |
77 } | 79 } |
78 void Shutdown() { | 80 void Shutdown() { |
79 // The IPC thread needs to outlive SyncChannel. We can't do this in | 81 // The IPC thread needs to outlive SyncChannel. We can't do this in |
80 // ~Worker(), since that'll reset the vtable pointer (to Worker's), which | 82 // ~Worker(), since that'll reset the vtable pointer (to Worker's), which |
81 // may result in a race conditions. See http://crbug.com/25841. | 83 // may result in a race conditions. See http://crbug.com/25841. |
82 WaitableEvent listener_done(false, false), ipc_done(false, false); | 84 WaitableEvent listener_done(false, false), ipc_done(false, false); |
83 ListenerThread()->message_loop()->PostTask( | 85 ListenerThread()->task_runner()->PostTask( |
84 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown1, this, | 86 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown1, this, |
85 &listener_done, &ipc_done)); | 87 &listener_done, &ipc_done)); |
86 listener_done.Wait(); | 88 listener_done.Wait(); |
87 ipc_done.Wait(); | 89 ipc_done.Wait(); |
88 ipc_thread_.Stop(); | 90 ipc_thread_.Stop(); |
89 listener_thread_.Stop(); | 91 listener_thread_.Stop(); |
90 is_shutdown_ = true; | 92 is_shutdown_ = true; |
91 } | 93 } |
92 void OverrideThread(base::Thread* overrided_thread) { | 94 void OverrideThread(base::Thread* overrided_thread) { |
93 DCHECK(overrided_thread_ == NULL); | 95 DCHECK(overrided_thread_ == NULL); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, result); | 147 SyncChannelTestMsg_Double::WriteReplyParams(reply_msg, result); |
146 Send(reply_msg); | 148 Send(reply_msg); |
147 } | 149 } |
148 | 150 |
149 virtual void OnNestedTestMsg(Message* reply_msg) { | 151 virtual void OnNestedTestMsg(Message* reply_msg) { |
150 NOTREACHED(); | 152 NOTREACHED(); |
151 } | 153 } |
152 | 154 |
153 virtual SyncChannel* CreateChannel() { | 155 virtual SyncChannel* CreateChannel() { |
154 scoped_ptr<SyncChannel> channel = SyncChannel::Create( | 156 scoped_ptr<SyncChannel> channel = SyncChannel::Create( |
155 channel_name_, mode_, this, ipc_thread_.message_loop_proxy().get(), | 157 channel_name_, mode_, this, ipc_thread_.task_runner().get(), true, |
156 true, &shutdown_event_); | 158 &shutdown_event_); |
157 return channel.release(); | 159 return channel.release(); |
158 } | 160 } |
159 | 161 |
160 base::Thread* ListenerThread() { | 162 base::Thread* ListenerThread() { |
161 return overrided_thread_ ? overrided_thread_ : &listener_thread_; | 163 return overrided_thread_ ? overrided_thread_ : &listener_thread_; |
162 } | 164 } |
163 | 165 |
164 const base::Thread& ipc_thread() const { return ipc_thread_; } | 166 const base::Thread& ipc_thread() const { return ipc_thread_; } |
165 | 167 |
166 private: | 168 private: |
(...skipping 16 matching lines...) Expand all Loading... |
183 ipc_thread_.message_loop()->PostTask( | 185 ipc_thread_.message_loop()->PostTask( |
184 FROM_HERE, base::Bind(&Worker::OnIPCThreadShutdown, this, | 186 FROM_HERE, base::Bind(&Worker::OnIPCThreadShutdown, this, |
185 listener_event, ipc_event)); | 187 listener_event, ipc_event)); |
186 } | 188 } |
187 | 189 |
188 void OnIPCThreadShutdown(WaitableEvent* listener_event, | 190 void OnIPCThreadShutdown(WaitableEvent* listener_event, |
189 WaitableEvent* ipc_event) { | 191 WaitableEvent* ipc_event) { |
190 base::RunLoop().RunUntilIdle(); | 192 base::RunLoop().RunUntilIdle(); |
191 ipc_event->Signal(); | 193 ipc_event->Signal(); |
192 | 194 |
193 listener_thread_.message_loop()->PostTask( | 195 listener_thread_.task_runner()->PostTask( |
194 FROM_HERE, base::Bind(&Worker::OnListenerThreadShutdown2, this, | 196 FROM_HERE, |
195 listener_event)); | 197 base::Bind(&Worker::OnListenerThreadShutdown2, this, listener_event)); |
196 } | 198 } |
197 | 199 |
198 void OnListenerThreadShutdown2(WaitableEvent* listener_event) { | 200 void OnListenerThreadShutdown2(WaitableEvent* listener_event) { |
199 base::RunLoop().RunUntilIdle(); | 201 base::RunLoop().RunUntilIdle(); |
200 listener_event->Signal(); | 202 listener_event->Signal(); |
201 } | 203 } |
202 | 204 |
203 bool OnMessageReceived(const Message& message) override { | 205 bool OnMessageReceived(const Message& message) override { |
204 IPC_BEGIN_MESSAGE_MAP(Worker, message) | 206 IPC_BEGIN_MESSAGE_MAP(Worker, message) |
205 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_Double, OnDoubleDelay) | 207 IPC_MESSAGE_HANDLER_DELAY_REPLY(SyncChannelTestMsg_Double, OnDoubleDelay) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 create_pipe_now_(create_pipe_now) { } | 319 create_pipe_now_(create_pipe_now) { } |
318 | 320 |
319 void Run() override { | 321 void Run() override { |
320 SendAnswerToLife(false, true); | 322 SendAnswerToLife(false, true); |
321 Done(); | 323 Done(); |
322 } | 324 } |
323 | 325 |
324 SyncChannel* CreateChannel() override { | 326 SyncChannel* CreateChannel() override { |
325 SyncChannel* channel = | 327 SyncChannel* channel = |
326 SyncChannel::Create(channel_name(), mode(), this, | 328 SyncChannel::Create(channel_name(), mode(), this, |
327 ipc_thread().message_loop_proxy().get(), | 329 ipc_thread().task_runner().get(), create_pipe_now_, |
328 create_pipe_now_, | |
329 shutdown_event()).release(); | 330 shutdown_event()).release(); |
330 return channel; | 331 return channel; |
331 } | 332 } |
332 | 333 |
333 bool create_pipe_now_; | 334 bool create_pipe_now_; |
334 }; | 335 }; |
335 | 336 |
336 class TwoStepClient : public Worker { | 337 class TwoStepClient : public Worker { |
337 public: | 338 public: |
338 TwoStepClient(bool create_pipe_now) | 339 TwoStepClient(bool create_pipe_now) |
339 : Worker(Channel::MODE_CLIENT, "simple_client"), | 340 : Worker(Channel::MODE_CLIENT, "simple_client"), |
340 create_pipe_now_(create_pipe_now) { } | 341 create_pipe_now_(create_pipe_now) { } |
341 | 342 |
342 void OnAnswer(int* answer) override { | 343 void OnAnswer(int* answer) override { |
343 *answer = 42; | 344 *answer = 42; |
344 Done(); | 345 Done(); |
345 } | 346 } |
346 | 347 |
347 SyncChannel* CreateChannel() override { | 348 SyncChannel* CreateChannel() override { |
348 SyncChannel* channel = | 349 SyncChannel* channel = |
349 SyncChannel::Create(channel_name(), mode(), this, | 350 SyncChannel::Create(channel_name(), mode(), this, |
350 ipc_thread().message_loop_proxy().get(), | 351 ipc_thread().task_runner().get(), 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 }; |
358 | 358 |
359 void TwoStep(bool create_server_pipe_now, bool create_client_pipe_now) { | 359 void TwoStep(bool create_server_pipe_now, bool create_client_pipe_now) { |
360 std::vector<Worker*> workers; | 360 std::vector<Worker*> workers; |
361 workers.push_back(new TwoStepServer(create_server_pipe_now)); | 361 workers.push_back(new TwoStepServer(create_server_pipe_now)); |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 void Run() override { | 898 void Run() override { |
899 base::MessageLoop::current()->PostTask(FROM_HERE, | 899 base::ThreadTaskRunnerHandle::Get()->PostTask( |
900 base::Bind(&NestedCallback, this)); | 900 FROM_HERE, base::Bind(&NestedCallback, this)); |
901 base::MessageLoop::current()->PostDelayedTask( | 901 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
902 FROM_HERE, | 902 FROM_HERE, base::Bind(&TimeoutCallback), |
903 base::Bind(&TimeoutCallback), | |
904 base::TimeDelta::FromSeconds(9)); | 903 base::TimeDelta::FromSeconds(9)); |
905 // Even though we have a timeout on the Send, it will succeed since for this | 904 // 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 | 905 // 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 | 906 // event wasn't set. So we indirectly use the timeout task to notice if a |
908 // timeout occurred. | 907 // timeout occurred. |
909 SendAnswerToLife(true, true); | 908 SendAnswerToLife(true, true); |
910 DCHECK(!timeout_occurred); | 909 DCHECK(!timeout_occurred); |
911 Done(); | 910 Done(); |
912 } | 911 } |
913 }; | 912 }; |
914 | 913 |
915 // Tests http://b/1474092 - that if after the done_event is set but before | 914 // Tests http://b/1474092 - that if after the done_event is set but before |
916 // OnObjectSignaled is called another message is sent out, then after its | 915 // OnObjectSignaled is called another message is sent out, then after its |
917 // reply comes back OnObjectSignaled will be called for the first message. | 916 // reply comes back OnObjectSignaled will be called for the first message. |
918 TEST_F(IPCSyncChannelTest, DoneEventRace) { | 917 TEST_F(IPCSyncChannelTest, DoneEventRace) { |
919 std::vector<Worker*> workers; | 918 std::vector<Worker*> workers; |
920 workers.push_back(new DoneEventRaceServer()); | 919 workers.push_back(new DoneEventRaceServer()); |
921 workers.push_back(new SimpleClient()); | 920 workers.push_back(new SimpleClient()); |
922 RunTest(workers); | 921 RunTest(workers); |
923 } | 922 } |
924 | 923 |
925 //------------------------------------------------------------------------------ | 924 //------------------------------------------------------------------------------ |
926 | 925 |
927 class TestSyncMessageFilter : public SyncMessageFilter { | 926 class TestSyncMessageFilter : public SyncMessageFilter { |
928 public: | 927 public: |
929 TestSyncMessageFilter(base::WaitableEvent* shutdown_event, | 928 TestSyncMessageFilter( |
930 Worker* worker, | 929 base::WaitableEvent* shutdown_event, |
931 scoped_refptr<base::MessageLoopProxy> message_loop) | 930 Worker* worker, |
| 931 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
932 : SyncMessageFilter(shutdown_event), | 932 : SyncMessageFilter(shutdown_event), |
933 worker_(worker), | 933 worker_(worker), |
934 message_loop_(message_loop) { | 934 task_runner_(task_runner) {} |
935 } | |
936 | 935 |
937 void OnFilterAdded(Sender* sender) override { | 936 void OnFilterAdded(Sender* sender) override { |
938 SyncMessageFilter::OnFilterAdded(sender); | 937 SyncMessageFilter::OnFilterAdded(sender); |
939 message_loop_->PostTask( | 938 task_runner_->PostTask( |
940 FROM_HERE, | 939 FROM_HERE, |
941 base::Bind(&TestSyncMessageFilter::SendMessageOnHelperThread, this)); | 940 base::Bind(&TestSyncMessageFilter::SendMessageOnHelperThread, this)); |
942 } | 941 } |
943 | 942 |
944 void SendMessageOnHelperThread() { | 943 void SendMessageOnHelperThread() { |
945 int answer = 0; | 944 int answer = 0; |
946 bool result = Send(new SyncChannelTestMsg_AnswerToLife(&answer)); | 945 bool result = Send(new SyncChannelTestMsg_AnswerToLife(&answer)); |
947 DCHECK(result); | 946 DCHECK(result); |
948 DCHECK_EQ(answer, 42); | 947 DCHECK_EQ(answer, 42); |
949 | 948 |
950 worker_->Done(); | 949 worker_->Done(); |
951 } | 950 } |
952 | 951 |
953 private: | 952 private: |
954 ~TestSyncMessageFilter() override {} | 953 ~TestSyncMessageFilter() override {} |
955 | 954 |
956 Worker* worker_; | 955 Worker* worker_; |
957 scoped_refptr<base::MessageLoopProxy> message_loop_; | 956 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
958 }; | 957 }; |
959 | 958 |
960 class SyncMessageFilterServer : public Worker { | 959 class SyncMessageFilterServer : public Worker { |
961 public: | 960 public: |
962 SyncMessageFilterServer() | 961 SyncMessageFilterServer() |
963 : Worker(Channel::MODE_SERVER, "sync_message_filter_server"), | 962 : Worker(Channel::MODE_SERVER, "sync_message_filter_server"), |
964 thread_("helper_thread") { | 963 thread_("helper_thread") { |
965 base::Thread::Options options; | 964 base::Thread::Options options; |
966 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; | 965 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; |
967 thread_.StartWithOptions(options); | 966 thread_.StartWithOptions(options); |
968 filter_ = new TestSyncMessageFilter(shutdown_event(), this, | 967 filter_ = new TestSyncMessageFilter(shutdown_event(), this, |
969 thread_.message_loop_proxy()); | 968 thread_.task_runner()); |
970 } | 969 } |
971 | 970 |
972 void Run() override { | 971 void Run() override { |
973 channel()->AddFilter(filter_.get()); | 972 channel()->AddFilter(filter_.get()); |
974 } | 973 } |
975 | 974 |
976 base::Thread thread_; | 975 base::Thread thread_; |
977 scoped_refptr<TestSyncMessageFilter> filter_; | 976 scoped_refptr<TestSyncMessageFilter> filter_; |
978 }; | 977 }; |
979 | 978 |
980 // This class provides functionality to test the case that a Send on the sync | 979 // 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. | 980 // channel does not crash after the channel has been closed. |
982 class ServerSendAfterClose : public Worker { | 981 class ServerSendAfterClose : public Worker { |
983 public: | 982 public: |
984 ServerSendAfterClose() | 983 ServerSendAfterClose() |
985 : Worker(Channel::MODE_SERVER, "simpler_server"), | 984 : Worker(Channel::MODE_SERVER, "simpler_server"), |
986 send_result_(true) { | 985 send_result_(true) { |
987 } | 986 } |
988 | 987 |
989 bool SendDummy() { | 988 bool SendDummy() { |
990 ListenerThread()->message_loop()->PostTask( | 989 ListenerThread()->task_runner()->PostTask( |
991 FROM_HERE, base::Bind(base::IgnoreResult(&ServerSendAfterClose::Send), | 990 FROM_HERE, base::Bind(base::IgnoreResult(&ServerSendAfterClose::Send), |
992 this, new SyncChannelTestMsg_NoArgs)); | 991 this, new SyncChannelTestMsg_NoArgs)); |
993 return true; | 992 return true; |
994 } | 993 } |
995 | 994 |
996 bool send_result() const { | 995 bool send_result() const { |
997 return send_result_; | 996 return send_result_; |
998 } | 997 } |
999 | 998 |
1000 private: | 999 private: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 sent_ping_event_(sent_ping_event), | 1045 sent_ping_event_(sent_ping_event), |
1047 wait_event_(wait_event) { } | 1046 wait_event_(wait_event) { } |
1048 | 1047 |
1049 void OnDoPing(int ping) { | 1048 void OnDoPing(int ping) { |
1050 // Send an asynchronous message that unblocks the caller. | 1049 // Send an asynchronous message that unblocks the caller. |
1051 Message* msg = new SyncChannelTestMsg_Ping(ping); | 1050 Message* msg = new SyncChannelTestMsg_Ping(ping); |
1052 msg->set_unblock(true); | 1051 msg->set_unblock(true); |
1053 Send(msg); | 1052 Send(msg); |
1054 // Signal the event after the message has been sent on the channel, on the | 1053 // Signal the event after the message has been sent on the channel, on the |
1055 // IPC thread. | 1054 // IPC thread. |
1056 ipc_thread().message_loop()->PostTask( | 1055 ipc_thread().task_runner()->PostTask( |
1057 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnPingSent, this)); | 1056 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnPingSent, this)); |
1058 } | 1057 } |
1059 | 1058 |
1060 void OnPingTTL(int ping, int* out) { | 1059 void OnPingTTL(int ping, int* out) { |
1061 *out = ping; | 1060 *out = ping; |
1062 wait_event_->Wait(); | 1061 wait_event_->Wait(); |
1063 } | 1062 } |
1064 | 1063 |
1065 base::Thread* ListenerThread() { return Worker::ListenerThread(); } | 1064 base::Thread* ListenerThread() { return Worker::ListenerThread(); } |
1066 | 1065 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 server_(server), | 1120 server_(server), |
1122 server2_(server2), | 1121 server2_(server2), |
1123 success_(success), | 1122 success_(success), |
1124 sent_ping_event_(sent_ping_event) {} | 1123 sent_ping_event_(sent_ping_event) {} |
1125 | 1124 |
1126 void Run() override { | 1125 void Run() override { |
1127 // Incoming messages from our channel should only be dispatched when we | 1126 // Incoming messages from our channel should only be dispatched when we |
1128 // send a message on that same channel. | 1127 // send a message on that same channel. |
1129 channel()->SetRestrictDispatchChannelGroup(1); | 1128 channel()->SetRestrictDispatchChannelGroup(1); |
1130 | 1129 |
1131 server_->ListenerThread()->message_loop()->PostTask( | 1130 server_->ListenerThread()->task_runner()->PostTask( |
1132 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1)); | 1131 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 1)); |
1133 sent_ping_event_->Wait(); | 1132 sent_ping_event_->Wait(); |
1134 Send(new SyncChannelTestMsg_NoArgs); | 1133 Send(new SyncChannelTestMsg_NoArgs); |
1135 if (ping_ == 1) | 1134 if (ping_ == 1) |
1136 ++*success_; | 1135 ++*success_; |
1137 else | 1136 else |
1138 LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; | 1137 LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; |
1139 | 1138 |
1140 non_restricted_channel_ = | 1139 non_restricted_channel_ = SyncChannel::Create( |
1141 SyncChannel::Create("non_restricted_channel", | 1140 "non_restricted_channel", IPC::Channel::MODE_CLIENT, this, |
1142 IPC::Channel::MODE_CLIENT, | 1141 ipc_thread().task_runner().get(), true, shutdown_event()); |
1143 this, | |
1144 ipc_thread().message_loop_proxy().get(), | |
1145 true, | |
1146 shutdown_event()); | |
1147 | 1142 |
1148 server_->ListenerThread()->message_loop()->PostTask( | 1143 server_->ListenerThread()->task_runner()->PostTask( |
1149 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 2)); | 1144 FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 2)); |
1150 sent_ping_event_->Wait(); | 1145 sent_ping_event_->Wait(); |
1151 // Check that the incoming message is *not* dispatched when sending on the | 1146 // Check that the incoming message is *not* dispatched when sending on the |
1152 // non restricted channel. | 1147 // non restricted channel. |
1153 // TODO(piman): there is a possibility of a false positive race condition | 1148 // TODO(piman): there is a possibility of a false positive race condition |
1154 // here, if the message that was posted on the server-side end of the pipe | 1149 // here, if the message that was posted on the server-side end of the pipe |
1155 // is not visible yet on the client side, but I don't know how to solve this | 1150 // is not visible yet on the client side, but I don't know how to solve this |
1156 // without hooking into the internals of SyncChannel. I haven't seen it in | 1151 // without hooking into the internals of SyncChannel. I haven't seen it in |
1157 // practice (i.e. not setting SetRestrictDispatchToSameChannel does cause | 1152 // practice (i.e. not setting SetRestrictDispatchToSameChannel does cause |
1158 // the following to fail). | 1153 // the following to fail). |
1159 non_restricted_channel_->Send(new SyncChannelTestMsg_NoArgs); | 1154 non_restricted_channel_->Send(new SyncChannelTestMsg_NoArgs); |
1160 if (ping_ == 1) | 1155 if (ping_ == 1) |
1161 ++*success_; | 1156 ++*success_; |
1162 else | 1157 else |
1163 LOG(ERROR) << "Send dispatched message from restricted channel"; | 1158 LOG(ERROR) << "Send dispatched message from restricted channel"; |
1164 | 1159 |
1165 Send(new SyncChannelTestMsg_NoArgs); | 1160 Send(new SyncChannelTestMsg_NoArgs); |
1166 if (ping_ == 2) | 1161 if (ping_ == 2) |
1167 ++*success_; | 1162 ++*success_; |
1168 else | 1163 else |
1169 LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; | 1164 LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; |
1170 | 1165 |
1171 // Check that the incoming message on the non-restricted channel is | 1166 // Check that the incoming message on the non-restricted channel is |
1172 // dispatched when sending on the restricted channel. | 1167 // dispatched when sending on the restricted channel. |
1173 server2_->ListenerThread()->message_loop()->PostTask( | 1168 server2_->ListenerThread()->task_runner()->PostTask( |
1174 FROM_HERE, | 1169 FROM_HERE, |
1175 base::Bind(&NonRestrictedDispatchServer::OnDoPingTTL, server2_, 3)); | 1170 base::Bind(&NonRestrictedDispatchServer::OnDoPingTTL, server2_, 3)); |
1176 int value = 0; | 1171 int value = 0; |
1177 Send(new SyncChannelTestMsg_PingTTL(4, &value)); | 1172 Send(new SyncChannelTestMsg_PingTTL(4, &value)); |
1178 if (ping_ == 3 && value == 4) | 1173 if (ping_ == 3 && value == 4) |
1179 ++*success_; | 1174 ++*success_; |
1180 else | 1175 else |
1181 LOG(ERROR) << "Send failed to dispatch message from unrestricted channel"; | 1176 LOG(ERROR) << "Send failed to dispatch message from unrestricted channel"; |
1182 | 1177 |
1183 non_restricted_channel_->Send(new SyncChannelTestMsg_Done); | 1178 non_restricted_channel_->Send(new SyncChannelTestMsg_Done); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 server_(server), | 1380 server_(server), |
1386 peer_(peer), | 1381 peer_(peer), |
1387 server_ready_event_(server_ready_event), | 1382 server_ready_event_(server_ready_event), |
1388 events_(events), | 1383 events_(events), |
1389 received_msg_(false), | 1384 received_msg_(false), |
1390 received_noarg_reply_(false), | 1385 received_noarg_reply_(false), |
1391 done_issued_(false) {} | 1386 done_issued_(false) {} |
1392 | 1387 |
1393 void Run() override { | 1388 void Run() override { |
1394 server_ready_event_->Wait(); | 1389 server_ready_event_->Wait(); |
1395 server_->ListenerThread()->message_loop()->PostTask( | 1390 server_->ListenerThread()->task_runner()->PostTask( |
1396 FROM_HERE, | 1391 FROM_HERE, |
1397 base::Bind(&RestrictedDispatchDeadlockServer::OnDoServerTask, server_)); | 1392 base::Bind(&RestrictedDispatchDeadlockServer::OnDoServerTask, server_)); |
1398 peer_->ListenerThread()->message_loop()->PostTask( | 1393 peer_->ListenerThread()->task_runner()->PostTask( |
1399 FROM_HERE, | 1394 FROM_HERE, |
1400 base::Bind(&RestrictedDispatchDeadlockClient2::OnDoClient2Task, peer_)); | 1395 base::Bind(&RestrictedDispatchDeadlockClient2::OnDoClient2Task, peer_)); |
1401 events_[0]->Wait(); | 1396 events_[0]->Wait(); |
1402 events_[1]->Wait(); | 1397 events_[1]->Wait(); |
1403 DCHECK(received_msg_ == false); | 1398 DCHECK(received_msg_ == false); |
1404 | 1399 |
1405 Message* message = new SyncChannelTestMsg_NoArgs; | 1400 Message* message = new SyncChannelTestMsg_NoArgs; |
1406 message->set_unblock(true); | 1401 message->set_unblock(true); |
1407 Send(message); | 1402 Send(message); |
1408 received_noarg_reply_ = true; | 1403 received_noarg_reply_ = true; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 other_channel_->Send(new SyncChannelTestMsg_Done); | 1516 other_channel_->Send(new SyncChannelTestMsg_Done); |
1522 other_channel_.reset(); | 1517 other_channel_.reset(); |
1523 Done(); | 1518 Done(); |
1524 } | 1519 } |
1525 | 1520 |
1526 void Run() override { | 1521 void Run() override { |
1527 channel()->SetRestrictDispatchChannelGroup(group_); | 1522 channel()->SetRestrictDispatchChannelGroup(group_); |
1528 if (is_first()) | 1523 if (is_first()) |
1529 event1_->Signal(); | 1524 event1_->Signal(); |
1530 event2_->Wait(); | 1525 event2_->Wait(); |
1531 other_channel_ = | 1526 other_channel_ = SyncChannel::Create( |
1532 SyncChannel::Create(other_channel_name_, | 1527 other_channel_name_, IPC::Channel::MODE_CLIENT, this, |
1533 IPC::Channel::MODE_CLIENT, | 1528 ipc_thread().task_runner().get(), true, shutdown_event()); |
1534 this, | |
1535 ipc_thread().message_loop_proxy().get(), | |
1536 true, | |
1537 shutdown_event()); | |
1538 other_channel_->SetRestrictDispatchChannelGroup(group_); | 1529 other_channel_->SetRestrictDispatchChannelGroup(group_); |
1539 if (!is_first()) { | 1530 if (!is_first()) { |
1540 event1_->Signal(); | 1531 event1_->Signal(); |
1541 return; | 1532 return; |
1542 } | 1533 } |
1543 *success_ = 0; | 1534 *success_ = 0; |
1544 int value = 0; | 1535 int value = 0; |
1545 OnPingTTL(3, &value); | 1536 OnPingTTL(3, &value); |
1546 *success_ += (value == 3); | 1537 *success_ += (value == 3); |
1547 OnPingTTL(4, &value); | 1538 OnPingTTL(4, &value); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 // it will send another message to Server2. While sending that second message it | 1592 // it will send another message to Server2. While sending that second message it |
1602 // will receive a reply from Server1 with the unblock flag. | 1593 // will receive a reply from Server1 with the unblock flag. |
1603 | 1594 |
1604 class ReentrantReplyServer1 : public Worker { | 1595 class ReentrantReplyServer1 : public Worker { |
1605 public: | 1596 public: |
1606 ReentrantReplyServer1(WaitableEvent* server_ready) | 1597 ReentrantReplyServer1(WaitableEvent* server_ready) |
1607 : Worker("reentrant_reply1", Channel::MODE_SERVER), | 1598 : Worker("reentrant_reply1", Channel::MODE_SERVER), |
1608 server_ready_(server_ready) { } | 1599 server_ready_(server_ready) { } |
1609 | 1600 |
1610 void Run() override { | 1601 void Run() override { |
1611 server2_channel_ = | 1602 server2_channel_ = SyncChannel::Create( |
1612 SyncChannel::Create("reentrant_reply2", | 1603 "reentrant_reply2", IPC::Channel::MODE_CLIENT, this, |
1613 IPC::Channel::MODE_CLIENT, | 1604 ipc_thread().task_runner().get(), true, shutdown_event()); |
1614 this, | |
1615 ipc_thread().message_loop_proxy().get(), | |
1616 true, | |
1617 shutdown_event()); | |
1618 server_ready_->Signal(); | 1605 server_ready_->Signal(); |
1619 Message* msg = new SyncChannelTestMsg_Reentrant1(); | 1606 Message* msg = new SyncChannelTestMsg_Reentrant1(); |
1620 server2_channel_->Send(msg); | 1607 server2_channel_->Send(msg); |
1621 server2_channel_.reset(); | 1608 server2_channel_.reset(); |
1622 Done(); | 1609 Done(); |
1623 } | 1610 } |
1624 | 1611 |
1625 private: | 1612 private: |
1626 bool OnMessageReceived(const Message& message) override { | 1613 bool OnMessageReceived(const Message& message) override { |
1627 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message) | 1614 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 } | 1773 } |
1787 | 1774 |
1788 // Windows needs to send an out-of-band secret to verify the client end of the | 1775 // Windows needs to send an out-of-band secret to verify the client end of the |
1789 // channel. Test that we still connect correctly in that case. | 1776 // channel. Test that we still connect correctly in that case. |
1790 TEST_F(IPCSyncChannelTest, Verified) { | 1777 TEST_F(IPCSyncChannelTest, Verified) { |
1791 Verified(); | 1778 Verified(); |
1792 } | 1779 } |
1793 | 1780 |
1794 } // namespace | 1781 } // namespace |
1795 } // namespace IPC | 1782 } // namespace IPC |
OLD | NEW |