summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-23 23:37:19 +0000
committertoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-23 23:37:19 +0000
commitb330cab36b67a7a3c75b52bdf9fc907858dbfced (patch)
treefc7367f6abe66f56c2f8c0fed8e58688935078a6 /base
parent1d3a1d21edc4e338e19f9132c406a8ee2860de31 (diff)
downloadchromium_src-b330cab36b67a7a3c75b52bdf9fc907858dbfced.zip
chromium_src-b330cab36b67a7a3c75b52bdf9fc907858dbfced.tar.gz
chromium_src-b330cab36b67a7a3c75b52bdf9fc907858dbfced.tar.bz2
Extract similar code into SetJobObjectAsKillOnJobClose()
For now, Chromium have five same code in various place to handle JobObject as KILL_ON_JOB_CLOSE. This change provide a common utility function to be used by them. BUG=n/a TEST=n/a; run existing unit tests because this is just a refactoring change Review URL: http://codereview.chromium.org/8667006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/process_util.h9
-rw-r--r--base/process_util_win.cc11
2 files changed, 20 insertions, 0 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.