OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/mac/mock_launchd.h" | 5 #include "chrome/common/mac/mock_launchd.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/un.h> | 9 #include <sys/un.h> |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 ADD_FAILURE(); | 122 ADD_FAILURE(); |
123 return NULL; | 123 return NULL; |
124 } | 124 } |
125 | 125 |
126 CFStringRef env_var = | 126 CFStringRef env_var = |
127 base::mac::NSToCFCast(GetServiceProcessLaunchDSocketEnvVar()); | 127 base::mac::NSToCFCast(GetServiceProcessLaunchDSocketEnvVar()); |
128 base::ScopedCFTypeRef<CFStringRef> socket_path(CFStringCreateWithCString( | 128 base::ScopedCFTypeRef<CFStringRef> socket_path(CFStringCreateWithCString( |
129 kCFAllocatorDefault, pipe_name_.c_str(), kCFStringEncodingUTF8)); | 129 kCFAllocatorDefault, pipe_name_.c_str(), kCFStringEncodingUTF8)); |
130 const void *keys[] = { env_var }; | 130 const void *keys[] = { env_var }; |
131 const void *values[] = { socket_path }; | 131 const void *values[] = { socket_path }; |
132 COMPILE_ASSERT(arraysize(keys) == arraysize(values), array_sizes_must_match); | 132 static_assert(arraysize(keys) == arraysize(values), |
| 133 "keys must have the same number of elements as values"); |
133 return CFDictionaryCreate(kCFAllocatorDefault, | 134 return CFDictionaryCreate(kCFAllocatorDefault, |
134 keys, | 135 keys, |
135 values, | 136 values, |
136 arraysize(keys), | 137 arraysize(keys), |
137 &kCFTypeDictionaryKeyCallBacks, | 138 &kCFTypeDictionaryKeyCallBacks, |
138 &kCFTypeDictionaryValueCallBacks); | 139 &kCFTypeDictionaryValueCallBacks); |
139 } | 140 } |
140 | 141 |
141 CFDictionaryRef MockLaunchd::CopyJobDictionary(CFStringRef label) { | 142 CFDictionaryRef MockLaunchd::CopyJobDictionary(CFStringRef label) { |
142 if (!as_service_) { | 143 if (!as_service_) { |
143 scoped_ptr<MultiProcessLock> running_lock( | 144 scoped_ptr<MultiProcessLock> running_lock( |
144 TakeNamedLock(pipe_name_, false)); | 145 TakeNamedLock(pipe_name_, false)); |
145 if (running_lock.get()) | 146 if (running_lock.get()) |
146 return NULL; | 147 return NULL; |
147 } | 148 } |
148 | 149 |
149 CFStringRef program = CFSTR(LAUNCH_JOBKEY_PROGRAM); | 150 CFStringRef program = CFSTR(LAUNCH_JOBKEY_PROGRAM); |
150 CFStringRef program_pid = CFSTR(LAUNCH_JOBKEY_PID); | 151 CFStringRef program_pid = CFSTR(LAUNCH_JOBKEY_PID); |
151 const void *keys[] = { program, program_pid }; | 152 const void *keys[] = { program, program_pid }; |
152 base::ScopedCFTypeRef<CFStringRef> path( | 153 base::ScopedCFTypeRef<CFStringRef> path( |
153 base::SysUTF8ToCFStringRef(file_.value())); | 154 base::SysUTF8ToCFStringRef(file_.value())); |
154 int process_id = base::GetCurrentProcId(); | 155 int process_id = base::GetCurrentProcId(); |
155 base::ScopedCFTypeRef<CFNumberRef> pid( | 156 base::ScopedCFTypeRef<CFNumberRef> pid( |
156 CFNumberCreate(NULL, kCFNumberIntType, &process_id)); | 157 CFNumberCreate(NULL, kCFNumberIntType, &process_id)); |
157 const void *values[] = { path, pid }; | 158 const void *values[] = { path, pid }; |
158 COMPILE_ASSERT(arraysize(keys) == arraysize(values), array_sizes_must_match); | 159 static_assert(arraysize(keys) == arraysize(values), |
| 160 "keys must have the same number of elements as values"); |
159 return CFDictionaryCreate(kCFAllocatorDefault, | 161 return CFDictionaryCreate(kCFAllocatorDefault, |
160 keys, | 162 keys, |
161 values, | 163 values, |
162 arraysize(keys), | 164 arraysize(keys), |
163 &kCFTypeDictionaryKeyCallBacks, | 165 &kCFTypeDictionaryKeyCallBacks, |
164 &kCFTypeDictionaryValueCallBacks); | 166 &kCFTypeDictionaryValueCallBacks); |
165 } | 167 } |
166 | 168 |
167 CFDictionaryRef MockLaunchd::CopyDictionaryByCheckingIn(CFErrorRef* error) { | 169 CFDictionaryRef MockLaunchd::CopyDictionaryByCheckingIn(CFErrorRef* error) { |
168 checkin_called_ = true; | 170 checkin_called_ = true; |
169 CFStringRef program = CFSTR(LAUNCH_JOBKEY_PROGRAM); | 171 CFStringRef program = CFSTR(LAUNCH_JOBKEY_PROGRAM); |
170 CFStringRef program_args = CFSTR(LAUNCH_JOBKEY_PROGRAMARGUMENTS); | 172 CFStringRef program_args = CFSTR(LAUNCH_JOBKEY_PROGRAMARGUMENTS); |
171 base::ScopedCFTypeRef<CFStringRef> path( | 173 base::ScopedCFTypeRef<CFStringRef> path( |
172 base::SysUTF8ToCFStringRef(file_.value())); | 174 base::SysUTF8ToCFStringRef(file_.value())); |
173 const void *array_values[] = { path.get() }; | 175 const void *array_values[] = { path.get() }; |
174 base::ScopedCFTypeRef<CFArrayRef> args(CFArrayCreate( | 176 base::ScopedCFTypeRef<CFArrayRef> args(CFArrayCreate( |
175 kCFAllocatorDefault, array_values, 1, &kCFTypeArrayCallBacks)); | 177 kCFAllocatorDefault, array_values, 1, &kCFTypeArrayCallBacks)); |
176 | 178 |
177 if (!create_socket_) { | 179 if (!create_socket_) { |
178 const void *keys[] = { program, program_args }; | 180 const void *keys[] = { program, program_args }; |
179 const void *values[] = { path, args }; | 181 const void *values[] = { path, args }; |
180 COMPILE_ASSERT(arraysize(keys) == arraysize(values), | 182 static_assert(arraysize(keys) == arraysize(values), |
181 array_sizes_must_match); | 183 "keys must have the same number of elements as values"); |
182 return CFDictionaryCreate(kCFAllocatorDefault, | 184 return CFDictionaryCreate(kCFAllocatorDefault, |
183 keys, | 185 keys, |
184 values, | 186 values, |
185 arraysize(keys), | 187 arraysize(keys), |
186 &kCFTypeDictionaryKeyCallBacks, | 188 &kCFTypeDictionaryKeyCallBacks, |
187 &kCFTypeDictionaryValueCallBacks); | 189 &kCFTypeDictionaryValueCallBacks); |
188 } | 190 } |
189 | 191 |
190 CFStringRef socket_key = CFSTR(LAUNCH_JOBKEY_SOCKETS); | 192 CFStringRef socket_key = CFSTR(LAUNCH_JOBKEY_SOCKETS); |
191 int local_pipe = -1; | 193 int local_pipe = -1; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 225 } |
224 | 226 |
225 base::ScopedCFTypeRef<CFNumberRef> socket_fd( | 227 base::ScopedCFTypeRef<CFNumberRef> socket_fd( |
226 CFNumberCreate(NULL, kCFNumberIntType, &local_pipe)); | 228 CFNumberCreate(NULL, kCFNumberIntType, &local_pipe)); |
227 const void *socket_array_values[] = { socket_fd }; | 229 const void *socket_array_values[] = { socket_fd }; |
228 base::ScopedCFTypeRef<CFArrayRef> sockets(CFArrayCreate( | 230 base::ScopedCFTypeRef<CFArrayRef> sockets(CFArrayCreate( |
229 kCFAllocatorDefault, socket_array_values, 1, &kCFTypeArrayCallBacks)); | 231 kCFAllocatorDefault, socket_array_values, 1, &kCFTypeArrayCallBacks)); |
230 CFStringRef socket_dict_key = CFSTR("ServiceProcessSocket"); | 232 CFStringRef socket_dict_key = CFSTR("ServiceProcessSocket"); |
231 const void *socket_keys[] = { socket_dict_key }; | 233 const void *socket_keys[] = { socket_dict_key }; |
232 const void *socket_values[] = { sockets }; | 234 const void *socket_values[] = { sockets }; |
233 COMPILE_ASSERT(arraysize(socket_keys) == arraysize(socket_values), | 235 static_assert(arraysize(socket_keys) == arraysize(socket_values), |
234 socket_array_sizes_must_match); | 236 "socket_keys must have the same number of elements " |
| 237 "as socket_values"); |
235 base::ScopedCFTypeRef<CFDictionaryRef> socket_dict( | 238 base::ScopedCFTypeRef<CFDictionaryRef> socket_dict( |
236 CFDictionaryCreate(kCFAllocatorDefault, | 239 CFDictionaryCreate(kCFAllocatorDefault, |
237 socket_keys, | 240 socket_keys, |
238 socket_values, | 241 socket_values, |
239 arraysize(socket_keys), | 242 arraysize(socket_keys), |
240 &kCFTypeDictionaryKeyCallBacks, | 243 &kCFTypeDictionaryKeyCallBacks, |
241 &kCFTypeDictionaryValueCallBacks)); | 244 &kCFTypeDictionaryValueCallBacks)); |
242 const void *keys[] = { program, program_args, socket_key }; | 245 const void *keys[] = { program, program_args, socket_key }; |
243 const void *values[] = { path, args, socket_dict }; | 246 const void *values[] = { path, args, socket_dict }; |
244 COMPILE_ASSERT(arraysize(keys) == arraysize(values), array_sizes_must_match); | 247 static_assert(arraysize(keys) == arraysize(values), |
| 248 "keys must have the same number of elements as values"); |
245 return CFDictionaryCreate(kCFAllocatorDefault, | 249 return CFDictionaryCreate(kCFAllocatorDefault, |
246 keys, | 250 keys, |
247 values, | 251 values, |
248 arraysize(keys), | 252 arraysize(keys), |
249 &kCFTypeDictionaryKeyCallBacks, | 253 &kCFTypeDictionaryKeyCallBacks, |
250 &kCFTypeDictionaryValueCallBacks); | 254 &kCFTypeDictionaryValueCallBacks); |
251 } | 255 } |
252 | 256 |
253 bool MockLaunchd::RemoveJob(CFStringRef label, CFErrorRef* error) { | 257 bool MockLaunchd::RemoveJob(CFStringRef label, CFErrorRef* error) { |
254 remove_called_ = true; | 258 remove_called_ = true; |
(...skipping 30 matching lines...) Expand all Loading... |
285 Type type, | 289 Type type, |
286 CFStringRef name) { | 290 CFStringRef name) { |
287 delete_called_ = true; | 291 delete_called_ = true; |
288 return true; | 292 return true; |
289 } | 293 } |
290 | 294 |
291 void MockLaunchd::SignalReady() { | 295 void MockLaunchd::SignalReady() { |
292 ASSERT_TRUE(as_service_); | 296 ASSERT_TRUE(as_service_); |
293 running_lock_.reset(TakeNamedLock(pipe_name_, true)); | 297 running_lock_.reset(TakeNamedLock(pipe_name_, true)); |
294 } | 298 } |
OLD | NEW |