OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/message_pump/handle_watcher.h" | 5 #include "mojo/message_pump/handle_watcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 void DeleteWatcherAndForwardResult( | 43 void DeleteWatcherAndForwardResult( |
44 HandleWatcher* watcher, | 44 HandleWatcher* watcher, |
45 base::Callback<void(MojoResult)> next_callback, | 45 base::Callback<void(MojoResult)> next_callback, |
46 MojoResult result) { | 46 MojoResult result) { |
47 delete watcher; | 47 delete watcher; |
48 next_callback.Run(result); | 48 next_callback.Run(result); |
49 } | 49 } |
50 | 50 |
51 scoped_ptr<base::MessageLoop> CreateMessageLoop(MessageLoopConfig config) { | 51 std::unique_ptr<base::MessageLoop> CreateMessageLoop(MessageLoopConfig config) { |
52 scoped_ptr<base::MessageLoop> loop; | 52 std::unique_ptr<base::MessageLoop> loop; |
53 if (config == MESSAGE_LOOP_CONFIG_DEFAULT) | 53 if (config == MESSAGE_LOOP_CONFIG_DEFAULT) |
54 loop.reset(new base::MessageLoop()); | 54 loop.reset(new base::MessageLoop()); |
55 else | 55 else |
56 loop.reset(new base::MessageLoop(MessagePumpMojo::Create())); | 56 loop.reset(new base::MessageLoop(MessagePumpMojo::Create())); |
57 return loop; | 57 return loop; |
58 } | 58 } |
59 | 59 |
60 // Helper class to manage the callback and running the message loop waiting for | 60 // Helper class to manage the callback and running the message loop waiting for |
61 // message to be received. Typical usage is something like: | 61 // message to be received. Typical usage is something like: |
62 // Schedule callback returned from GetCallback(). | 62 // Schedule callback returned from GetCallback(). |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 131 } |
132 | 132 |
133 void InstallTickClock() { | 133 void InstallTickClock() { |
134 test::SetTickClockForTest(&tick_clock_); | 134 test::SetTickClockForTest(&tick_clock_); |
135 } | 135 } |
136 | 136 |
137 base::SimpleTestTickClock tick_clock_; | 137 base::SimpleTestTickClock tick_clock_; |
138 | 138 |
139 private: | 139 private: |
140 base::ShadowingAtExitManager at_exit_; | 140 base::ShadowingAtExitManager at_exit_; |
141 scoped_ptr<base::MessageLoop> message_loop_; | 141 std::unique_ptr<base::MessageLoop> message_loop_; |
142 | 142 |
143 DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest); | 143 DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest); |
144 }; | 144 }; |
145 | 145 |
146 INSTANTIATE_TEST_CASE_P( | 146 INSTANTIATE_TEST_CASE_P( |
147 MultipleMessageLoopConfigs, HandleWatcherTest, | 147 MultipleMessageLoopConfigs, HandleWatcherTest, |
148 testing::Values(MESSAGE_LOOP_CONFIG_DEFAULT, MESSAGE_LOOP_CONFIG_MOJO)); | 148 testing::Values(MESSAGE_LOOP_CONFIG_DEFAULT, MESSAGE_LOOP_CONFIG_MOJO)); |
149 | 149 |
150 // Trivial test case with a single handle to watch. | 150 // Trivial test case with a single handle to watch. |
151 TEST_P(HandleWatcherTest, SingleHandler) { | 151 TEST_P(HandleWatcherTest, SingleHandler) { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 callback_helper.Start(&watcher, test_pipe.handle0.get()); | 413 callback_helper.Start(&watcher, test_pipe.handle0.get()); |
414 RunUntilIdle(); | 414 RunUntilIdle(); |
415 EXPECT_FALSE(callback_helper.got_callback()); | 415 EXPECT_FALSE(callback_helper.got_callback()); |
416 EXPECT_TRUE(mojo::test::WriteTextMessage(test_pipe.handle1.get(), | 416 EXPECT_TRUE(mojo::test::WriteTextMessage(test_pipe.handle1.get(), |
417 std::string())); | 417 std::string())); |
418 base::MessageLoop::ScopedNestableTaskAllower scoper( | 418 base::MessageLoop::ScopedNestableTaskAllower scoper( |
419 base::MessageLoop::current()); | 419 base::MessageLoop::current()); |
420 callback_helper.RunUntilGotCallback(); | 420 callback_helper.RunUntilGotCallback(); |
421 EXPECT_TRUE(callback_helper.got_callback()); | 421 EXPECT_TRUE(callback_helper.got_callback()); |
422 } else { | 422 } else { |
423 scoped_ptr<TestData> test_data(new TestData); | 423 std::unique_ptr<TestData> test_data(new TestData); |
424 ASSERT_TRUE(test_data->pipe.handle0.is_valid()); | 424 ASSERT_TRUE(test_data->pipe.handle0.is_valid()); |
425 test_data->watcher.Start(test_data->pipe.handle0.get(), | 425 test_data->watcher.Start(test_data->pipe.handle0.get(), |
426 MOJO_HANDLE_SIGNAL_READABLE, | 426 MOJO_HANDLE_SIGNAL_READABLE, |
427 MOJO_DEADLINE_INDEFINITE, | 427 MOJO_DEADLINE_INDEFINITE, |
428 base::Bind(&NeverReached)); | 428 base::Bind(&NeverReached)); |
429 data_vector.push_back(test_data.release()); | 429 data_vector.push_back(test_data.release()); |
430 } | 430 } |
431 if (i % 15 == 0) | 431 if (i % 15 == 0) |
432 data_vector.clear(); | 432 data_vector.clear(); |
433 } | 433 } |
(...skipping 16 matching lines...) Expand all Loading... |
450 #endif | 450 #endif |
451 | 451 |
452 base::ShadowingAtExitManager at_exit; | 452 base::ShadowingAtExitManager at_exit; |
453 base::MessageLoop message_loop; | 453 base::MessageLoop message_loop; |
454 base::RunLoop run_loop; | 454 base::RunLoop run_loop; |
455 ScopedVector<base::Thread> threads; | 455 ScopedVector<base::Thread> threads; |
456 int threads_active_counter = kThreadCount; | 456 int threads_active_counter = kThreadCount; |
457 // Starts the threads first and then post the task in hopes of having more | 457 // Starts the threads first and then post the task in hopes of having more |
458 // threads running at once. | 458 // threads running at once. |
459 for (int i = 0; i < kThreadCount; ++i) { | 459 for (int i = 0; i < kThreadCount; ++i) { |
460 scoped_ptr<base::Thread> thread(new base::Thread("test thread")); | 460 std::unique_ptr<base::Thread> thread(new base::Thread("test thread")); |
461 if (i % 2) { | 461 if (i % 2) { |
462 base::Thread::Options thread_options; | 462 base::Thread::Options thread_options; |
463 thread_options.message_pump_factory = | 463 thread_options.message_pump_factory = |
464 base::Bind(&MessagePumpMojo::Create); | 464 base::Bind(&MessagePumpMojo::Create); |
465 thread->StartWithOptions(thread_options); | 465 thread->StartWithOptions(thread_options); |
466 } else { | 466 } else { |
467 thread->Start(); | 467 thread->Start(); |
468 } | 468 } |
469 threads.push_back(thread.release()); | 469 threads.push_back(thread.release()); |
470 } | 470 } |
471 for (int i = 0; i < kThreadCount; ++i) { | 471 for (int i = 0; i < kThreadCount; ++i) { |
472 threads[i]->task_runner()->PostTask( | 472 threads[i]->task_runner()->PostTask( |
473 FROM_HERE, base::Bind(&RunStressTest, kWatchCount, | 473 FROM_HERE, base::Bind(&RunStressTest, kWatchCount, |
474 message_loop.task_runner(), | 474 message_loop.task_runner(), |
475 &run_loop, &threads_active_counter)); | 475 &run_loop, &threads_active_counter)); |
476 } | 476 } |
477 run_loop.Run(); | 477 run_loop.Run(); |
478 ASSERT_EQ(0, threads_active_counter); | 478 ASSERT_EQ(0, threads_active_counter); |
479 } | 479 } |
480 | 480 |
481 } // namespace test | 481 } // namespace test |
482 } // namespace common | 482 } // namespace common |
483 } // namespace mojo | 483 } // namespace mojo |
OLD | NEW |