| 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 "chrome/utility/importer/firefox_importer_unittest_utils.h" | 5 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/test/test_timeouts.h" | 21 #include "base/test/test_timeouts.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "chrome/common/importer/firefox_importer_utils.h" | 23 #include "chrome/common/importer/firefox_importer_utils.h" |
| 24 #include "content/public/common/content_descriptors.h" | 24 #include "content/public/common/content_descriptors.h" |
| 25 #include "content/public/common/mojo_channel_switches.h" | 25 #include "content/public/common/mojo_channel_switches.h" |
| 26 #include "ipc/ipc_channel.h" | 26 #include "ipc/ipc_channel.h" |
| 27 #include "ipc/ipc_descriptors.h" | 27 #include "ipc/ipc_descriptors.h" |
| 28 #include "ipc/ipc_listener.h" | 28 #include "ipc/ipc_listener.h" |
| 29 #include "ipc/ipc_message.h" | 29 #include "ipc/ipc_message.h" |
| 30 #include "mojo/edk/embedder/embedder.h" | 30 #include "mojo/edk/embedder/embedder.h" |
| 31 #include "mojo/edk/embedder/pending_process_connection.h" |
| 31 #include "mojo/edk/embedder/platform_channel_pair.h" | 32 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 32 #include "mojo/edk/embedder/scoped_platform_handle.h" | 33 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 33 #include "testing/multiprocess_func_list.h" | 34 #include "testing/multiprocess_func_list.h" |
| 34 | 35 |
| 35 #define IPC_MESSAGE_IMPL | 36 #define IPC_MESSAGE_IMPL |
| 36 #include "chrome/utility/importer/firefox_importer_unittest_messages_internal.h" | 37 #include "chrome/utility/importer/firefox_importer_unittest_messages_internal.h" |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 // Launch the child process: | 41 // Launch the child process: |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() { | 140 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() { |
| 140 } | 141 } |
| 141 | 142 |
| 142 bool FFUnitTestDecryptorProxy::Setup(const base::FilePath& nss_path) { | 143 bool FFUnitTestDecryptorProxy::Setup(const base::FilePath& nss_path) { |
| 143 // Create a new message loop and spawn the child process. | 144 // Create a new message loop and spawn the child process. |
| 144 message_loop_.reset(new base::MessageLoopForIO()); | 145 message_loop_.reset(new base::MessageLoopForIO()); |
| 145 | 146 |
| 146 listener_.reset(new FFDecryptorServerChannelListener()); | 147 listener_.reset(new FFDecryptorServerChannelListener()); |
| 147 | 148 |
| 148 // Set up IPC channel using ChannelMojo. | 149 // Set up IPC channel using ChannelMojo. |
| 149 const std::string mojo_child_token = mojo::edk::GenerateRandomToken(); | 150 mojo::edk::PendingProcessConnection process; |
| 150 const std::string mojo_channel_token = mojo::edk::GenerateRandomToken(); | 151 std::string token; |
| 151 mojo::ScopedMessagePipeHandle parent_handle = | 152 mojo::ScopedMessagePipeHandle parent_pipe = process.CreateMessagePipe(&token); |
| 152 mojo::edk::CreateParentMessagePipe(mojo_channel_token, mojo_child_token); | 153 channel_ = IPC::Channel::CreateServer(parent_pipe.release(), listener_.get()); |
| 153 channel_ = IPC::Channel::CreateServer(parent_handle.release(), | |
| 154 listener_.get()); | |
| 155 CHECK(channel_->Connect()); | 154 CHECK(channel_->Connect()); |
| 156 listener_->SetSender(channel_.get()); | 155 listener_->SetSender(channel_.get()); |
| 157 | 156 |
| 158 // Spawn child and set up sync IPC connection. | 157 // Spawn child and set up sync IPC connection. |
| 159 mojo::edk::PlatformChannelPair channel_pair; | 158 mojo::edk::PlatformChannelPair channel_pair; |
| 160 child_process_ = LaunchNSSDecrypterChildProcess( | 159 child_process_ = LaunchNSSDecrypterChildProcess( |
| 161 nss_path, channel_pair.PassClientHandle(), mojo_channel_token); | 160 nss_path, channel_pair.PassClientHandle(), token); |
| 162 if (child_process_.IsValid()) { | 161 if (child_process_.IsValid()) |
| 163 mojo::edk::ChildProcessLaunched(child_process_.Handle(), | 162 process.Connect(child_process_.Handle(), channel_pair.PassServerHandle()); |
| 164 channel_pair.PassServerHandle(), | |
| 165 mojo_child_token); | |
| 166 } else { | |
| 167 mojo::edk::ChildProcessLaunchFailed(mojo_child_token); | |
| 168 } | |
| 169 | |
| 170 return child_process_.IsValid(); | 163 return child_process_.IsValid(); |
| 171 } | 164 } |
| 172 | 165 |
| 173 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { | 166 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { |
| 174 listener_->QuitClient(); | 167 listener_->QuitClient(); |
| 175 channel_->Close(); | 168 channel_->Close(); |
| 176 | 169 |
| 177 if (child_process_.IsValid()) { | 170 if (child_process_.IsValid()) { |
| 178 int exit_code; | 171 int exit_code; |
| 179 child_process_.WaitForExitWithTimeout(base::TimeDelta::FromSeconds(5), | 172 child_process_.WaitForExitWithTimeout(base::TimeDelta::FromSeconds(5), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 std::unique_ptr<IPC::Channel> channel = | 288 std::unique_ptr<IPC::Channel> channel = |
| 296 IPC::Channel::CreateClient(mojo_handle.release(), &listener); | 289 IPC::Channel::CreateClient(mojo_handle.release(), &listener); |
| 297 CHECK(channel->Connect()); | 290 CHECK(channel->Connect()); |
| 298 listener.SetSender(channel.get()); | 291 listener.SetSender(channel.get()); |
| 299 | 292 |
| 300 // run message loop | 293 // run message loop |
| 301 base::RunLoop().Run(); | 294 base::RunLoop().Run(); |
| 302 | 295 |
| 303 return 0; | 296 return 0; |
| 304 } | 297 } |
| OLD | NEW |