summaryrefslogtreecommitdiffstats
path: root/base/process_util_mac.mm
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-27 20:49:55 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-27 20:49:55 +0000
commit9c73c775a14581f1b005c30242be0354afe64bfd (patch)
tree5c3de6ed874caf93886fba43d951c56ebc7c704b /base/process_util_mac.mm
parent467751964600388345aa537e1436b036d159ac92 (diff)
downloadchromium_src-9c73c775a14581f1b005c30242be0354afe64bfd.zip
chromium_src-9c73c775a14581f1b005c30242be0354afe64bfd.tar.gz
chromium_src-9c73c775a14581f1b005c30242be0354afe64bfd.tar.bz2
Enable stats_tabe_unittest.cc on OS X.
Review URL: http://codereview.chromium.org/8160 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4024 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_mac.mm')
-rw-r--r--base/process_util_mac.mm61
1 files changed, 61 insertions, 0 deletions
diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm
new file mode 100644
index 0000000..942dbab
--- /dev/null
+++ b/base/process_util_mac.mm
@@ -0,0 +1,61 @@
+// Copyright (c) 2008 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.
+
+
+#include "base/process_util.h"
+
+#import <Cocoa/Cocoa.h>
+#include <spawn.h>
+#include <string>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+namespace process_util {
+
+bool LaunchApp(const std::vector<std::string>& argv,
+ bool wait, ProcessHandle* process_handle) {
+ bool retval = true;
+
+ char* argv_copy[argv.size() + 1];
+ for (size_t i = 0; i < argv.size(); i++) {
+ argv_copy[i] = const_cast<char*>(argv[i].c_str());
+ }
+ argv_copy[argv.size()] = NULL;
+
+ int pid = 0;
+ int spawn_succeeded = (posix_spawn(&pid,
+ argv_copy[0],
+ NULL,
+ NULL,
+ argv_copy,
+ NULL) == 0);
+
+ bool process_handle_valid = pid > 0;
+ if (!spawn_succeeded || !process_handle_valid) {
+ retval = false;
+ } else {
+ if (wait)
+ waitpid(pid, 0, 0);
+
+ if(process_handle)
+ *process_handle = pid;
+ }
+
+ return retval;
+}
+
+bool LaunchApp(const CommandLine& cl,
+ bool wait, bool start_hidden, ProcessHandle* process_handle) {
+ // TODO(playmobil): Do we need to respect the start_hidden flag?
+ return LaunchApp(cl.argv(), wait, process_handle);
+}
+
+bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
+ // TODO(playmobil): Do we need to support wait_milliseconds?
+ int status;
+ waitpid(handle, &status, 0);
+ return WIFEXITED(status);
+}
+
+} // namespace process_util