Chromium Code Reviews| 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" | 5 #include "chrome/common/service_process_util_posix.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <launch.h> | 8 #include <launch.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 bool ServiceProcessState::Initialize() { | 173 bool ServiceProcessState::Initialize() { |
| 174 CFErrorRef err = NULL; | 174 CFErrorRef err = NULL; |
| 175 CFDictionaryRef dict = | 175 CFDictionaryRef dict = |
| 176 Launchd::GetInstance()->CopyDictionaryByCheckingIn(&err); | 176 Launchd::GetInstance()->CopyDictionaryByCheckingIn(&err); |
| 177 if (!dict) { | 177 if (!dict) { |
| 178 DLOG(ERROR) << "ServiceProcess must be launched by launchd. " | 178 DLOG(ERROR) << "ServiceProcess must be launched by launchd. " |
| 179 << "CopyLaunchdDictionaryByCheckingIn: " << err; | 179 << "CopyLaunchdDictionaryByCheckingIn: " << err; |
| 180 CFRelease(err); | 180 CFRelease(err); |
| 181 return false; | 181 return false; |
| 182 } | 182 } |
| 183 state_->launchd_conf_.reset(dict); | 183 state_->launchd_conf.reset(dict); |
| 184 return true; | 184 return true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { | 187 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { |
| 188 DCHECK(state_); | 188 DCHECK(state_); |
| 189 NSDictionary *ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf_); | 189 NSDictionary* ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf); |
| 190 NSDictionary* socket_dict = | 190 NSDictionary* socket_dict = |
| 191 [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_SOCKETS]; | 191 [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_SOCKETS]; |
| 192 NSArray* sockets = | 192 NSArray* sockets = |
| 193 [socket_dict objectForKey:GetServiceProcessLaunchDSocketKey()]; | 193 [socket_dict objectForKey:GetServiceProcessLaunchDSocketKey()]; |
| 194 DCHECK_EQ([sockets count], 1U); | 194 DCHECK_EQ([sockets count], 1U); |
| 195 int socket = [[sockets objectAtIndex:0] intValue]; | 195 int socket = [[sockets objectAtIndex:0] intValue]; |
| 196 base::FileDescriptor fd(socket, false); | 196 base::FileDescriptor fd(socket, false); |
| 197 return IPC::ChannelHandle(std::string(), fd); | 197 return IPC::ChannelHandle(std::string(), fd); |
| 198 } | 198 } |
| 199 | 199 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 name, | 294 name, |
| 295 plist); | 295 plist); |
| 296 } | 296 } |
| 297 | 297 |
| 298 bool ServiceProcessState::RemoveFromAutoRun() { | 298 bool ServiceProcessState::RemoveFromAutoRun() { |
| 299 return RemoveFromLaunchd(); | 299 return RemoveFromLaunchd(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 bool ServiceProcessState::StateData::WatchExecutable() { | 302 bool ServiceProcessState::StateData::WatchExecutable() { |
| 303 base::mac::ScopedNSAutoreleasePool pool; | 303 base::mac::ScopedNSAutoreleasePool pool; |
| 304 NSDictionary* ns_launchd_conf = base::mac::CFToNSCast(launchd_conf_); | 304 NSDictionary* ns_launchd_conf = base::mac::CFToNSCast(launchd_conf); |
| 305 NSString* exe_path = [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_PROGRAM]; | 305 NSString* exe_path = [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_PROGRAM]; |
| 306 if (!exe_path) { | 306 if (!exe_path) { |
| 307 DLOG(ERROR) << "No " LAUNCH_JOBKEY_PROGRAM; | 307 DLOG(ERROR) << "No " LAUNCH_JOBKEY_PROGRAM; |
| 308 return false; | 308 return false; |
| 309 } | 309 } |
| 310 | 310 |
| 311 base::FilePath executable_path = | 311 base::FilePath executable_path = |
| 312 base::FilePath([exe_path fileSystemRepresentation]); | 312 base::FilePath([exe_path fileSystemRepresentation]); |
| 313 scoped_ptr<ExecFilePathWatcherCallback> callback( | 313 scoped_ptr<ExecFilePathWatcherCallback> callback( |
| 314 new ExecFilePathWatcherCallback); | 314 new ExecFilePathWatcherCallback); |
| 315 if (!callback->Init(executable_path)) { | 315 if (!callback->Init(executable_path)) { |
| 316 DLOG(ERROR) << "executable_watcher_.Init " << executable_path.value(); | 316 DLOG(ERROR) << "executable_watcher.Init " << executable_path.value(); |
| 317 return false; | 317 return false; |
| 318 } | 318 } |
| 319 if (!executable_watcher_.Watch( | 319 if (!executable_watcher.Watch( |
| 320 executable_path, | 320 executable_path, false, |
|
James Hawkins
2015/03/02 15:36:27
Please don't change the style of the original file
qi1988.yang
2015/03/03 05:59:19
Done.
| |
| 321 false, | |
| 322 base::Bind(&ExecFilePathWatcherCallback::NotifyPathChanged, | 321 base::Bind(&ExecFilePathWatcherCallback::NotifyPathChanged, |
| 323 base::Owned(callback.release())))) { | 322 base::Owned(callback.release())))) { |
| 324 DLOG(ERROR) << "executable_watcher_.watch " << executable_path.value(); | 323 DLOG(ERROR) << "executable_watcher.watch " << executable_path.value(); |
| 325 return false; | 324 return false; |
| 326 } | 325 } |
| 327 return true; | 326 return true; |
| 328 } | 327 } |
| 329 | 328 |
| 330 bool ExecFilePathWatcherCallback::Init(const base::FilePath& path) { | 329 bool ExecFilePathWatcherCallback::Init(const base::FilePath& path) { |
| 331 return base::mac::FSRefFromPath(path.value(), &executable_fsref_); | 330 return base::mac::FSRefFromPath(path.value(), &executable_fsref_); |
| 332 } | 331 } |
| 333 | 332 |
| 334 void ExecFilePathWatcherCallback::NotifyPathChanged(const base::FilePath& path, | 333 void ExecFilePathWatcherCallback::NotifyPathChanged(const base::FilePath& path, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 CFErrorRef err = NULL; | 433 CFErrorRef err = NULL; |
| 435 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { | 434 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { |
| 436 base::ScopedCFTypeRef<CFErrorRef> scoped_err(err); | 435 base::ScopedCFTypeRef<CFErrorRef> scoped_err(err); |
| 437 DLOG(ERROR) << "RemoveJob " << err; | 436 DLOG(ERROR) << "RemoveJob " << err; |
| 438 // Exiting with zero, so launchd doesn't restart the process. | 437 // Exiting with zero, so launchd doesn't restart the process. |
| 439 exit(0); | 438 exit(0); |
| 440 } | 439 } |
| 441 } | 440 } |
| 442 } | 441 } |
| 443 } | 442 } |
| OLD | NEW |