From 682daa3bf0bcf779596da7cceec778b7b59cdc55 Mon Sep 17 00:00:00 2001 From: rvargas Date: Wed, 14 Jan 2015 12:17:32 -0800 Subject: Remove deprecated versions of LaunchProcess. BUG=417532 Review URL: https://codereview.chromium.org/799323003 Cr-Commit-Position: refs/heads/master@{#311537} --- base/process/launch.h | 12 ------- base/process/launch_posix.cc | 42 +++++------------------ base/process/launch_win.cc | 64 +++++++++-------------------------- base/process/process_util_unittest.cc | 2 +- 4 files changed, 26 insertions(+), 94 deletions(-) diff --git a/base/process/launch.h b/base/process/launch.h index e9fb3b9..d7e2351 100644 --- a/base/process/launch.h +++ b/base/process/launch.h @@ -159,12 +159,6 @@ struct BASE_EXPORT LaunchOptions { BASE_EXPORT Process LaunchProcess(const CommandLine& cmdline, const LaunchOptions& options); -// Deprecated version. -// TODO(rvargas) crbug.com/417532: Remove this after migrating all consumers. -BASE_EXPORT bool LaunchProcess(const CommandLine& cmdline, - const LaunchOptions& options, - ProcessHandle* process_handle); - #if defined(OS_WIN) // Windows-specific LaunchProcess that takes the command line as a // string. Useful for situations where you need to control the @@ -195,12 +189,6 @@ BASE_EXPORT Process LaunchElevatedProcess(const CommandLine& cmdline, BASE_EXPORT Process LaunchProcess(const std::vector& argv, const LaunchOptions& options); -// Deprecated version. -// TODO(rvargas) crbug.com/417532: Remove this after migrating all consumers. -BASE_EXPORT bool LaunchProcess(const std::vector& argv, - const LaunchOptions& options, - ProcessHandle* process_handle); - // Close all file descriptors, except those which are a destination in the // given multimap. Only call this function in a child process where you know // that there aren't any other threads. diff --git a/base/process/launch_posix.cc b/base/process/launch_posix.cc index c475748..7bcd834 100644 --- a/base/process/launch_posix.cc +++ b/base/process/launch_posix.cc @@ -277,9 +277,13 @@ void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) { } } -bool LaunchProcess(const std::vector& argv, - const LaunchOptions& options, - ProcessHandle* process_handle) { +Process LaunchProcess(const CommandLine& cmdline, + const LaunchOptions& options) { + return LaunchProcess(cmdline.argv(), options); +} + +Process LaunchProcess(const std::vector& argv, + const LaunchOptions& options) { size_t fd_shuffle_size = 0; if (options.fds_to_remap) { fd_shuffle_size = options.fds_to_remap->size(); @@ -335,7 +339,7 @@ bool LaunchProcess(const std::vector& argv, if (pid < 0) { DPLOG(ERROR) << "fork"; - return false; + return Process(); } else if (pid == 0) { // Child process @@ -475,37 +479,9 @@ bool LaunchProcess(const std::vector& argv, pid_t ret = HANDLE_EINTR(waitpid(pid, 0, 0)); DPCHECK(ret > 0); } - - if (process_handle) - *process_handle = pid; } - return true; -} - -Process LaunchProcess(const std::vector& argv, - const LaunchOptions& options) { - ProcessHandle process_handle; - if (LaunchProcess(argv, options, &process_handle)) - return Process(process_handle); - - return Process(); -} - - -bool LaunchProcess(const CommandLine& cmdline, - const LaunchOptions& options, - ProcessHandle* process_handle) { - return LaunchProcess(cmdline.argv(), options, process_handle); -} - -Process LaunchProcess(const CommandLine& cmdline, - const LaunchOptions& options) { - ProcessHandle process_handle; - if (LaunchProcess(cmdline, options, &process_handle)) - return Process(process_handle); - - return Process(); + return Process(pid); } void RaiseProcessToHighPriority() { diff --git a/base/process/launch_win.cc b/base/process/launch_win.cc index 1d83ef9..c2bd295 100644 --- a/base/process/launch_win.cc +++ b/base/process/launch_win.cc @@ -105,9 +105,13 @@ void RouteStdioToConsole() { std::ios::sync_with_stdio(); } -bool LaunchProcess(const string16& cmdline, - const LaunchOptions& options, - win::ScopedHandle* process_handle) { +Process LaunchProcess(const CommandLine& cmdline, + const LaunchOptions& options) { + return LaunchProcess(cmdline.GetCommandLineString(), options); +} + +Process LaunchProcess(const string16& cmdline, + const LaunchOptions& options) { win::StartupInformation startup_info_wrapper; STARTUPINFO* startup_info = startup_info_wrapper.startup_info(); @@ -119,18 +123,18 @@ bool LaunchProcess(const string16& cmdline, } else { if (base::win::GetVersion() < base::win::VERSION_VISTA) { DLOG(ERROR) << "Specifying handles to inherit requires Vista or later."; - return false; + return Process(); } if (options.handles_to_inherit->size() > std::numeric_limits::max() / sizeof(HANDLE)) { DLOG(ERROR) << "Too many handles to inherit."; - return false; + return Process(); } if (!startup_info_wrapper.InitializeProcThreadAttributeList(1)) { DPLOG(ERROR); - return false; + return Process(); } if (!startup_info_wrapper.UpdateProcThreadAttribute( @@ -139,7 +143,7 @@ bool LaunchProcess(const string16& cmdline, static_cast(options.handles_to_inherit->size() * sizeof(HANDLE)))) { DPLOG(ERROR); - return false; + return Process(); } inherit_handles = true; @@ -184,7 +188,7 @@ bool LaunchProcess(const string16& cmdline, if (!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE)) { DPLOG(ERROR); - return false; + return Process(); } BOOL launched = @@ -197,7 +201,7 @@ bool LaunchProcess(const string16& cmdline, if (!launched) { DPLOG(ERROR) << "Command line:" << std::endl << UTF16ToUTF8(cmdline) << std::endl;; - return false; + return Process(); } } else { if (!CreateProcess(NULL, @@ -206,7 +210,7 @@ bool LaunchProcess(const string16& cmdline, startup_info, &temp_process_info)) { DPLOG(ERROR) << "Command line:" << std::endl << UTF16ToUTF8(cmdline) << std::endl;; - return false; + return Process(); } } base::win::ScopedProcessInformation process_info(temp_process_info); @@ -216,7 +220,7 @@ bool LaunchProcess(const string16& cmdline, process_info.process_handle())) { DLOG(ERROR) << "Could not AssignProcessToObject."; KillProcess(process_info.process_handle(), kProcessKilledExitCode, true); - return false; + return Process(); } ResumeThread(process_info.thread_handle()); @@ -225,43 +229,7 @@ bool LaunchProcess(const string16& cmdline, if (options.wait) WaitForSingleObject(process_info.process_handle(), INFINITE); - // If the caller wants the process handle, we won't close it. - if (process_handle) - process_handle->Set(process_info.TakeProcessHandle()); - - return true; -} - -// TODO(rvargas) crbug.com/416721: Remove this stub after LaunchProcess is -// fully migrated to use Process. -Process LaunchProcess(const string16& cmdline, - const LaunchOptions& options) { - win::ScopedHandle process_handle; - if (LaunchProcess(cmdline, options, &process_handle)) - return Process(process_handle.Take()); - - return Process(); -} - -bool LaunchProcess(const CommandLine& cmdline, - const LaunchOptions& options, - ProcessHandle* process_handle) { - if (!process_handle) - return LaunchProcess(cmdline.GetCommandLineString(), options, NULL); - - win::ScopedHandle process; - bool rv = LaunchProcess(cmdline.GetCommandLineString(), options, &process); - *process_handle = process.Take(); - return rv; -} - -Process LaunchProcess(const CommandLine& cmdline, - const LaunchOptions& options) { - ProcessHandle process_handle; - if (LaunchProcess(cmdline, options, &process_handle)) - return Process(process_handle); - - return Process(); + return Process(process_info.TakeProcessHandle()); } Process LaunchElevatedProcess(const CommandLine& cmdline, diff --git a/base/process/process_util_unittest.cc b/base/process/process_util_unittest.cc index cb87d90..4b2a575 100644 --- a/base/process/process_util_unittest.cc +++ b/base/process/process_util_unittest.cc @@ -607,7 +607,7 @@ std::string TestLaunchProcess(const std::vector& args, #else CHECK_EQ(0, clone_flags); #endif // OS_LINUX - EXPECT_TRUE(base::LaunchProcess(args, options, NULL)); + EXPECT_TRUE(base::LaunchProcess(args, options).IsValid()); PCHECK(IGNORE_EINTR(close(fds[1])) == 0); char buf[512]; -- cgit v1.1