| 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 <errno.h> | 8 #include <errno.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| 11 #include <sys/un.h> | 11 #include <sys/un.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/mac/foundation_util.h" | 17 #include "base/mac/foundation_util.h" |
| 18 #include "base/mac/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 21 #include "base/single_thread_task_runner.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 23 #include "base/strings/sys_string_conversions.h" | 24 #include "base/strings/sys_string_conversions.h" |
| 24 #include "chrome/common/mac/launchd.h" | 25 #include "chrome/common/mac/launchd.h" |
| 25 #include "chrome/common/service_process_util.h" | 26 #include "chrome/common/service_process_util.h" |
| 26 #include "components/version_info/version_info.h" | 27 #include "components/version_info/version_info.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 // static | 30 // static |
| 30 bool MockLaunchd::MakeABundle(const base::FilePath& dst, | 31 bool MockLaunchd::MakeABundle(const base::FilePath& dst, |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 return CFDictionaryCreate(kCFAllocatorDefault, | 220 return CFDictionaryCreate(kCFAllocatorDefault, |
| 220 keys, | 221 keys, |
| 221 values, | 222 values, |
| 222 arraysize(keys), | 223 arraysize(keys), |
| 223 &kCFTypeDictionaryKeyCallBacks, | 224 &kCFTypeDictionaryKeyCallBacks, |
| 224 &kCFTypeDictionaryValueCallBacks); | 225 &kCFTypeDictionaryValueCallBacks); |
| 225 } | 226 } |
| 226 | 227 |
| 227 bool MockLaunchd::RemoveJob(CFStringRef label, CFErrorRef* error) { | 228 bool MockLaunchd::RemoveJob(CFStringRef label, CFErrorRef* error) { |
| 228 remove_called_ = true; | 229 remove_called_ = true; |
| 229 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 230 message_loop_->task_runner()->PostTask( |
| 231 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 230 return true; | 232 return true; |
| 231 } | 233 } |
| 232 | 234 |
| 233 bool MockLaunchd::RestartJob(Domain domain, | 235 bool MockLaunchd::RestartJob(Domain domain, |
| 234 Type type, | 236 Type type, |
| 235 CFStringRef name, | 237 CFStringRef name, |
| 236 CFStringRef session_type) { | 238 CFStringRef session_type) { |
| 237 restart_called_ = true; | 239 restart_called_ = true; |
| 238 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 240 message_loop_->task_runner()->PostTask( |
| 241 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 239 return true; | 242 return true; |
| 240 } | 243 } |
| 241 | 244 |
| 242 CFMutableDictionaryRef MockLaunchd::CreatePlistFromFile( | 245 CFMutableDictionaryRef MockLaunchd::CreatePlistFromFile( |
| 243 Domain domain, | 246 Domain domain, |
| 244 Type type, | 247 Type type, |
| 245 CFStringRef name) { | 248 CFStringRef name) { |
| 246 base::ScopedCFTypeRef<CFDictionaryRef> dict(CopyDictionaryByCheckingIn(NULL)); | 249 base::ScopedCFTypeRef<CFDictionaryRef> dict(CopyDictionaryByCheckingIn(NULL)); |
| 247 return CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, dict); | 250 return CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, dict); |
| 248 } | 251 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 259 Type type, | 262 Type type, |
| 260 CFStringRef name) { | 263 CFStringRef name) { |
| 261 delete_called_ = true; | 264 delete_called_ = true; |
| 262 return true; | 265 return true; |
| 263 } | 266 } |
| 264 | 267 |
| 265 void MockLaunchd::SignalReady() { | 268 void MockLaunchd::SignalReady() { |
| 266 ASSERT_TRUE(as_service_); | 269 ASSERT_TRUE(as_service_); |
| 267 running_lock_.reset(TakeNamedLock(pipe_name_, true)); | 270 running_lock_.reset(TakeNamedLock(pipe_name_, true)); |
| 268 } | 271 } |
| OLD | NEW |