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

Side by Side Diff: mojo/public/cpp/bindings/tests/associated_interface_unittest.cc

Issue 2958703002: Rename TaskRunner::RunsTasksOnCurrentThread() in //ipc, //mojo (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void CreateIntegerSender(IntegerSenderAssociatedPtrInfo* ptr_info, 138 void CreateIntegerSender(IntegerSenderAssociatedPtrInfo* ptr_info,
139 IntegerSenderAssociatedRequest* request) { 139 IntegerSenderAssociatedRequest* request) {
140 scoped_refptr<MultiplexRouter> router0; 140 scoped_refptr<MultiplexRouter> router0;
141 scoped_refptr<MultiplexRouter> router1; 141 scoped_refptr<MultiplexRouter> router1;
142 CreateRouterPair(&router0, &router1); 142 CreateRouterPair(&router0, &router1);
143 CreateIntegerSenderWithExistingRouters(router1, ptr_info, router0, request); 143 CreateIntegerSenderWithExistingRouters(router1, ptr_info, router0, request);
144 } 144 }
145 145
146 // Okay to call from any thread. 146 // Okay to call from any thread.
147 void QuitRunLoop(base::RunLoop* run_loop) { 147 void QuitRunLoop(base::RunLoop* run_loop) {
148 if (main_runner_->RunsTasksOnCurrentThread()) { 148 if (main_runner_->RunsTasksInCurrentSequence()) {
149 run_loop->Quit(); 149 run_loop->Quit();
150 } else { 150 } else {
151 main_runner_->PostTask( 151 main_runner_->PostTask(
152 FROM_HERE, 152 FROM_HERE,
153 base::Bind(&AssociatedInterfaceTest::QuitRunLoop, 153 base::Bind(&AssociatedInterfaceTest::QuitRunLoop,
154 base::Unretained(this), base::Unretained(run_loop))); 154 base::Unretained(this), base::Unretained(run_loop)));
155 } 155 }
156 } 156 }
157 157
158 private: 158 private:
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 public: 248 public:
249 TestSender() 249 TestSender()
250 : task_runner_(base::CreateSequencedTaskRunnerWithTraits({})), 250 : task_runner_(base::CreateSequencedTaskRunnerWithTraits({})),
251 next_sender_(nullptr), 251 next_sender_(nullptr),
252 max_value_to_send_(-1) {} 252 max_value_to_send_(-1) {}
253 253
254 // The following three methods are called on the corresponding sender thread. 254 // The following three methods are called on the corresponding sender thread.
255 void SetUp(IntegerSenderAssociatedPtrInfo ptr_info, 255 void SetUp(IntegerSenderAssociatedPtrInfo ptr_info,
256 TestSender* next_sender, 256 TestSender* next_sender,
257 int32_t max_value_to_send) { 257 int32_t max_value_to_send) {
258 CHECK(task_runner()->RunsTasksOnCurrentThread()); 258 CHECK(task_runner()->RunsTasksInCurrentSequence());
259 259
260 ptr_.Bind(std::move(ptr_info)); 260 ptr_.Bind(std::move(ptr_info));
261 next_sender_ = next_sender ? next_sender : this; 261 next_sender_ = next_sender ? next_sender : this;
262 max_value_to_send_ = max_value_to_send; 262 max_value_to_send_ = max_value_to_send;
263 } 263 }
264 264
265 void Send(int32_t value) { 265 void Send(int32_t value) {
266 CHECK(task_runner()->RunsTasksOnCurrentThread()); 266 CHECK(task_runner()->RunsTasksInCurrentSequence());
267 267
268 if (value > max_value_to_send_) 268 if (value > max_value_to_send_)
269 return; 269 return;
270 270
271 ptr_->Send(value); 271 ptr_->Send(value);
272 272
273 next_sender_->task_runner()->PostTask( 273 next_sender_->task_runner()->PostTask(
274 FROM_HERE, 274 FROM_HERE,
275 base::Bind(&TestSender::Send, base::Unretained(next_sender_), ++value)); 275 base::Bind(&TestSender::Send, base::Unretained(next_sender_), ++value));
276 } 276 }
277 277
278 void TearDown() { 278 void TearDown() {
279 CHECK(task_runner()->RunsTasksOnCurrentThread()); 279 CHECK(task_runner()->RunsTasksInCurrentSequence());
280 280
281 ptr_.reset(); 281 ptr_.reset();
282 } 282 }
283 283
284 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } 284 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); }
285 285
286 private: 286 private:
287 scoped_refptr<base::SequencedTaskRunner> task_runner_; 287 scoped_refptr<base::SequencedTaskRunner> task_runner_;
288 TestSender* next_sender_; 288 TestSender* next_sender_;
289 int32_t max_value_to_send_; 289 int32_t max_value_to_send_;
290 290
291 AssociatedInterfacePtr<IntegerSender> ptr_; 291 AssociatedInterfacePtr<IntegerSender> ptr_;
292 }; 292 };
293 293
294 class TestReceiver { 294 class TestReceiver {
295 public: 295 public:
296 TestReceiver() 296 TestReceiver()
297 : task_runner_(base::CreateSequencedTaskRunnerWithTraits({})), 297 : task_runner_(base::CreateSequencedTaskRunnerWithTraits({})),
298 expected_calls_(0) {} 298 expected_calls_(0) {}
299 299
300 void SetUp(AssociatedInterfaceRequest<IntegerSender> request0, 300 void SetUp(AssociatedInterfaceRequest<IntegerSender> request0,
301 AssociatedInterfaceRequest<IntegerSender> request1, 301 AssociatedInterfaceRequest<IntegerSender> request1,
302 size_t expected_calls, 302 size_t expected_calls,
303 const base::Closure& notify_finish) { 303 const base::Closure& notify_finish) {
304 CHECK(task_runner()->RunsTasksOnCurrentThread()); 304 CHECK(task_runner()->RunsTasksInCurrentSequence());
305 305
306 impl0_.reset(new IntegerSenderImpl(std::move(request0))); 306 impl0_.reset(new IntegerSenderImpl(std::move(request0)));
307 impl0_->set_notify_send_method_called( 307 impl0_->set_notify_send_method_called(
308 base::Bind(&TestReceiver::SendMethodCalled, base::Unretained(this))); 308 base::Bind(&TestReceiver::SendMethodCalled, base::Unretained(this)));
309 impl1_.reset(new IntegerSenderImpl(std::move(request1))); 309 impl1_.reset(new IntegerSenderImpl(std::move(request1)));
310 impl1_->set_notify_send_method_called( 310 impl1_->set_notify_send_method_called(
311 base::Bind(&TestReceiver::SendMethodCalled, base::Unretained(this))); 311 base::Bind(&TestReceiver::SendMethodCalled, base::Unretained(this)));
312 312
313 expected_calls_ = expected_calls; 313 expected_calls_ = expected_calls;
314 notify_finish_ = notify_finish; 314 notify_finish_ = notify_finish;
315 } 315 }
316 316
317 void TearDown() { 317 void TearDown() {
318 CHECK(task_runner()->RunsTasksOnCurrentThread()); 318 CHECK(task_runner()->RunsTasksInCurrentSequence());
319 319
320 impl0_.reset(); 320 impl0_.reset();
321 impl1_.reset(); 321 impl1_.reset();
322 } 322 }
323 323
324 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } 324 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); }
325 const std::vector<int32_t>& values() const { return values_; } 325 const std::vector<int32_t>& values() const { return values_; }
326 326
327 private: 327 private:
328 void SendMethodCalled(int32_t value) { 328 void SendMethodCalled(int32_t value) {
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 1178
1179 TEST_F(AssociatedInterfaceTest, GetIsolatedInterface) { 1179 TEST_F(AssociatedInterfaceTest, GetIsolatedInterface) {
1180 IntegerSenderAssociatedPtr sender; 1180 IntegerSenderAssociatedPtr sender;
1181 GetIsolatedInterface(MakeRequest(&sender).PassHandle()); 1181 GetIsolatedInterface(MakeRequest(&sender).PassHandle());
1182 sender->Send(42); 1182 sender->Send(42);
1183 } 1183 }
1184 1184
1185 } // namespace 1185 } // namespace
1186 } // namespace test 1186 } // namespace test
1187 } // namespace mojo 1187 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698