| 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 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
| 6 #include <launch.h> | 6 #include <launch.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 base::FilePath socket_name; | 94 base::FilePath socket_name; |
| 95 PathService::Get(base::DIR_TEMP, &socket_name); | 95 PathService::Get(base::DIR_TEMP, &socket_name); |
| 96 std::string pipe_name = GetServiceProcessScopedName("srv"); | 96 std::string pipe_name = GetServiceProcessScopedName("srv"); |
| 97 socket_name = socket_name.Append(pipe_name); | 97 socket_name = socket_name.Append(pipe_name); |
| 98 CHECK_LT(socket_name.value().size(), IPC::kMaxSocketNameLength); | 98 CHECK_LT(socket_name.value().size(), IPC::kMaxSocketNameLength); |
| 99 return socket_name; | 99 return socket_name; |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace | 102 } // namespace |
| 103 | 103 |
| 104 IPC::ChannelHandle GetServiceProcessChannel() { | 104 mojo::edk::NamedPlatformHandle GetServiceProcessChannel() { |
| 105 base::FilePath socket_name = GetServiceProcessSocketName(); | 105 base::FilePath socket_name = GetServiceProcessSocketName(); |
| 106 VLOG(1) << "ServiceProcessChannel: " << socket_name.value(); | 106 VLOG(1) << "ServiceProcessChannel: " << socket_name.value(); |
| 107 return IPC::ChannelHandle(socket_name.value()); | 107 return mojo::edk::NamedPlatformHandle(socket_name.value()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool ForceServiceProcessShutdown(const std::string& /* version */, | 110 bool ForceServiceProcessShutdown(const std::string& /* version */, |
| 111 base::ProcessId /* process_id */) { | 111 base::ProcessId /* process_id */) { |
| 112 base::mac::ScopedNSAutoreleasePool pool; | 112 base::mac::ScopedNSAutoreleasePool pool; |
| 113 CFStringRef label = base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); | 113 CFStringRef label = base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); |
| 114 CFErrorRef err = NULL; | 114 CFErrorRef err = NULL; |
| 115 bool ret = Launchd::GetInstance()->RemoveJob(label, &err); | 115 bool ret = Launchd::GetInstance()->RemoveJob(label, &err); |
| 116 if (!ret) { | 116 if (!ret) { |
| 117 DLOG(ERROR) << "ForceServiceProcessShutdown: " << err << " " | 117 DLOG(ERROR) << "ForceServiceProcessShutdown: " << err << " " |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 if (!dict) { | 175 if (!dict) { |
| 176 DLOG(ERROR) << "ServiceProcess must be launched by launchd. " | 176 DLOG(ERROR) << "ServiceProcess must be launched by launchd. " |
| 177 << "CopyLaunchdDictionaryByCheckingIn: " << err; | 177 << "CopyLaunchdDictionaryByCheckingIn: " << err; |
| 178 CFRelease(err); | 178 CFRelease(err); |
| 179 return false; | 179 return false; |
| 180 } | 180 } |
| 181 state_->launchd_conf.reset(dict); | 181 state_->launchd_conf.reset(dict); |
| 182 return true; | 182 return true; |
| 183 } | 183 } |
| 184 | 184 |
| 185 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { | 185 mojo::edk::ScopedPlatformHandle |
| 186 ServiceProcessState::GetServiceProcessChannel() { |
| 186 DCHECK(state_); | 187 DCHECK(state_); |
| 187 NSDictionary* ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf); | 188 NSDictionary* ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf); |
| 188 NSDictionary* socket_dict = | 189 NSDictionary* socket_dict = |
| 189 [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_SOCKETS]; | 190 [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_SOCKETS]; |
| 190 NSArray* sockets = | 191 NSArray* sockets = |
| 191 [socket_dict objectForKey:GetServiceProcessLaunchDSocketKey()]; | 192 [socket_dict objectForKey:GetServiceProcessLaunchDSocketKey()]; |
| 192 DCHECK_EQ([sockets count], 1U); | 193 DCHECK_EQ([sockets count], 1U); |
| 193 int socket = [[sockets objectAtIndex:0] intValue]; | 194 int socket = [[sockets objectAtIndex:0] intValue]; |
| 194 base::FileDescriptor fd(socket, false); | 195 return mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(socket)); |
| 195 return IPC::ChannelHandle(std::string(), fd); | |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool CheckServiceProcessReady() { | 198 bool CheckServiceProcessReady() { |
| 199 std::string version; | 199 std::string version; |
| 200 pid_t pid; | 200 pid_t pid; |
| 201 if (!GetServiceProcessData(&version, &pid)) { | 201 if (!GetServiceProcessData(&version, &pid)) { |
| 202 return false; | 202 return false; |
| 203 } | 203 } |
| 204 base::Version service_version(version); | 204 base::Version service_version(version); |
| 205 bool ready = true; | 205 bool ready = true; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 CFErrorRef err = NULL; | 462 CFErrorRef err = NULL; |
| 463 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { | 463 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { |
| 464 base::ScopedCFTypeRef<CFErrorRef> scoped_err(err); | 464 base::ScopedCFTypeRef<CFErrorRef> scoped_err(err); |
| 465 DLOG(ERROR) << "RemoveJob " << err; | 465 DLOG(ERROR) << "RemoveJob " << err; |
| 466 // Exiting with zero, so launchd doesn't restart the process. | 466 // Exiting with zero, so launchd doesn't restart the process. |
| 467 exit(0); | 467 exit(0); |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 } | 471 } |
| OLD | NEW |