Demonstrate the basic functionality of the File System
[chromium-blink-merge.git] / chrome / common / mac / launchd.h
blob46d408095356f8409676d0745079a41145b83f0d
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 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
50 // "System".
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
53 // received shortly.
54 virtual bool RestartJob(Domain domain,
55 Type type,
56 CFStringRef name,
57 CFStringRef session_type);
59 // Read a launchd plist from disk.
60 // |name| should not have an extension.
61 virtual CFMutableDictionaryRef CreatePlistFromFile(Domain domain,
62 Type type,
63 CFStringRef name);
64 // Write a launchd plist to disk.
65 // |name| should not have an extension.
66 virtual bool WritePlistToFile(Domain domain,
67 Type type,
68 CFStringRef name,
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 {
79 public:
80 explicit ScopedInstance(Launchd* instance) {
81 Launchd::SetInstance(instance);
83 ~ScopedInstance() {
84 Launchd::SetInstance(NULL);
88 protected:
89 Launchd() { }
91 private:
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_