diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-29 16:57:53 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-29 16:57:53 +0000 |
commit | fd1c931540c431023b09927b717ba848daefc369 (patch) | |
tree | 4030d49336ea3d3074a231f2645888c301182138 | |
parent | c849fab653f06cbb9246eeafa5b7d1f5281cc251 (diff) | |
download | chromium_src-fd1c931540c431023b09927b717ba848daefc369.zip chromium_src-fd1c931540c431023b09927b717ba848daefc369.tar.gz chromium_src-fd1c931540c431023b09927b717ba848daefc369.tar.bz2 |
Move launchd code from chrome/browser/mac to base/mac.
This is to allow the code to be used by the Chromoting host plugin.
Also expand the interface of PIDForJob() to report if a job is loaded but not
running.
BUG=None
TEST=Compiles, unit-tests pass
Review URL: https://chromiumcodereview.appspot.com/9837098
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129636 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gypi | 3 | ||||
-rw-r--r-- | base/mac/launchd.cc (renamed from chrome/browser/mac/launchd.cc) | 24 | ||||
-rw-r--r-- | base/mac/launchd.h | 31 | ||||
-rw-r--r-- | base/mac/scoped_launch_data.h (renamed from chrome/browser/mac/scoped_launch_data.h) | 14 | ||||
-rw-r--r-- | chrome/browser/mac/dock.mm | 4 | ||||
-rw-r--r-- | chrome/browser/mac/launchd.h | 20 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 3 |
7 files changed, 53 insertions, 46 deletions
diff --git a/base/base.gypi b/base/base.gypi index 5bd9885..aecba8b 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -158,6 +158,8 @@ 'mac/crash_logging.mm', 'mac/foundation_util.h', 'mac/foundation_util.mm', + 'mac/launchd.cc', + 'mac/launchd.h', 'mac/mac_logging.h', 'mac/mac_logging.cc', 'mac/mac_util.h', @@ -170,6 +172,7 @@ 'mac/scoped_authorizationref.h', 'mac/scoped_cftyperef.h', 'mac/scoped_ioobject.h', + 'mac/scoped_launch_data.h', 'mac/scoped_nsautorelease_pool.h', 'mac/scoped_nsautorelease_pool.mm', 'mac/scoped_nsexception_enabler.h', diff --git a/chrome/browser/mac/launchd.cc b/base/mac/launchd.cc index 3a55c3b..1d384c9 100644 --- a/chrome/browser/mac/launchd.cc +++ b/base/mac/launchd.cc @@ -1,17 +1,14 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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 "chrome/browser/mac/launchd.h" - -#include <launch.h> +#include "base/mac/launchd.h" #include "base/logging.h" -#include "chrome/browser/mac/scoped_launch_data.h" - -namespace launchd { +#include "base/mac/scoped_launch_data.h" -namespace { +namespace base { +namespace mac { // MessageForJob sends a single message to launchd with a simple dictionary // mapping |operation| to |job_label|, and returns the result of calling @@ -45,8 +42,6 @@ launch_data_t MessageForJob(const std::string& job_label, return launch_msg(message); } -} // namespace - pid_t PIDForJob(const std::string& job_label) { ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB)); if (!response) { @@ -65,10 +60,8 @@ pid_t PIDForJob(const std::string& job_label) { launch_data_t pid_data = launch_data_dict_lookup(response, LAUNCH_JOBKEY_PID); - if (!pid_data) { - LOG(ERROR) << "PIDForJob: no pid"; - return -1; - } + if (!pid_data) + return 0; if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) { LOG(ERROR) << "PIDForJob: expected integer"; @@ -78,4 +71,5 @@ pid_t PIDForJob(const std::string& job_label) { return launch_data_get_integer(pid_data); } -} // namespace launchd +} // namespace mac +} // namespace base diff --git a/base/mac/launchd.h b/base/mac/launchd.h new file mode 100644 index 0000000..b693687 --- /dev/null +++ b/base/mac/launchd.h @@ -0,0 +1,31 @@ +// Copyright (c) 2012 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. + +#ifndef BASE_MAC_LAUNCHD_H_ +#define BASE_MAC_LAUNCHD_H_ +#pragma once + +#include <launch.h> +#include <sys/types.h> + +#include <string> + +namespace base { +namespace mac { + +// MessageForJob sends a single message to launchd with a simple dictionary +// mapping |operation| to |job_label|, and returns the result of calling +// launch_msg to send that message. On failure, returns NULL. The caller +// assumes ownership of the returned launch_data_t object. +launch_data_t MessageForJob(const std::string& job_label, + const char* operation); + +// Returns the process ID for |job_label| if the job is running, 0 if the job +// is loaded but not running, or -1 on error. +pid_t PIDForJob(const std::string& job_label); + +} // namespace mac +} // namespace base + +#endif // BASE_MAC_LAUNCHD_H_ diff --git a/chrome/browser/mac/scoped_launch_data.h b/base/mac/scoped_launch_data.h index 750b296..955c3e7 100644 --- a/chrome/browser/mac/scoped_launch_data.h +++ b/base/mac/scoped_launch_data.h @@ -1,9 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. -#ifndef CHROME_BROWSER_MAC_SCOPED_LAUNCH_DATA_H_ -#define CHROME_BROWSER_MAC_SCOPED_LAUNCH_DATA_H_ +#ifndef BASE_MAC_SCOPED_LAUNCH_DATA_H_ +#define BASE_MAC_SCOPED_LAUNCH_DATA_H_ #pragma once #include <launch.h> @@ -13,7 +13,8 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -namespace launchd { +namespace base { +namespace mac { // Just like scoped_ptr<> but for launch_data_t. class ScopedLaunchData { @@ -69,6 +70,7 @@ class ScopedLaunchData { DISALLOW_COPY_AND_ASSIGN(ScopedLaunchData); }; -} // namespace launchd +} // namespace mac +} // namespace base -#endif // CHROME_BROWSER_MAC_SCOPED_LAUNCH_DATA_H_ +#endif // BASE_MAC_SCOPED_LAUNCH_DATA_H_ diff --git a/chrome/browser/mac/dock.mm b/chrome/browser/mac/dock.mm index 39c33b9..1256b17b 100644 --- a/chrome/browser/mac/dock.mm +++ b/chrome/browser/mac/dock.mm @@ -10,12 +10,12 @@ #include <signal.h> #include "base/logging.h" +#include "base/mac/launchd.h" #include "base/mac/mac_logging.h" #include "base/mac/mac_util.h" #include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_nsautorelease_pool.h" #include "base/sys_string_conversions.h" -#include "chrome/browser/mac/launchd.h" extern "C" { @@ -176,7 +176,7 @@ void Restart() { // Doing this via launchd using the proper job label is the safest way to // handle the restart. Unlike "killall Dock", looking this up via launchd // guarantees that only the right process will be targeted. - pid = launchd::PIDForJob("com.apple.Dock.agent"); + pid = base::mac::PIDForJob("com.apple.Dock.agent"); } else { // On Leopard, the Dock doesn't have a known fixed job label name as it // does on Snow Leopard and Lion because it's not launched as a launch diff --git a/chrome/browser/mac/launchd.h b/chrome/browser/mac/launchd.h deleted file mode 100644 index a65e354..0000000 --- a/chrome/browser/mac/launchd.h +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -#ifndef CHROME_BROWSER_MAC_LAUNCHD_H_ -#define CHROME_BROWSER_MAC_LAUNCHD_H_ -#pragma once - -#include <sys/types.h> - -#include <string> - -namespace launchd { - -// Returns the process ID for |job_label|, or -1 on error. -pid_t PIDForJob(const std::string& job_label); - -} // namespace launchd - -#endif // CHROME_BROWSER_MAC_LAUNCHD_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 9789fa1..73aa7d8 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1346,13 +1346,10 @@ 'browser/mac/keystone_glue.mm', 'browser/mac/keystone_registration.h', 'browser/mac/keystone_registration.mm', - 'browser/mac/launchd.cc', - 'browser/mac/launchd.h', 'browser/mac/master_prefs.h', 'browser/mac/master_prefs.mm', 'browser/mac/relauncher.cc', 'browser/mac/relauncher.h', - 'browser/mac/scoped_launch_data.h', 'browser/managed_mode.cc', 'browser/managed_mode.h', 'browser/media/media_internals.cc', |