OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/test/render_thread_impl_browser_test_ipc_helper.h" | 5 #include "content/test/render_thread_impl_browser_test_ipc_helper.h" |
6 | 6 |
7 #include "ipc/mojo/ipc_channel_mojo_host.h" | 7 #include "ipc/mojo/ipc_channel_mojo_host.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 class RenderThreadImplBrowserIPCTestHelper::DummyListener | 12 class RenderThreadImplBrowserIPCTestHelper::DummyListener |
13 : public IPC::Listener { | 13 : public IPC::Listener { |
14 public: | 14 public: |
15 bool OnMessageReceived(const IPC::Message& message) override { return true; } | 15 bool OnMessageReceived(const IPC::Message& message) override { return true; } |
16 }; | 16 }; |
17 | 17 |
18 RenderThreadImplBrowserIPCTestHelper::RenderThreadImplBrowserIPCTestHelper() { | 18 RenderThreadImplBrowserIPCTestHelper::RenderThreadImplBrowserIPCTestHelper() { |
19 message_loop_.reset(new base::MessageLoopForIO()); | 19 message_loop_.reset(new base::MessageLoopForIO()); |
20 | 20 |
21 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(""); | 21 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(""); |
22 dummy_listener_.reset(new DummyListener()); | 22 dummy_listener_.reset(new DummyListener()); |
23 | 23 |
24 SetupIpcThread(); | 24 SetupIpcThread(); |
25 | 25 |
26 // TODO(crbug.com/451221): Mojo should be used here even for Android. | 26 if (IPC::ChannelMojo::ShouldBeUsed()) { |
27 // Currently SetupMojo() calls InitializeMojo() which can be called at most | |
28 // once for each process. This implices that every test case using | |
29 // RenderThreadImplBrowserIPCTestHelper has to run in a dedicated process, but | |
30 // that is false on OS_ANDROID. There is no way to call InitializeMojo() only | |
31 // if it isn't initialized yet. | |
32 #if defined(OS_ANDROID) | |
33 bool use_mojo_channel = false; | |
34 #else | |
35 bool use_mojo_channel = IPC::ChannelMojo::ShouldBeUsed(); | |
36 #endif | |
37 if (use_mojo_channel) { | |
38 SetupMojo(); | 27 SetupMojo(); |
39 } else { | 28 } else { |
40 channel_ = IPC::ChannelProxy::Create(channel_id_, IPC::Channel::MODE_SERVER, | 29 channel_ = IPC::ChannelProxy::Create(channel_id_, IPC::Channel::MODE_SERVER, |
41 dummy_listener_.get(), | 30 dummy_listener_.get(), |
42 ipc_thread_->task_runner()); | 31 ipc_thread_->task_runner()); |
43 } | 32 } |
44 } | 33 } |
45 | 34 |
46 RenderThreadImplBrowserIPCTestHelper::~RenderThreadImplBrowserIPCTestHelper() { | 35 RenderThreadImplBrowserIPCTestHelper::~RenderThreadImplBrowserIPCTestHelper() { |
47 } | 36 } |
(...skipping 16 matching lines...) Expand all Loading... |
64 channel_id_), | 53 channel_id_), |
65 dummy_listener_.get(), ipc_thread_->task_runner()); | 54 dummy_listener_.get(), ipc_thread_->task_runner()); |
66 | 55 |
67 mojo_application_host_->Init(); | 56 mojo_application_host_->Init(); |
68 mojo_application_host_->Activate(channel_.get(), | 57 mojo_application_host_->Activate(channel_.get(), |
69 base::GetCurrentProcessHandle()); | 58 base::GetCurrentProcessHandle()); |
70 mojo_host_->OnClientLaunched(base::GetCurrentProcessHandle()); | 59 mojo_host_->OnClientLaunched(base::GetCurrentProcessHandle()); |
71 } | 60 } |
72 | 61 |
73 } // namespace content | 62 } // namespace content |
OLD | NEW |