Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4061)

Unified Diff: chrome/common/launchd_mac.h

Issue 6660001: Getting service process on Mac to handle having things moved/changed underneath it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move over to FilePathWatcher Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/launchd_mac.h
diff --git a/chrome/common/launchd_mac.h b/chrome/common/launchd_mac.h
new file mode 100644
index 0000000000000000000000000000000000000000..93bc34bb1fc393b018eb0225e8b2233e79b94afe
--- /dev/null
+++ b/chrome/common/launchd_mac.h
@@ -0,0 +1,114 @@
+// 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_COMMON_LAUNCHD_MAC_H_
+#define CHROME_COMMON_LAUNCHD_MAC_H_
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include "base/basictypes.h"
+#include "base/singleton.h"
+
+class Launchd {
Mark Mentovai 2011/03/21 16:50:49 I don’t like this as a class name, especially with
dmac 2011/03/21 22:59:19 Will fix up in a later CL.
+ public:
+
+ enum Type {
+ Agent, // LaunchAgent
+ Daemon // LaunchDaemon
+ };
+
+ // Domains map to NSSearchPathDomainMask without requiring Foundation
+ // to be included.
Mark Mentovai 2011/03/21 16:50:49 In order to get away with this, you need to have a
dmac 2011/03/21 22:59:19 Done.
+ enum Domain {
+ User = 1, // ~/Library/Launch*
Mark Mentovai 2011/03/21 16:50:49 To make it obvious that these are bits, I would wr
dmac 2011/03/21 22:59:19 Foundation definitions have them mapped out as 1,2
+ Local = 2, // /Library/Launch*
+ Network = 4, // /Network/Library/Launch*
+ System = 8 // /System/Library/Launch*
+ };
+
+ // TODO(dmaclach): Get rid of this pseudo singleton, and inject it
+ // appropriately wherever it is used.
+ // http://crbug.com/76925
+ static Launchd* GetInstance();
+
+ virtual ~Launchd();
+
+ // Return a dictionary with the launchd export settings.
+ virtual CFDictionaryRef CopyLaunchdExports();
+
+ // Return a dictionary with the launchd entries for job labeled |name|.
+ virtual CFDictionaryRef CopyLaunchdJobDictionary(CFStringRef label);
+
+ // Return a dictionary for launchd process.
+ virtual CFDictionaryRef CopyLaunchdDictionaryByCheckingIn(CFErrorRef* error);
+
+ // Remove a launchd process from launchd. This should not be used by a process
+ // to commit suicide. ShutdownLaunchdJob/RestartLaunchdJob should be used
+ // instead.
+ virtual bool RemoveLaunchdJob(CFStringRef label, CFErrorRef* error);
+
+ // Used by a process controlled by launchd to kill oneself.
Mark Mentovai 2011/03/21 16:50:49 itself
dmac 2011/03/21 22:59:19 Done.
+ // |session_type| can be "Aqua", "LoginWindow", "Background", "StandardIO" or
+ // "System".
+ // ShutdownLaunchdJob starts up a separate process to tell launchd to
+ // send us SIGTERM. This call will return, but a SIGTERM should occur shortly.
Mark Mentovai 2011/03/21 16:50:49 send us SIGTERM -> send this process a SIGTERM
Mark Mentovai 2011/03/21 16:50:49 occur -> be received
dmac 2011/03/21 22:59:19 Done.
dmac 2011/03/21 22:59:19 Done.
+ virtual bool ShutdownLaunchdJob(Domain domain,
+ Type type,
+ CFStringRef name,
+ CFStringRef session_type);
+
+ // Used by a process controlled by launchd to restart oneself.
+ // |session_type| can be "Aqua", "LoginWindow", "Background", "StandardIO" or
+ // "System".
+ // RestartLaunchdJob starts up a separate process to tell launchd to
+ // send us SIGTERM and then reload us. This call will return, but a SIGTERM
Mark Mentovai 2011/03/21 16:50:49 Revise comment as above: itself, send this process
dmac 2011/03/21 22:59:19 Done.
+ // should occur shortly.
+ virtual bool RestartLaunchdJob(Domain domain,
+ Type type,
+ CFStringRef name,
+ CFStringRef session_type);
+
+ // Read a launchd plist from disk.
+ // |name| should not have an extension.
+ virtual CFMutableDictionaryRef ReadLaunchdPlist(Domain domain,
Mark Mentovai 2011/03/21 16:50:49 Your CFDictionaryRef-returning functions above wer
+ Type type,
+ CFStringRef name);
+ // Write a launchd plist to disk.
+ // |name| should not have an extension.
+ virtual bool WriteLaunchdPlist(Domain domain,
+ Type type,
+ CFStringRef name,
+ CFDictionaryRef dict);
+
+ // Delete a launchd plist.
+ // |name| should not have an extension.
+ virtual bool DeleteLaunchDPlist(Domain domain, Type type, CFStringRef name);
Mark Mentovai 2011/03/21 16:50:49 You have ReadLaunchdPlist and WriteLaunchdPlist (l
dmac 2011/03/21 22:59:19 Done.
+
+ // TODO(dmaclach): remove this once http://crbug.com/76925 is fixed.
+ // Scaffolding for doing unittests with our singleton.
+ static void SetInstance(Launchd* instance);
+ class ScopedInstance {
+ public:
+ ScopedInstance(Launchd* instance) {
Mark Mentovai 2011/03/21 16:50:49 explicit
dmac 2011/03/21 22:59:19 Done.
+ Launchd::SetInstance(instance);
+ }
+ ~ScopedInstance() {
+ Launchd::SetInstance(NULL);
Mark Mentovai 2011/03/21 16:50:49 This doesn’t reset the initial state. That’s proba
dmac 2011/03/21 22:59:19 Actually it's exactly what I want ;-)
+ }
+ };
+
+ protected:
+ Launchd() { }
+
+ private:
+ // TODO(dmaclach): remove this once http://crbug.com/76925 is fixed.
+ // Scaffolding for doing unittests with our singleton.
+ friend struct DefaultSingletonTraits<Launchd>;
+ static Launchd* g_instance_;
+ static bool g_set_to_singleton_;
+
+ DISALLOW_COPY_AND_ASSIGN(Launchd);
+};
+
+#endif // CHROME_COMMON_LAUNCHD_MAC_H_

Powered by Google App Engine
This is Rietveld 408576698