Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / common / mac / launchd.h
blobc43341c9a42dca28d522ee064b8ffefa17724e96
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"
13 class Launchd {
14 public:
15 enum Type {
16 Agent, // LaunchAgent
17 Daemon // LaunchDaemon
20 // Domains map to NSSearchPathDomainMask so Foundation does not need to be
21 // included.
22 enum Domain {
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();
34 virtual ~Launchd();
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
47 // "System".
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
50 // received shortly.
51 virtual bool RestartJob(Domain domain,
52 Type type,
53 CFStringRef name,
54 CFStringRef session_type);
56 // Read a launchd plist from disk.
57 // |name| should not have an extension.
58 virtual CFMutableDictionaryRef CreatePlistFromFile(Domain domain,
59 Type type,
60 CFStringRef name);
61 // Write a launchd plist to disk.
62 // |name| should not have an extension.
63 virtual bool WritePlistToFile(Domain domain,
64 Type type,
65 CFStringRef name,
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 {
76 public:
77 explicit ScopedInstance(Launchd* instance) {
78 Launchd::SetInstance(instance);
80 ~ScopedInstance() {
81 Launchd::SetInstance(NULL);
85 protected:
86 Launchd() { }
88 private:
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_