diff options
-rw-r--r-- | base/process_util.h | 9 | ||||
-rw-r--r-- | base/process_util_win.cc | 11 | ||||
-rw-r--r-- | chrome/common/chrome_content_client.cc | 6 | ||||
-rw-r--r-- | chrome/test/base/layout_test_http_server.cc | 7 | ||||
-rw-r--r-- | chrome/test/ui/ui_test_suite.cc | 6 | ||||
-rw-r--r-- | net/test/test_server_win.cc | 7 |
6 files changed, 25 insertions, 21 deletions
diff --git a/base/process_util.h b/base/process_util.h index 874e656..3c9dfbe 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -383,6 +383,15 @@ BASE_EXPORT void LaunchSynchronize(LaunchSynchronizationHandle handle); #endif // defined(OS_MACOSX) #endif // defined(OS_POSIX) +#if defined(OS_WIN) +// Set JOBOBJECT_EXTENDED_LIMIT_INFORMATION to JobObject |job_object|. +// As its limit_info.BasicLimitInformation.LimitFlags has +// JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE. +// When the provide JobObject |job_object| is closed, the binded process will +// be terminated. +BASE_EXPORT bool SetJobObjectAsKillOnJobClose(HANDLE job_object); +#endif // defined(OS_WIN) + // Executes the application specified by |cl| and wait for it to exit. Stores // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true // on success (application launched and exited cleanly, with exit code diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 891dc3b..ff9d3fd 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -362,6 +362,17 @@ bool LaunchProcess(const CommandLine& cmdline, return LaunchProcess(cmdline.GetCommandLineString(), options, process_handle); } +bool SetJobObjectAsKillOnJobClose(HANDLE job_object) { + JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; + limit_info.BasicLimitInformation.LimitFlags = + JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + return 0 != SetInformationJobObject( + job_object, + JobObjectExtendedLimitInformation, + &limit_info, + sizeof(limit_info)); +} + // Attempts to kill the process identified by the given process // entry structure, giving it the specified exit code. // Returns true if this is successful, false otherwise. diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc index 65b004b..9c8ca65 100644 --- a/chrome/common/chrome_content_client.cc +++ b/chrome/common/chrome_content_client.cc @@ -229,11 +229,7 @@ bool LoadFlashBroker(const FilePath& plugin_path, CommandLine* cmd_line) { // terminates the job object is destroyed (by the OS) and the flash broker // is terminated. HANDLE job = ::CreateJobObjectW(NULL, NULL); - JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_limits = {0}; - job_limits.BasicLimitInformation.LimitFlags = - JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; - if (::SetInformationJobObject(job, JobObjectExtendedLimitInformation, - &job_limits, sizeof(job_limits))) { + if (base::SetJobObjectAsKillOnJobClose(job)) { ::AssignProcessToJobObject(job, process); // Yes, we are leaking the object here. Read comment above. } else { diff --git a/chrome/test/base/layout_test_http_server.cc b/chrome/test/base/layout_test_http_server.cc index 7ae0891..b0ba02d 100644 --- a/chrome/test/base/layout_test_http_server.cc +++ b/chrome/test/base/layout_test_http_server.cc @@ -87,11 +87,7 @@ bool LayoutTestHttpServer::Start() { return false; } - JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; - limit_info.BasicLimitInformation.LimitFlags = - JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; - if (0 == SetInformationJobObject(job_handle_.Get(), - JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info))) { + if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) { LOG(ERROR) << "Could not SetInformationJobObject."; return false; } @@ -136,4 +132,3 @@ bool LayoutTestHttpServer::Stop() { return stopped; } - diff --git a/chrome/test/ui/ui_test_suite.cc b/chrome/test/ui/ui_test_suite.cc index 5a5e07f..d9abae4 100644 --- a/chrome/test/ui/ui_test_suite.cc +++ b/chrome/test/ui/ui_test_suite.cc @@ -52,11 +52,7 @@ void UITestSuite::LoadCrashService() { return; } - JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; - limit_info.BasicLimitInformation.LimitFlags = - JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; - if (0 == SetInformationJobObject(job_handle_.Get(), - JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info))) { + if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) { LOG(ERROR) << "Could not SetInformationJobObject."; return; } diff --git a/net/test/test_server_win.cc b/net/test/test_server_win.cc index ee62d1df..889180f 100644 --- a/net/test/test_server_win.cc +++ b/net/test/test_server_win.cc @@ -13,6 +13,7 @@ #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/process_util.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/test/test_timeouts.h" @@ -132,11 +133,7 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) { return false; } - JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; - limit_info.BasicLimitInformation.LimitFlags = - JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; - if (0 == SetInformationJobObject(job_handle_.Get(), - JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info))) { + if (!base::SetJobObjectAsKillOnJobClose(job_handle_.Get())) { LOG(ERROR) << "Could not SetInformationJobObject."; return false; } |