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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/location.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" |
15 #include "ipc/ipc_sync_channel.h" | 17 #include "ipc/ipc_sync_channel.h" |
16 #include "ipc/message_filter.h" | 18 #include "ipc/message_filter.h" |
17 #include "ppapi/c/pp_errors.h" | 19 #include "ppapi/c/pp_errors.h" |
18 #include "ppapi/c/private/ppb_proxy_private.h" | 20 #include "ppapi/c/private/ppb_proxy_private.h" |
19 #include "ppapi/proxy/ppapi_messages.h" | 21 #include "ppapi/proxy/ppapi_messages.h" |
20 #include "ppapi/proxy/ppb_message_loop_proxy.h" | 22 #include "ppapi/proxy/ppb_message_loop_proxy.h" |
21 | 23 |
22 namespace ppapi { | 24 namespace ppapi { |
23 namespace proxy { | 25 namespace proxy { |
24 | 26 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if (interface) | 74 if (interface) |
73 return interface; | 75 return interface; |
74 } | 76 } |
75 if (strcmp(name, PPB_PROXY_PRIVATE_INTERFACE) == 0) | 77 if (strcmp(name, PPB_PROXY_PRIVATE_INTERFACE) == 0) |
76 return &ppb_proxy_private; | 78 return &ppb_proxy_private; |
77 return NULL; | 79 return NULL; |
78 } | 80 } |
79 | 81 |
80 void SetUpRemoteHarness(ProxyTestHarnessBase* harness, | 82 void SetUpRemoteHarness(ProxyTestHarnessBase* harness, |
81 const IPC::ChannelHandle& handle, | 83 const IPC::ChannelHandle& handle, |
82 base::MessageLoopProxy* ipc_message_loop_proxy, | 84 base::SingleThreadTaskRunner* ipc_task_runner, |
83 base::WaitableEvent* shutdown_event, | 85 base::WaitableEvent* shutdown_event, |
84 base::WaitableEvent* harness_set_up) { | 86 base::WaitableEvent* harness_set_up) { |
85 harness->SetUpHarnessWithChannel(handle, ipc_message_loop_proxy, | 87 harness->SetUpHarnessWithChannel(handle, ipc_task_runner, shutdown_event, |
86 shutdown_event, false); | 88 false); |
87 harness_set_up->Signal(); | 89 harness_set_up->Signal(); |
88 } | 90 } |
89 | 91 |
90 void TearDownRemoteHarness(ProxyTestHarnessBase* harness, | 92 void TearDownRemoteHarness(ProxyTestHarnessBase* harness, |
91 base::WaitableEvent* harness_torn_down) { | 93 base::WaitableEvent* harness_torn_down) { |
92 harness->TearDownHarness(); | 94 harness->TearDownHarness(); |
93 harness_torn_down->Signal(); | 95 harness_torn_down->Signal(); |
94 } | 96 } |
95 | 97 |
96 void RunTaskOnRemoteHarness(const base::Closure& task, | 98 void RunTaskOnRemoteHarness(const base::Closure& task, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // in |ResourceCreationProxy::GetConnection| to get the channel to the | 183 // in |ResourceCreationProxy::GetConnection| to get the channel to the |
182 // browser. In this case we just use the |plugin_dispatcher_| as the channel | 184 // browser. In this case we just use the |plugin_dispatcher_| as the channel |
183 // for test purposes. | 185 // for test purposes. |
184 plugin_delegate_mock_.set_browser_sender(plugin_dispatcher_.get()); | 186 plugin_delegate_mock_.set_browser_sender(plugin_dispatcher_.get()); |
185 PluginGlobals::Get()->SetPluginProxyDelegate(&plugin_delegate_mock_); | 187 PluginGlobals::Get()->SetPluginProxyDelegate(&plugin_delegate_mock_); |
186 plugin_dispatcher_->DidCreateInstance(pp_instance()); | 188 plugin_dispatcher_->DidCreateInstance(pp_instance()); |
187 } | 189 } |
188 | 190 |
189 void PluginProxyTestHarness::SetUpHarnessWithChannel( | 191 void PluginProxyTestHarness::SetUpHarnessWithChannel( |
190 const IPC::ChannelHandle& channel_handle, | 192 const IPC::ChannelHandle& channel_handle, |
191 base::MessageLoopProxy* ipc_message_loop, | 193 base::SingleThreadTaskRunner* ipc_task_runner, |
192 base::WaitableEvent* shutdown_event, | 194 base::WaitableEvent* shutdown_event, |
193 bool is_client) { | 195 bool is_client) { |
194 // These must be first since the dispatcher set-up uses them. | 196 // These must be first since the dispatcher set-up uses them. |
195 scoped_refptr<base::TaskRunner> ipc_task_runner(ipc_message_loop); | 197 CreatePluginGlobals(ipc_task_runner); |
196 CreatePluginGlobals(ipc_message_loop); | |
197 // Some of the methods called during set-up check that the lock is held. | 198 // Some of the methods called during set-up check that the lock is held. |
198 ProxyAutoLock lock; | 199 ProxyAutoLock lock; |
199 | 200 |
200 resource_tracker().DidCreateInstance(pp_instance()); | 201 resource_tracker().DidCreateInstance(pp_instance()); |
201 plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); | 202 plugin_delegate_mock_.Init(ipc_task_runner, shutdown_event); |
202 | 203 |
203 plugin_dispatcher_.reset(new PluginDispatcher( | 204 plugin_dispatcher_.reset(new PluginDispatcher( |
204 &MockGetInterface, | 205 &MockGetInterface, |
205 PpapiPermissions(), | 206 PpapiPermissions(), |
206 false)); | 207 false)); |
207 plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, | 208 plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, |
208 base::kNullProcessId, | 209 base::kNullProcessId, |
209 channel_handle, | 210 channel_handle, |
210 is_client); | 211 is_client); |
211 plugin_delegate_mock_.set_browser_sender(plugin_dispatcher_.get()); | 212 plugin_delegate_mock_.set_browser_sender(plugin_dispatcher_.get()); |
(...skipping 20 matching lines...) Expand all Loading... |
232 plugin_globals_.reset(new PluginGlobals(PpapiGlobals::PerThreadForTest(), | 233 plugin_globals_.reset(new PluginGlobals(PpapiGlobals::PerThreadForTest(), |
233 ipc_task_runner)); | 234 ipc_task_runner)); |
234 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); | 235 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
235 } else { | 236 } else { |
236 plugin_globals_.reset(new PluginGlobals(ipc_task_runner)); | 237 plugin_globals_.reset(new PluginGlobals(ipc_task_runner)); |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
240 base::SingleThreadTaskRunner* | 241 base::SingleThreadTaskRunner* |
241 PluginProxyTestHarness::PluginDelegateMock::GetIPCTaskRunner() { | 242 PluginProxyTestHarness::PluginDelegateMock::GetIPCTaskRunner() { |
242 return ipc_message_loop_; | 243 return ipc_task_runner_; |
243 } | 244 } |
244 | 245 |
245 base::WaitableEvent* | 246 base::WaitableEvent* |
246 PluginProxyTestHarness::PluginDelegateMock::GetShutdownEvent() { | 247 PluginProxyTestHarness::PluginDelegateMock::GetShutdownEvent() { |
247 return shutdown_event_; | 248 return shutdown_event_; |
248 } | 249 } |
249 | 250 |
250 IPC::PlatformFileForTransit | 251 IPC::PlatformFileForTransit |
251 PluginProxyTestHarness::PluginDelegateMock::ShareHandleWithRemote( | 252 PluginProxyTestHarness::PluginDelegateMock::ShareHandleWithRemote( |
252 base::PlatformFile handle, | 253 base::PlatformFile handle, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 321 |
321 // PluginProxyMultiThreadTest -------------------------------------------------- | 322 // PluginProxyMultiThreadTest -------------------------------------------------- |
322 | 323 |
323 PluginProxyMultiThreadTest::PluginProxyMultiThreadTest() { | 324 PluginProxyMultiThreadTest::PluginProxyMultiThreadTest() { |
324 } | 325 } |
325 | 326 |
326 PluginProxyMultiThreadTest::~PluginProxyMultiThreadTest() { | 327 PluginProxyMultiThreadTest::~PluginProxyMultiThreadTest() { |
327 } | 328 } |
328 | 329 |
329 void PluginProxyMultiThreadTest::RunTest() { | 330 void PluginProxyMultiThreadTest::RunTest() { |
330 main_thread_message_loop_proxy_ = | 331 main_thread_task_runner_ = PpapiGlobals::Get()->GetMainThreadMessageLoop(); |
331 PpapiGlobals::Get()->GetMainThreadMessageLoop(); | 332 ASSERT_EQ(main_thread_task_runner_.get(), |
332 ASSERT_EQ(main_thread_message_loop_proxy_.get(), | 333 base::ThreadTaskRunnerHandle::Get().get()); |
333 base::MessageLoopProxy::current().get()); | |
334 nested_main_thread_message_loop_.reset(new base::RunLoop()); | 334 nested_main_thread_message_loop_.reset(new base::RunLoop()); |
335 | 335 |
336 secondary_thread_.reset(new base::DelegateSimpleThread( | 336 secondary_thread_.reset(new base::DelegateSimpleThread( |
337 this, "PluginProxyMultiThreadTest")); | 337 this, "PluginProxyMultiThreadTest")); |
338 | 338 |
339 { | 339 { |
340 ProxyAutoLock auto_lock; | 340 ProxyAutoLock auto_lock; |
341 | 341 |
342 // MessageLoopResource assumes that the proxy lock has been acquired. | 342 // MessageLoopResource assumes that the proxy lock has been acquired. |
343 secondary_thread_message_loop_ = new MessageLoopResource(pp_instance()); | 343 secondary_thread_message_loop_ = new MessageLoopResource(pp_instance()); |
(...skipping 15 matching lines...) Expand all Loading... |
359 { | 359 { |
360 ProxyAutoLock auto_lock; | 360 ProxyAutoLock auto_lock; |
361 | 361 |
362 // The destruction requires a valid PpapiGlobals instance, so we should | 362 // The destruction requires a valid PpapiGlobals instance, so we should |
363 // explicitly release it. | 363 // explicitly release it. |
364 secondary_thread_message_loop_ = NULL; | 364 secondary_thread_message_loop_ = NULL; |
365 } | 365 } |
366 | 366 |
367 secondary_thread_.reset(NULL); | 367 secondary_thread_.reset(NULL); |
368 nested_main_thread_message_loop_.reset(NULL); | 368 nested_main_thread_message_loop_.reset(NULL); |
369 main_thread_message_loop_proxy_ = NULL; | 369 main_thread_task_runner_ = NULL; |
370 } | 370 } |
371 | 371 |
372 void PluginProxyMultiThreadTest::CheckOnThread(ThreadType thread_type) { | 372 void PluginProxyMultiThreadTest::CheckOnThread(ThreadType thread_type) { |
373 ProxyAutoLock auto_lock; | 373 ProxyAutoLock auto_lock; |
374 if (thread_type == MAIN_THREAD) { | 374 if (thread_type == MAIN_THREAD) { |
375 ASSERT_TRUE(MessageLoopResource::GetCurrent()->is_main_thread_loop()); | 375 ASSERT_TRUE(MessageLoopResource::GetCurrent()->is_main_thread_loop()); |
376 } else { | 376 } else { |
377 ASSERT_EQ(secondary_thread_message_loop_.get(), | 377 ASSERT_EQ(secondary_thread_message_loop_.get(), |
378 MessageLoopResource::GetCurrent()); | 378 MessageLoopResource::GetCurrent()); |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 void PluginProxyMultiThreadTest::PostQuitForMainThread() { | 382 void PluginProxyMultiThreadTest::PostQuitForMainThread() { |
383 main_thread_message_loop_proxy_->PostTask( | 383 main_thread_task_runner_->PostTask( |
384 FROM_HERE, | 384 FROM_HERE, base::Bind(&PluginProxyMultiThreadTest::QuitNestedLoop, |
385 base::Bind(&PluginProxyMultiThreadTest::QuitNestedLoop, | 385 base::Unretained(this))); |
386 base::Unretained(this))); | |
387 } | 386 } |
388 | 387 |
389 void PluginProxyMultiThreadTest::PostQuitForSecondaryThread() { | 388 void PluginProxyMultiThreadTest::PostQuitForSecondaryThread() { |
390 ProxyAutoLock auto_lock; | 389 ProxyAutoLock auto_lock; |
391 secondary_thread_message_loop_->PostQuit(PP_TRUE); | 390 secondary_thread_message_loop_->PostQuit(PP_TRUE); |
392 } | 391 } |
393 | 392 |
394 void PluginProxyMultiThreadTest::Run() { | 393 void PluginProxyMultiThreadTest::Run() { |
395 ProxyAutoLock auto_lock; | 394 ProxyAutoLock auto_lock; |
396 ASSERT_EQ(PP_OK, secondary_thread_message_loop_->AttachToCurrentThread()); | 395 ASSERT_EQ(PP_OK, secondary_thread_message_loop_->AttachToCurrentThread()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 host_dispatcher_.reset(new HostDispatcher( | 436 host_dispatcher_.reset(new HostDispatcher( |
438 pp_module(), | 437 pp_module(), |
439 &MockGetInterface, | 438 &MockGetInterface, |
440 PpapiPermissions::AllPermissions())); | 439 PpapiPermissions::AllPermissions())); |
441 host_dispatcher_->InitWithTestSink(&sink()); | 440 host_dispatcher_->InitWithTestSink(&sink()); |
442 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); | 441 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
443 } | 442 } |
444 | 443 |
445 void HostProxyTestHarness::SetUpHarnessWithChannel( | 444 void HostProxyTestHarness::SetUpHarnessWithChannel( |
446 const IPC::ChannelHandle& channel_handle, | 445 const IPC::ChannelHandle& channel_handle, |
447 base::MessageLoopProxy* ipc_message_loop, | 446 base::SingleThreadTaskRunner* ipc_task_runner, |
448 base::WaitableEvent* shutdown_event, | 447 base::WaitableEvent* shutdown_event, |
449 bool is_client) { | 448 bool is_client) { |
450 // These must be first since the dispatcher set-up uses them. | 449 // These must be first since the dispatcher set-up uses them. |
451 CreateHostGlobals(); | 450 CreateHostGlobals(); |
452 | 451 |
453 delegate_mock_.Init(ipc_message_loop, shutdown_event); | 452 delegate_mock_.Init(ipc_task_runner, shutdown_event); |
454 | 453 |
455 host_dispatcher_.reset(new HostDispatcher( | 454 host_dispatcher_.reset(new HostDispatcher( |
456 pp_module(), | 455 pp_module(), |
457 &MockGetInterface, | 456 &MockGetInterface, |
458 PpapiPermissions::AllPermissions())); | 457 PpapiPermissions::AllPermissions())); |
459 ppapi::Preferences preferences; | 458 ppapi::Preferences preferences; |
460 host_dispatcher_->InitHostWithChannel(&delegate_mock_, | 459 host_dispatcher_->InitHostWithChannel(&delegate_mock_, |
461 base::kNullProcessId, channel_handle, | 460 base::kNullProcessId, channel_handle, |
462 is_client, preferences); | 461 is_client, preferences); |
463 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); | 462 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
464 } | 463 } |
465 | 464 |
466 void HostProxyTestHarness::TearDownHarness() { | 465 void HostProxyTestHarness::TearDownHarness() { |
467 HostDispatcher::RemoveForInstance(pp_instance()); | 466 HostDispatcher::RemoveForInstance(pp_instance()); |
468 host_dispatcher_.reset(); | 467 host_dispatcher_.reset(); |
469 host_globals_.reset(); | 468 host_globals_.reset(); |
470 } | 469 } |
471 | 470 |
472 void HostProxyTestHarness::CreateHostGlobals() { | 471 void HostProxyTestHarness::CreateHostGlobals() { |
473 disable_locking_.reset(new ProxyLock::LockingDisablerForTest); | 472 disable_locking_.reset(new ProxyLock::LockingDisablerForTest); |
474 if (globals_config_ == PER_THREAD_GLOBALS) { | 473 if (globals_config_ == PER_THREAD_GLOBALS) { |
475 host_globals_.reset(new TestGlobals(PpapiGlobals::PerThreadForTest())); | 474 host_globals_.reset(new TestGlobals(PpapiGlobals::PerThreadForTest())); |
476 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); | 475 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
477 } else { | 476 } else { |
478 host_globals_.reset(new TestGlobals()); | 477 host_globals_.reset(new TestGlobals()); |
479 } | 478 } |
480 } | 479 } |
481 | 480 |
482 base::MessageLoopProxy* HostProxyTestHarness::DelegateMock::GetIPCTaskRunner() { | 481 base::SingleThreadTaskRunner* |
483 return ipc_message_loop_; | 482 HostProxyTestHarness::DelegateMock::GetIPCTaskRunner() { |
| 483 return ipc_task_runner_; |
484 } | 484 } |
485 | 485 |
486 base::WaitableEvent* HostProxyTestHarness::DelegateMock::GetShutdownEvent() { | 486 base::WaitableEvent* HostProxyTestHarness::DelegateMock::GetShutdownEvent() { |
487 return shutdown_event_; | 487 return shutdown_event_; |
488 } | 488 } |
489 | 489 |
490 IPC::PlatformFileForTransit | 490 IPC::PlatformFileForTransit |
491 HostProxyTestHarness::DelegateMock::ShareHandleWithRemote( | 491 HostProxyTestHarness::DelegateMock::ShareHandleWithRemote( |
492 base::PlatformFile handle, | 492 base::PlatformFile handle, |
493 base::ProcessId /* remote_pid */, | 493 base::ProcessId /* remote_pid */, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 options.message_loop_type = base::MessageLoop::TYPE_IO; | 550 options.message_loop_type = base::MessageLoop::TYPE_IO; |
551 io_thread_.StartWithOptions(options); | 551 io_thread_.StartWithOptions(options); |
552 plugin_thread_.Start(); | 552 plugin_thread_.Start(); |
553 | 553 |
554 // Construct the IPC handle name using the process ID so we can safely run | 554 // Construct the IPC handle name using the process ID so we can safely run |
555 // multiple |TwoWayTest|s concurrently. | 555 // multiple |TwoWayTest|s concurrently. |
556 std::ostringstream handle_name; | 556 std::ostringstream handle_name; |
557 handle_name << "TwoWayTestChannel" << base::GetCurrentProcId(); | 557 handle_name << "TwoWayTestChannel" << base::GetCurrentProcId(); |
558 IPC::ChannelHandle handle(handle_name.str()); | 558 IPC::ChannelHandle handle(handle_name.str()); |
559 base::WaitableEvent remote_harness_set_up(true, false); | 559 base::WaitableEvent remote_harness_set_up(true, false); |
560 plugin_thread_.message_loop_proxy()->PostTask( | 560 plugin_thread_.task_runner()->PostTask( |
561 FROM_HERE, | 561 FROM_HERE, base::Bind(&SetUpRemoteHarness, remote_harness_, handle, |
562 base::Bind(&SetUpRemoteHarness, | 562 io_thread_.task_runner(), &shutdown_event_, |
563 remote_harness_, | 563 &remote_harness_set_up)); |
564 handle, | |
565 io_thread_.message_loop_proxy(), | |
566 &shutdown_event_, | |
567 &remote_harness_set_up)); | |
568 remote_harness_set_up.Wait(); | 564 remote_harness_set_up.Wait(); |
569 local_harness_->SetUpHarnessWithChannel(handle, | 565 local_harness_->SetUpHarnessWithChannel( |
570 io_thread_.message_loop_proxy().get(), | 566 handle, io_thread_.task_runner().get(), &shutdown_event_, |
571 &shutdown_event_, | 567 true); // is_client |
572 true); // is_client | |
573 } | 568 } |
574 | 569 |
575 void TwoWayTest::TearDown() { | 570 void TwoWayTest::TearDown() { |
576 base::WaitableEvent remote_harness_torn_down(true, false); | 571 base::WaitableEvent remote_harness_torn_down(true, false); |
577 plugin_thread_.message_loop_proxy()->PostTask( | 572 plugin_thread_.task_runner()->PostTask( |
578 FROM_HERE, | 573 FROM_HERE, base::Bind(&TearDownRemoteHarness, remote_harness_, |
579 base::Bind(&TearDownRemoteHarness, | 574 &remote_harness_torn_down)); |
580 remote_harness_, | |
581 &remote_harness_torn_down)); | |
582 remote_harness_torn_down.Wait(); | 575 remote_harness_torn_down.Wait(); |
583 | 576 |
584 local_harness_->TearDownHarness(); | 577 local_harness_->TearDownHarness(); |
585 | 578 |
586 io_thread_.Stop(); | 579 io_thread_.Stop(); |
587 } | 580 } |
588 | 581 |
589 void TwoWayTest::PostTaskOnRemoteHarness(const base::Closure& task) { | 582 void TwoWayTest::PostTaskOnRemoteHarness(const base::Closure& task) { |
590 base::WaitableEvent task_complete(true, false); | 583 base::WaitableEvent task_complete(true, false); |
591 plugin_thread_.message_loop_proxy()->PostTask(FROM_HERE, | 584 plugin_thread_.task_runner()->PostTask( |
592 base::Bind(&RunTaskOnRemoteHarness, | 585 FROM_HERE, base::Bind(&RunTaskOnRemoteHarness, task, &task_complete)); |
593 task, | |
594 &task_complete)); | |
595 task_complete.Wait(); | 586 task_complete.Wait(); |
596 } | 587 } |
597 | 588 |
598 | 589 |
599 } // namespace proxy | 590 } // namespace proxy |
600 } // namespace ppapi | 591 } // namespace ppapi |
OLD | NEW |