1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_COMMON_MAC_LAUNCHD_H_
6 #define CHROME_COMMON_MAC_LAUNCHD_H_
8 #include <CoreFoundation/CoreFoundation.h>
10 #include "base/basictypes.h"
11 #include "base/memory/singleton.h"
17 Daemon
// LaunchDaemon
20 // Domains map to NSSearchPathDomainMask so Foundation does not need to be
23 User
= 1, // ~/Library/Launch*
24 Local
= 2, // /Library/Launch*
25 Network
= 4, // /Network/Library/Launch*
26 System
= 8 // /System/Library/Launch*
29 // TODO(dmaclach): Get rid of this pseudo singleton, and inject it
30 // appropriately wherever it is used.
31 // http://crbug.com/76925
32 static Launchd
* GetInstance();
36 // Return a dictionary with the launchd export settings.
37 virtual CFDictionaryRef
CopyExports();
39 // Return a dictionary with the launchd entries for job labeled |name|.
40 virtual CFDictionaryRef
CopyJobDictionary(CFStringRef label
);
42 // Return a dictionary for launchd process.
43 virtual CFDictionaryRef
CopyDictionaryByCheckingIn(CFErrorRef
* error
);
45 // Remove a launchd process from launchd.
46 virtual bool RemoveJob(CFStringRef label
, CFErrorRef
* error
);
48 // Used by a process controlled by launchd to restart itself.
49 // |session_type| can be "Aqua", "LoginWindow", "Background", "StandardIO" or
51 // RestartLaunchdJob starts up a separate process to tell launchd to
52 // send this process a SIGTERM. This call will return, but a SIGTERM will be
54 virtual bool RestartJob(Domain domain
,
57 CFStringRef session_type
);
59 // Read a launchd plist from disk.
60 // |name| should not have an extension.
61 virtual CFMutableDictionaryRef
CreatePlistFromFile(Domain domain
,
64 // Write a launchd plist to disk.
65 // |name| should not have an extension.
66 virtual bool WritePlistToFile(Domain domain
,
69 CFDictionaryRef dict
);
71 // Delete a launchd plist.
72 // |name| should not have an extension.
73 virtual bool DeletePlist(Domain domain
, Type type
, CFStringRef name
);
75 // TODO(dmaclach): remove this once http://crbug.com/76925 is fixed.
76 // Scaffolding for doing unittests with our singleton.
77 static void SetInstance(Launchd
* instance
);
78 class ScopedInstance
{
80 explicit ScopedInstance(Launchd
* instance
) {
81 Launchd::SetInstance(instance
);
84 Launchd::SetInstance(NULL
);
92 // TODO(dmaclach): remove this once http://crbug.com/76925 is fixed.
93 // Scaffolding for doing unittests with our singleton.
94 friend struct DefaultSingletonTraits
<Launchd
>;
95 static Launchd
* g_instance_
;
97 DISALLOW_COPY_AND_ASSIGN(Launchd
);
100 #endif // CHROME_COMMON_MAC_LAUNCHD_H_