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/service_process_util_posix.h" | |
6 | |
7 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
8 #include <launch.h> | 6 #include <launch.h> |
9 | 7 |
| 8 #include <memory> |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/bind.h" | 11 #include "base/bind.h" |
13 #include "base/command_line.h" | 12 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
15 #include "base/mac/bundle_locations.h" | 14 #include "base/mac/bundle_locations.h" |
16 #include "base/mac/foundation_util.h" | 15 #include "base/mac/foundation_util.h" |
17 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
18 #include "base/mac/scoped_nsautorelease_pool.h" | 17 #include "base/mac/scoped_nsautorelease_pool.h" |
19 #include "base/mac/scoped_nsobject.h" | 18 #include "base/mac/scoped_nsobject.h" |
20 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
21 #include "base/path_service.h" | 20 #include "base/path_service.h" |
22 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
23 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
24 #include "base/strings/sys_string_conversions.h" | 23 #include "base/strings/sys_string_conversions.h" |
25 #include "base/threading/thread_restrictions.h" | 24 #include "base/threading/thread_restrictions.h" |
26 #include "base/version.h" | 25 #include "base/version.h" |
27 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/mac/launchd.h" | 28 #include "chrome/common/mac/launchd.h" |
| 29 #include "chrome/common/service_process_util_posix.h" |
30 #include "components/version_info/version_info.h" | 30 #include "components/version_info/version_info.h" |
31 #include "ipc/unix_domain_socket_util.h" | 31 #include "ipc/unix_domain_socket_util.h" |
32 | 32 |
33 using ::base::FilePathWatcher; | 33 using ::base::FilePathWatcher; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 #define kServiceProcessSessionType "Aqua" | 37 #define kServiceProcessSessionType "Aqua" |
38 | 38 |
39 CFStringRef CopyServiceProcessLaunchDName() { | 39 CFStringRef CopyServiceProcessLaunchDName() { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 base::mac::ScopedNSAutoreleasePool pool; | 299 base::mac::ScopedNSAutoreleasePool pool; |
300 NSDictionary* ns_launchd_conf = base::mac::CFToNSCast(launchd_conf); | 300 NSDictionary* ns_launchd_conf = base::mac::CFToNSCast(launchd_conf); |
301 NSString* exe_path = [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_PROGRAM]; | 301 NSString* exe_path = [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_PROGRAM]; |
302 if (!exe_path) { | 302 if (!exe_path) { |
303 DLOG(ERROR) << "No " LAUNCH_JOBKEY_PROGRAM; | 303 DLOG(ERROR) << "No " LAUNCH_JOBKEY_PROGRAM; |
304 return false; | 304 return false; |
305 } | 305 } |
306 | 306 |
307 base::FilePath executable_path = | 307 base::FilePath executable_path = |
308 base::FilePath([exe_path fileSystemRepresentation]); | 308 base::FilePath([exe_path fileSystemRepresentation]); |
309 scoped_ptr<ExecFilePathWatcherCallback> callback( | 309 std::unique_ptr<ExecFilePathWatcherCallback> callback( |
310 new ExecFilePathWatcherCallback); | 310 new ExecFilePathWatcherCallback); |
311 if (!callback->Init(executable_path)) { | 311 if (!callback->Init(executable_path)) { |
312 DLOG(ERROR) << "executable_watcher.Init " << executable_path.value(); | 312 DLOG(ERROR) << "executable_watcher.Init " << executable_path.value(); |
313 return false; | 313 return false; |
314 } | 314 } |
315 if (!executable_watcher.Watch( | 315 if (!executable_watcher.Watch( |
316 executable_path, | 316 executable_path, |
317 false, | 317 false, |
318 base::Bind(&ExecFilePathWatcherCallback::NotifyPathChanged, | 318 base::Bind(&ExecFilePathWatcherCallback::NotifyPathChanged, |
319 base::Owned(callback.release())))) { | 319 base::Owned(callback.release())))) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 CFErrorRef err = NULL; | 430 CFErrorRef err = NULL; |
431 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { | 431 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { |
432 base::ScopedCFTypeRef<CFErrorRef> scoped_err(err); | 432 base::ScopedCFTypeRef<CFErrorRef> scoped_err(err); |
433 DLOG(ERROR) << "RemoveJob " << err; | 433 DLOG(ERROR) << "RemoveJob " << err; |
434 // Exiting with zero, so launchd doesn't restart the process. | 434 // Exiting with zero, so launchd doesn't restart the process. |
435 exit(0); | 435 exit(0); |
436 } | 436 } |
437 } | 437 } |
438 } | 438 } |
439 } | 439 } |
OLD | NEW |