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 entries for job labeled |name|.
37 virtual CFDictionaryRef
CopyJobDictionary(CFStringRef label
);
39 // Return a dictionary for launchd process.
40 virtual CFDictionaryRef
CopyDictionaryByCheckingIn(CFErrorRef
* error
);
42 // Remove a launchd process from launchd.
43 virtual bool RemoveJob(CFStringRef label
, CFErrorRef
* error
);
45 // Used by a process controlled by launchd to restart itself.
46 // |session_type| can be "Aqua", "LoginWindow", "Background", "StandardIO" or
48 // RestartLaunchdJob starts up a separate process to tell launchd to
49 // send this process a SIGTERM. This call will return, but a SIGTERM will be
51 virtual bool RestartJob(Domain domain
,
54 CFStringRef session_type
);
56 // Read a launchd plist from disk.
57 // |name| should not have an extension.
58 virtual CFMutableDictionaryRef
CreatePlistFromFile(Domain domain
,
61 // Write a launchd plist to disk.
62 // |name| should not have an extension.
63 virtual bool WritePlistToFile(Domain domain
,
66 CFDictionaryRef dict
);
68 // Delete a launchd plist.
69 // |name| should not have an extension.
70 virtual bool DeletePlist(Domain domain
, Type type
, CFStringRef name
);
72 // TODO(dmaclach): remove this once http://crbug.com/76925 is fixed.
73 // Scaffolding for doing unittests with our singleton.
74 static void SetInstance(Launchd
* instance
);
75 class ScopedInstance
{
77 explicit ScopedInstance(Launchd
* instance
) {
78 Launchd::SetInstance(instance
);
81 Launchd::SetInstance(NULL
);
89 // TODO(dmaclach): remove this once http://crbug.com/76925 is fixed.
90 // Scaffolding for doing unittests with our singleton.
91 friend struct DefaultSingletonTraits
<Launchd
>;
92 static Launchd
* g_instance_
;
94 DISALLOW_COPY_AND_ASSIGN(Launchd
);
97 #endif // CHROME_COMMON_MAC_LAUNCHD_H_