Skip to content

Commit

Permalink
Clean up users of a deprecated base::LaunchApp API.
Browse files Browse the repository at this point in the history
BUG=88990

Review URL: http://codereview.chromium.org/7346017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92393 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
evan@chromium.org committed Jul 13, 2011
1 parent 96b3760 commit b5ce736
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 75 deletions.
11 changes: 0 additions & 11 deletions base/process_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,6 @@ inline bool LaunchAppAsUser(UserTokenHandle token,
BASE_API bool LaunchProcess(const std::vector<std::string>& argv,
const LaunchOptions& options);

// TODO(evan): deprecated; change callers to use LaunchProcess, remove.
inline bool LaunchApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
bool wait, ProcessHandle* process_handle) {
LaunchOptions options;
options.fds_to_remap = &fds_to_remap;
options.wait = wait;
options.process_handle = process_handle;
return LaunchProcess(argv, options);
}

// AlterEnvironment returns a modified environment vector, constructed from the
// given environment and the list of changes given in |changes|. Each key in
// the environment is matched against the first element of the pairs. In the
Expand Down
32 changes: 9 additions & 23 deletions base/test/multiprocess_test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -19,12 +19,8 @@ MultiProcessTest::MultiProcessTest() {

ProcessHandle MultiProcessTest::SpawnChild(const std::string& procname,
bool debug_on_start) {
#if defined(OS_WIN)
return SpawnChildImpl(procname, debug_on_start);
#elif defined(OS_POSIX)
file_handle_mapping_vector empty_file_list;
return SpawnChildImpl(procname, empty_file_list, debug_on_start);
#endif
}

#if defined(OS_POSIX)
Expand All @@ -45,30 +41,20 @@ CommandLine MultiProcessTest::MakeCmdLine(const std::string& procname,
return cl;
}

#if defined(OS_WIN)

ProcessHandle MultiProcessTest::SpawnChildImpl(const std::string& procname,
bool debug_on_start) {
ProcessHandle handle = static_cast<ProcessHandle>(NULL);
LaunchApp(MakeCmdLine(procname, debug_on_start),
false, true, &handle);
return handle;
}

#elif defined(OS_POSIX)

// TODO(port): with the CommandLine refactoring, this code is very similar
// to the Windows code. Investigate whether this can be made shorter.
ProcessHandle MultiProcessTest::SpawnChildImpl(
const std::string& procname,
const file_handle_mapping_vector& fds_to_map,
bool debug_on_start) {
ProcessHandle handle = kNullProcessHandle;
LaunchApp(MakeCmdLine(procname, debug_on_start).argv(),
fds_to_map, false, &handle);
base::LaunchOptions options;
options.process_handle = &handle;
#if defined(OS_WIN)
options.start_hidden = true;
#else
options.fds_to_remap = &fds_to_map;
#endif
base::LaunchProcess(MakeCmdLine(procname, debug_on_start), options);
return handle;
}

#endif

} // namespace base
16 changes: 7 additions & 9 deletions base/test/multiprocess_test.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -58,6 +58,9 @@ class MultiProcessTest : public PlatformTest {
ProcessHandle SpawnChild(const std::string& procname, bool debug_on_start);

#if defined(OS_POSIX)
// TODO(evan): see if we can delete this via more refactoring.
// SpawnChild() should just take a base::LaunchOptions so that we don't
// need multiple versions of it.
ProcessHandle SpawnChild(const std::string& procname,
const file_handle_mapping_vector& fds_to_map,
bool debug_on_start);
Expand All @@ -68,17 +71,12 @@ class MultiProcessTest : public PlatformTest {
bool debug_on_start);

private:
#if defined(OS_WIN)
ProcessHandle SpawnChildImpl(const std::string& procname,
bool debug_on_start);

#elif defined(OS_POSIX)
// TODO(port): with the CommandLine refactoring, this code is very similar
// to the Windows code. Investigate whether this can be made shorter.
// Shared implementation of SpawnChild.
// TODO: |fds_to_map| is unused on Windows; see above TODO about
// further refactoring.
ProcessHandle SpawnChildImpl(const std::string& procname,
const file_handle_mapping_vector& fds_to_map,
bool debug_on_start);
#endif

DISALLOW_COPY_AND_ASSIGN(MultiProcessTest);
};
Expand Down
10 changes: 4 additions & 6 deletions chrome/browser/chromeos/input_method/input_method_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,16 +757,14 @@ class InputMethodManagerImpl : public InputMethodManager,
bool LaunchInputMethodProcess(const std::string& command_line,
base::ProcessHandle* process_handle) {
std::vector<std::string> argv;
base::file_handle_mapping_vector fds_to_remap;
base::ProcessHandle handle = base::kNullProcessHandle;

// TODO(zork): export "LD_PRELOAD=/usr/lib/libcrash.so"
base::SplitString(command_line, ' ', &argv);
const bool result = base::LaunchApp(argv,
fds_to_remap, // no remapping
false, // wait
&handle);
if (!result) {

base::LaunchOptions options;
options.process_handle = &handle;
if (!base::LaunchProcess(argv, options)) {
LOG(ERROR) << "Could not launch: " << command_line;
return false;
}
Expand Down
10 changes: 4 additions & 6 deletions chrome/browser/chromeos/input_method/xkeyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,16 @@ class XKeyboard {
const std::string layout_to_set = execute_queue_.front();

std::vector<std::string> argv;
base::file_handle_mapping_vector fds_to_remap;
base::ProcessHandle handle = base::kNullProcessHandle;

argv.push_back(kSetxkbmapCommand);
argv.push_back("-layout");
argv.push_back(layout_to_set);
argv.push_back("-synch");
const bool result = base::LaunchApp(argv,
fds_to_remap, // No remapping.
false, // Don't wait.
&handle);
if (!result) {

base::LaunchOptions options;
options.process_handle = &handle;
if (!base::LaunchProcess(argv, options)) {
LOG(ERROR) << "Failed to execute setxkbmap: " << layout_to_set;
execute_queue_ = std::queue<std::string>(); // clear the queue.
return;
Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/mac/relauncher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ bool RelaunchAppWithHelper(const std::string& helper,
base::file_handle_mapping_vector fd_map;
fd_map.push_back(std::make_pair(*pipe_write_fd, kRelauncherSyncFD));

if (!base::LaunchApp(relaunch_args, fd_map, false, NULL)) {
LOG(ERROR) << "base::LaunchApp failed";
base::LaunchOptions options;
options.fds_to_remap = &fd_map;
if (!base::LaunchProcess(relaunch_args, options)) {
LOG(ERROR) << "base::LaunchProcess failed";
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/printing/printer_manager_dialog_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ void DetectAndOpenPrinterConfigDialog() {

std::vector<std::string> argv;
argv.push_back(command);
base::file_handle_mapping_vector no_files;
base::LaunchOptions options;
base::ProcessHandle handle;
if (!base::LaunchApp(argv, no_files, false, &handle)) {
options.process_handle = &handle;
if (!base::LaunchProcess(argv, options)) {
LOG(ERROR) << "Failed to open printer manager dialog ";
return;
}
Expand Down
7 changes: 5 additions & 2 deletions chrome/browser/process_info_snapshot_mac_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -111,7 +111,10 @@ TEST_F(ProcessInfoSnapshotMacTest, EffectiveVsRealUserIDTest) {
argv.push_back("0");

base::ProcessHandle process_handle;
ASSERT_TRUE(base::LaunchApp(argv, fds_to_remap, false, &process_handle));
base::LaunchOptions options;
options.fds_to_remap = &fds_to_remap;
options.process_handle = &process_handle;
ASSERT_TRUE(base::LaunchProcess(argv, options));
PCHECK(HANDLE_EINTR(close(fds[1])) == 0);

// Wait until there's some output form top. This is an easy way to tell that
Expand Down
5 changes: 4 additions & 1 deletion chrome/browser/shell_integration_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code) {
no_stdin.push_back(std::make_pair(devnull, STDIN_FILENO));

base::ProcessHandle handle;
if (!base::LaunchApp(argv, no_stdin, false, &handle)) {
base::LaunchOptions options;
options.process_handle = &handle;
options.fds_to_remap = &no_stdin;
if (!base::LaunchProcess(argv, options)) {
close(devnull);
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/ui/webui/options/advanced_options_utils_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ bool StartProxyConfigUtil(TabContents* tab_contents, const char* command[]) {
std::vector<std::string> argv;
for (size_t i = 0; command[i]; ++i)
argv.push_back(command[i]);
base::file_handle_mapping_vector no_files;
base::ProcessHandle handle;
if (!base::LaunchApp(argv, no_files, false, &handle)) {
base::LaunchOptions options;
options.process_handle = &handle;
if (!base::LaunchProcess(argv, options)) {
LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0];
return false;
}
Expand Down
12 changes: 7 additions & 5 deletions chrome/test/automation/proxy_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,12 @@ bool ProxyLauncher::LaunchBrowserHelper(const LaunchState& state, bool wait,
// TODO(phajdan.jr): Only run it for "main" browser launch.
browser_launch_time_ = base::TimeTicks::Now();

base::LaunchOptions options;
options.wait = wait;
options.process_handle = process;

#if defined(OS_WIN)
bool started = base::LaunchApp(command_line, wait,
!state.show_window, process);
options.start_hidden = !state.show_window;
#elif defined(OS_POSIX)
// Sometimes one needs to run the browser under a special environment
// (e.g. valgrind) without also running the test harness (e.g. python)
Expand All @@ -458,11 +461,10 @@ bool ProxyLauncher::LaunchBrowserHelper(const LaunchState& state, bool wait,
base::file_handle_mapping_vector fds;
if (automation_proxy_.get())
fds = automation_proxy_->fds_to_map();

bool started = base::LaunchApp(command_line.argv(), fds, wait, process);
options.fds_to_remap = &fds;
#endif

return started;
return base::LaunchProcess(command_line, options);
}

AutomationProxy* ProxyLauncher::automation() const {
Expand Down
7 changes: 5 additions & 2 deletions content/browser/zygote_host_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,11 @@ void ZygoteHost::Init(const std::string& sandbox_cmd) {
fds_to_map.push_back(std::make_pair(dummy_fd, 7));
}

base::ProcessHandle process;
base::LaunchApp(cmd_line.argv(), fds_to_map, false, &process);
base::ProcessHandle process = -1;
base::LaunchOptions options;
options.process_handle = &process;
options.fds_to_remap = &fds_to_map;
base::LaunchProcess(cmd_line.argv(), options);
CHECK(process != -1) << "Failed to launch zygote process";

if (using_suid_sandbox_) {
Expand Down
9 changes: 5 additions & 4 deletions net/test/test_server_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) {
}

// Launch a new testserver process.
if (!base::LaunchApp(python_command.argv(), map_write_fd, false,
&process_handle_)) {
LOG(ERROR) << "Failed to launch " << python_command.command_line_string()
<< " ...";
base::LaunchOptions options;
options.fds_to_remap = &map_write_fd;
options.process_handle = &process_handle_;
if (!base::LaunchProcess(python_command, options)) {
LOG(ERROR) << "Failed to launch " << python_command.command_line_string();
return false;
}

Expand Down

0 comments on commit b5ce736

Please sign in to comment.