Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/importer/firefox_importer_unittest_utils_mac.cc

Issue 7870008: Wait properly for renderer crashes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win? Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser/importer/firefox_importer_unittest_utils.h" 5 #include "chrome/browser/importer/firefox_importer_unittest_utils.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
12 #include "chrome/browser/importer/firefox_importer_utils.h" 13 #include "chrome/browser/importer/firefox_importer_utils.h"
13 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
14 #include "ipc/ipc_descriptors.h" 15 #include "ipc/ipc_descriptors.h"
15 #include "ipc/ipc_message.h" 16 #include "ipc/ipc_message.h"
16 #include "ipc/ipc_switches.h" 17 #include "ipc/ipc_switches.h"
17 #include "testing/multiprocess_func_list.h" 18 #include "testing/multiprocess_func_list.h"
18 19
19 #define IPC_MESSAGE_IMPL 20 #define IPC_MESSAGE_IMPL
20 #include "chrome/browser/importer/firefox_importer_unittest_messages_internal.h" 21 #include "chrome/browser/importer/firefox_importer_unittest_messages_internal.h"
21 22
22 namespace { 23 namespace {
23 24
24 // Name of IPC Channel to use for Server<-> Child Communications. 25 // Name of IPC Channel to use for Server<-> Child Communications.
25 const char kTestChannelID[] = "T1"; 26 const char kTestChannelID[] = "T1";
26 27
27 // Launch the child process: 28 // Launch the child process:
28 // |nss_path| - path to the NSS directory holding the decryption libraries. 29 // |nss_path| - path to the NSS directory holding the decryption libraries.
29 // |channel| - IPC Channel to use for communication. 30 // |channel| - IPC Channel to use for communication.
30 // |handle| - On return, the process handle to use to communicate with the 31 // |handle| - On return, the process handle to use to communicate with the
31 // child. 32 // child.
32 bool LaunchNSSDecrypterChildProcess(const FilePath& nss_path, 33 bool LaunchNSSDecrypterChildProcess(const FilePath& nss_path,
33 const IPC::Channel& channel, base::ProcessHandle* handle) { 34 IPC::Channel* channel, base::ProcessHandle* handle) {
34 CommandLine cl(*CommandLine::ForCurrentProcess()); 35 CommandLine cl(*CommandLine::ForCurrentProcess());
35 cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); 36 cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess");
36 37
37 // Set env variable needed for FF encryption libs to load. 38 // Set env variable needed for FF encryption libs to load.
38 // See "chrome/browser/importer/nss_decryptor_mac.mm" for an explanation of 39 // See "chrome/browser/importer/nss_decryptor_mac.mm" for an explanation of
39 // why we need this. 40 // why we need this.
40 base::environment_vector env; 41 base::environment_vector env;
41 std::pair<std::string, std::string> dyld_override; 42 std::pair<std::string, std::string> dyld_override;
42 dyld_override.first = "DYLD_FALLBACK_LIBRARY_PATH"; 43 dyld_override.first = "DYLD_FALLBACK_LIBRARY_PATH";
43 dyld_override.second = nss_path.value(); 44 dyld_override.second = nss_path.value();
44 env.push_back(dyld_override); 45 env.push_back(dyld_override);
45 46
46 base::file_handle_mapping_vector fds_to_map; 47 base::file_handle_mapping_vector fds_to_map;
47 const int ipcfd = channel.GetClientFileDescriptor(); 48 const int ipcfd = channel->TakeClientFileDescriptor();
48 if (ipcfd > -1) { 49 if (ipcfd > -1) {
darin (slow to review) 2011/09/15 05:43:37 shouldn't this be "ipcfd != -1" ?
Paweł Hajdan Jr. 2011/09/15 18:36:44 Done.
49 fds_to_map.push_back(std::pair<int,int>(ipcfd, kPrimaryIPCChannel + 3)); 50 fds_to_map.push_back(std::pair<int,int>(ipcfd, kPrimaryIPCChannel + 3));
50 } else { 51 } else {
51 return false; 52 return false;
52 } 53 }
54 file_util::ScopedFD client_file_descriptor_closer(&ipcfd);
53 55
54 bool debug_on_start = CommandLine::ForCurrentProcess()->HasSwitch( 56 bool debug_on_start = CommandLine::ForCurrentProcess()->HasSwitch(
55 switches::kDebugChildren); 57 switches::kDebugChildren);
56 base::LaunchOptions options; 58 base::LaunchOptions options;
57 options.environ = &env; 59 options.environ = &env;
58 options.fds_to_remap = &fds_to_map; 60 options.fds_to_remap = &fds_to_map;
59 options.wait = debug_on_start; 61 options.wait = debug_on_start;
60 return base::LaunchProcess(cl.argv(), options, handle); 62 return base::LaunchProcess(cl.argv(), options, handle);
61 } 63 }
62 64
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 134
133 listener_.reset(new FFDecryptorServerChannelListener()); 135 listener_.reset(new FFDecryptorServerChannelListener());
134 channel_.reset(new IPC::Channel(kTestChannelID, 136 channel_.reset(new IPC::Channel(kTestChannelID,
135 IPC::Channel::MODE_SERVER, 137 IPC::Channel::MODE_SERVER,
136 listener_.get())); 138 listener_.get()));
137 CHECK(channel_->Connect()); 139 CHECK(channel_->Connect());
138 listener_->SetSender(channel_.get()); 140 listener_->SetSender(channel_.get());
139 141
140 // Spawn child and set up sync IPC connection. 142 // Spawn child and set up sync IPC connection.
141 bool ret = LaunchNSSDecrypterChildProcess(nss_path, 143 bool ret = LaunchNSSDecrypterChildProcess(nss_path,
142 *(channel_.get()), 144 channel_.get(),
143 &child_process_); 145 &child_process_);
144 return ret && (child_process_ != 0); 146 return ret && (child_process_ != 0);
145 } 147 }
146 148
147 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { 149 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() {
148 listener_->QuitClient(); 150 listener_->QuitClient();
149 channel_->Close(); 151 channel_->Close();
150 152
151 if (child_process_) { 153 if (child_process_) {
152 base::WaitForSingleProcess(child_process_, 5000); 154 base::WaitForSingleProcess(child_process_, 5000);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 265
264 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); 266 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener);
265 CHECK(channel.Connect()); 267 CHECK(channel.Connect());
266 listener.SetSender(&channel); 268 listener.SetSender(&channel);
267 269
268 // run message loop 270 // run message loop
269 MessageLoop::current()->Run(); 271 MessageLoop::current()->Run();
270 272
271 return 0; 273 return 0;
272 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698