OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef CHROME_COMMON_LAUNCHD_MAC_H_ | |
6 #define CHROME_COMMON_LAUNCHD_MAC_H_ | |
7 | |
8 #include <CoreFoundation/CoreFoundation.h> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/singleton.h" | |
12 | |
13 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.
| |
14 public: | |
15 | |
16 enum Type { | |
17 Agent, // LaunchAgent | |
18 Daemon // LaunchDaemon | |
19 }; | |
20 | |
21 // Domains map to NSSearchPathDomainMask without requiring Foundation | |
22 // 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.
| |
23 enum Domain { | |
24 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
| |
25 Local = 2, // /Library/Launch* | |
26 Network = 4, // /Network/Library/Launch* | |
27 System = 8 // /System/Library/Launch* | |
28 }; | |
29 | |
30 // TODO(dmaclach): Get rid of this pseudo singleton, and inject it | |
31 // appropriately wherever it is used. | |
32 // http://crbug.com/76925 | |
33 static Launchd* GetInstance(); | |
34 | |
35 virtual ~Launchd(); | |
36 | |
37 // Return a dictionary with the launchd export settings. | |
38 virtual CFDictionaryRef CopyLaunchdExports(); | |
39 | |
40 // Return a dictionary with the launchd entries for job labeled |name|. | |
41 virtual CFDictionaryRef CopyLaunchdJobDictionary(CFStringRef label); | |
42 | |
43 // Return a dictionary for launchd process. | |
44 virtual CFDictionaryRef CopyLaunchdDictionaryByCheckingIn(CFErrorRef* error); | |
45 | |
46 // Remove a launchd process from launchd. This should not be used by a process | |
47 // to commit suicide. ShutdownLaunchdJob/RestartLaunchdJob should be used | |
48 // instead. | |
49 virtual bool RemoveLaunchdJob(CFStringRef label, CFErrorRef* error); | |
50 | |
51 // 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.
| |
52 // |session_type| can be "Aqua", "LoginWindow", "Background", "StandardIO" or | |
53 // "System". | |
54 // ShutdownLaunchdJob starts up a separate process to tell launchd to | |
55 // 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.
| |
56 virtual bool ShutdownLaunchdJob(Domain domain, | |
57 Type type, | |
58 CFStringRef name, | |
59 CFStringRef session_type); | |
60 | |
61 // Used by a process controlled by launchd to restart oneself. | |
62 // |session_type| can be "Aqua", "LoginWindow", "Background", "StandardIO" or | |
63 // "System". | |
64 // RestartLaunchdJob starts up a separate process to tell launchd to | |
65 // 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.
| |
66 // should occur shortly. | |
67 virtual bool RestartLaunchdJob(Domain domain, | |
68 Type type, | |
69 CFStringRef name, | |
70 CFStringRef session_type); | |
71 | |
72 // Read a launchd plist from disk. | |
73 // |name| should not have an extension. | |
74 virtual CFMutableDictionaryRef ReadLaunchdPlist(Domain domain, | |
Mark Mentovai
2011/03/21 16:50:49
Your CFDictionaryRef-returning functions above wer
| |
75 Type type, | |
76 CFStringRef name); | |
77 // Write a launchd plist to disk. | |
78 // |name| should not have an extension. | |
79 virtual bool WriteLaunchdPlist(Domain domain, | |
80 Type type, | |
81 CFStringRef name, | |
82 CFDictionaryRef dict); | |
83 | |
84 // Delete a launchd plist. | |
85 // |name| should not have an extension. | |
86 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.
| |
87 | |
88 // TODO(dmaclach): remove this once http://crbug.com/76925 is fixed. | |
89 // Scaffolding for doing unittests with our singleton. | |
90 static void SetInstance(Launchd* instance); | |
91 class ScopedInstance { | |
92 public: | |
93 ScopedInstance(Launchd* instance) { | |
Mark Mentovai
2011/03/21 16:50:49
explicit
dmac
2011/03/21 22:59:19
Done.
| |
94 Launchd::SetInstance(instance); | |
95 } | |
96 ~ScopedInstance() { | |
97 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 ;-)
| |
98 } | |
99 }; | |
100 | |
101 protected: | |
102 Launchd() { } | |
103 | |
104 private: | |
105 // TODO(dmaclach): remove this once http://crbug.com/76925 is fixed. | |
106 // Scaffolding for doing unittests with our singleton. | |
107 friend struct DefaultSingletonTraits<Launchd>; | |
108 static Launchd* g_instance_; | |
109 static bool g_set_to_singleton_; | |
110 | |
111 DISALLOW_COPY_AND_ASSIGN(Launchd); | |
112 }; | |
113 | |
114 #endif // CHROME_COMMON_LAUNCHD_MAC_H_ | |
OLD | NEW |