| 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 "ppapi/proxy/ppapi_proxy_test.h" | 5 #include "ppapi/proxy/ppapi_proxy_test.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // TwoWayTest --------------------------------------------------------------- | 520 // TwoWayTest --------------------------------------------------------------- |
| 521 | 521 |
| 522 TwoWayTest::TwoWayTest(TwoWayTest::TwoWayTestMode test_mode) | 522 TwoWayTest::TwoWayTest(TwoWayTest::TwoWayTestMode test_mode) |
| 523 : test_mode_(test_mode), | 523 : test_mode_(test_mode), |
| 524 host_(ProxyTestHarnessBase::PER_THREAD_GLOBALS), | 524 host_(ProxyTestHarnessBase::PER_THREAD_GLOBALS), |
| 525 plugin_(ProxyTestHarnessBase::PER_THREAD_GLOBALS), | 525 plugin_(ProxyTestHarnessBase::PER_THREAD_GLOBALS), |
| 526 io_thread_("TwoWayTest_IOThread"), | 526 io_thread_("TwoWayTest_IOThread"), |
| 527 plugin_thread_("TwoWayTest_PluginThread"), | 527 plugin_thread_("TwoWayTest_PluginThread"), |
| 528 remote_harness_(NULL), | 528 remote_harness_(NULL), |
| 529 local_harness_(NULL), | 529 local_harness_(NULL), |
| 530 channel_created_(true, false), | 530 channel_created_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 531 shutdown_event_(true, false) { | 531 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 532 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 533 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
| 532 if (test_mode == TEST_PPP_INTERFACE) { | 534 if (test_mode == TEST_PPP_INTERFACE) { |
| 533 remote_harness_ = &plugin_; | 535 remote_harness_ = &plugin_; |
| 534 local_harness_ = &host_; | 536 local_harness_ = &host_; |
| 535 } else { | 537 } else { |
| 536 remote_harness_ = &host_; | 538 remote_harness_ = &host_; |
| 537 local_harness_ = &plugin_; | 539 local_harness_ = &plugin_; |
| 538 } | 540 } |
| 539 } | 541 } |
| 540 | 542 |
| 541 TwoWayTest::~TwoWayTest() { | 543 TwoWayTest::~TwoWayTest() { |
| 542 shutdown_event_.Signal(); | 544 shutdown_event_.Signal(); |
| 543 } | 545 } |
| 544 | 546 |
| 545 void TwoWayTest::SetUp() { | 547 void TwoWayTest::SetUp() { |
| 546 base::Thread::Options options; | 548 base::Thread::Options options; |
| 547 options.message_loop_type = base::MessageLoop::TYPE_IO; | 549 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 548 io_thread_.StartWithOptions(options); | 550 io_thread_.StartWithOptions(options); |
| 549 plugin_thread_.Start(); | 551 plugin_thread_.Start(); |
| 550 | 552 |
| 551 // Construct the IPC handle name using the process ID so we can safely run | 553 // Construct the IPC handle name using the process ID so we can safely run |
| 552 // multiple |TwoWayTest|s concurrently. | 554 // multiple |TwoWayTest|s concurrently. |
| 553 std::ostringstream handle_name; | 555 std::ostringstream handle_name; |
| 554 handle_name << "TwoWayTestChannel" << base::GetCurrentProcId(); | 556 handle_name << "TwoWayTestChannel" << base::GetCurrentProcId(); |
| 555 IPC::ChannelHandle handle(handle_name.str()); | 557 IPC::ChannelHandle handle(handle_name.str()); |
| 556 base::WaitableEvent remote_harness_set_up(true, false); | 558 base::WaitableEvent remote_harness_set_up( |
| 559 base::WaitableEvent::ResetPolicy::MANUAL, |
| 560 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 557 plugin_thread_.task_runner()->PostTask( | 561 plugin_thread_.task_runner()->PostTask( |
| 558 FROM_HERE, base::Bind(&SetUpRemoteHarness, remote_harness_, handle, | 562 FROM_HERE, base::Bind(&SetUpRemoteHarness, remote_harness_, handle, |
| 559 base::RetainedRef(io_thread_.task_runner()), | 563 base::RetainedRef(io_thread_.task_runner()), |
| 560 &shutdown_event_, &remote_harness_set_up)); | 564 &shutdown_event_, &remote_harness_set_up)); |
| 561 remote_harness_set_up.Wait(); | 565 remote_harness_set_up.Wait(); |
| 562 local_harness_->SetUpHarnessWithChannel( | 566 local_harness_->SetUpHarnessWithChannel( |
| 563 handle, io_thread_.task_runner().get(), &shutdown_event_, | 567 handle, io_thread_.task_runner().get(), &shutdown_event_, |
| 564 true); // is_client | 568 true); // is_client |
| 565 } | 569 } |
| 566 | 570 |
| 567 void TwoWayTest::TearDown() { | 571 void TwoWayTest::TearDown() { |
| 568 base::WaitableEvent remote_harness_torn_down(true, false); | 572 base::WaitableEvent remote_harness_torn_down( |
| 573 base::WaitableEvent::ResetPolicy::MANUAL, |
| 574 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 569 plugin_thread_.task_runner()->PostTask( | 575 plugin_thread_.task_runner()->PostTask( |
| 570 FROM_HERE, base::Bind(&TearDownRemoteHarness, remote_harness_, | 576 FROM_HERE, base::Bind(&TearDownRemoteHarness, remote_harness_, |
| 571 &remote_harness_torn_down)); | 577 &remote_harness_torn_down)); |
| 572 remote_harness_torn_down.Wait(); | 578 remote_harness_torn_down.Wait(); |
| 573 | 579 |
| 574 local_harness_->TearDownHarness(); | 580 local_harness_->TearDownHarness(); |
| 575 | 581 |
| 576 io_thread_.Stop(); | 582 io_thread_.Stop(); |
| 577 } | 583 } |
| 578 | 584 |
| 579 void TwoWayTest::PostTaskOnRemoteHarness(const base::Closure& task) { | 585 void TwoWayTest::PostTaskOnRemoteHarness(const base::Closure& task) { |
| 580 base::WaitableEvent task_complete(true, false); | 586 base::WaitableEvent task_complete( |
| 587 base::WaitableEvent::ResetPolicy::MANUAL, |
| 588 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 581 plugin_thread_.task_runner()->PostTask( | 589 plugin_thread_.task_runner()->PostTask( |
| 582 FROM_HERE, base::Bind(&RunTaskOnRemoteHarness, task, &task_complete)); | 590 FROM_HERE, base::Bind(&RunTaskOnRemoteHarness, task, &task_complete)); |
| 583 task_complete.Wait(); | 591 task_complete.Wait(); |
| 584 } | 592 } |
| 585 | 593 |
| 586 | 594 |
| 587 } // namespace proxy | 595 } // namespace proxy |
| 588 } // namespace ppapi | 596 } // namespace ppapi |
| OLD | NEW |