| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/mach_broker_mac.h" | 5 #include "content/browser/mach_broker_mac.h" |
| 6 | 6 |
| 7 #include <bsm/libbsm.h> | 7 #include <bsm/libbsm.h> |
| 8 #include <servers/bootstrap.h> | 8 #include <servers/bootstrap.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 private: | 125 private: |
| 126 // The MachBroker to use when new child task rights are received. Can be | 126 // The MachBroker to use when new child task rights are received. Can be |
| 127 // NULL. | 127 // NULL. |
| 128 MachBroker* broker_; // weak | 128 MachBroker* broker_; // weak |
| 129 | 129 |
| 130 base::mac::ScopedMachReceiveRight server_port_; | 130 base::mac::ScopedMachReceiveRight server_port_; |
| 131 | 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(MachListenerThreadDelegate); | 132 DISALLOW_COPY_AND_ASSIGN(MachListenerThreadDelegate); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 // static |
| 135 bool MachBroker::ChildSendTaskPortToParent() { | 136 bool MachBroker::ChildSendTaskPortToParent() { |
| 136 // Look up the named MachBroker port that's been registered with the | 137 // Look up the named MachBroker port that's been registered with the |
| 137 // bootstrap server. | 138 // bootstrap server. |
| 138 mach_port_t parent_port; | 139 mach_port_t parent_port; |
| 139 kern_return_t kr = bootstrap_look_up(bootstrap_port, | 140 kern_return_t kr = bootstrap_look_up(bootstrap_port, |
| 140 const_cast<char*>(GetMachPortName().c_str()), &parent_port); | 141 const_cast<char*>(GetMachPortName().c_str()), &parent_port); |
| 141 if (kr != KERN_SUCCESS) { | 142 if (kr != KERN_SUCCESS) { |
| 142 BOOTSTRAP_LOG(ERROR, kr) << "bootstrap_look_up"; | 143 BOOTSTRAP_LOG(ERROR, kr) << "bootstrap_look_up"; |
| 143 return false; | 144 return false; |
| 144 } | 145 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 160 kr = mach_msg(&msg.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, sizeof(msg), | 161 kr = mach_msg(&msg.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, sizeof(msg), |
| 161 0, MACH_PORT_NULL, 100 /*milliseconds*/, MACH_PORT_NULL); | 162 0, MACH_PORT_NULL, 100 /*milliseconds*/, MACH_PORT_NULL); |
| 162 if (kr != KERN_SUCCESS) { | 163 if (kr != KERN_SUCCESS) { |
| 163 MACH_LOG(ERROR, kr) << "mach_msg"; | 164 MACH_LOG(ERROR, kr) << "mach_msg"; |
| 164 return false; | 165 return false; |
| 165 } | 166 } |
| 166 | 167 |
| 167 return true; | 168 return true; |
| 168 } | 169 } |
| 169 | 170 |
| 171 // static |
| 172 std::string MachBroker::GetMachPortName() { |
| 173 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 174 const bool is_child = command_line->HasSwitch(switches::kProcessType); |
| 175 |
| 176 // In non-browser (child) processes, use the parent's pid. |
| 177 const pid_t pid = is_child ? getppid() : getpid(); |
| 178 return base::StringPrintf("%s.rohitfork.%d", base::mac::BaseBundleID(), pid); |
| 179 } |
| 180 |
| 181 // static |
| 170 MachBroker* MachBroker::GetInstance() { | 182 MachBroker* MachBroker::GetInstance() { |
| 171 return Singleton<MachBroker, LeakySingletonTraits<MachBroker> >::get(); | 183 return Singleton<MachBroker, LeakySingletonTraits<MachBroker> >::get(); |
| 172 } | 184 } |
| 173 | 185 |
| 174 base::Lock& MachBroker::GetLock() { | 186 base::Lock& MachBroker::GetLock() { |
| 175 return lock_; | 187 return lock_; |
| 176 } | 188 } |
| 177 | 189 |
| 178 void MachBroker::EnsureRunning() { | 190 void MachBroker::EnsureRunning() { |
| 179 lock_.AssertAcquired(); | 191 lock_.AssertAcquired(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 MachBroker::MachMap::iterator it = mach_map_.find(pid); | 279 MachBroker::MachMap::iterator it = mach_map_.find(pid); |
| 268 if (it == mach_map_.end()) | 280 if (it == mach_map_.end()) |
| 269 return; | 281 return; |
| 270 | 282 |
| 271 kern_return_t kr = mach_port_deallocate(mach_task_self(), | 283 kern_return_t kr = mach_port_deallocate(mach_task_self(), |
| 272 it->second); | 284 it->second); |
| 273 MACH_LOG_IF(WARNING, kr != KERN_SUCCESS, kr) << "mach_port_deallocate"; | 285 MACH_LOG_IF(WARNING, kr != KERN_SUCCESS, kr) << "mach_port_deallocate"; |
| 274 mach_map_.erase(it); | 286 mach_map_.erase(it); |
| 275 } | 287 } |
| 276 | 288 |
| 277 // static | |
| 278 std::string MachBroker::GetMachPortName() { | |
| 279 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 280 const bool is_child = command_line->HasSwitch(switches::kProcessType); | |
| 281 | |
| 282 // In non-browser (child) processes, use the parent's pid. | |
| 283 const pid_t pid = is_child ? getppid() : getpid(); | |
| 284 return base::StringPrintf("%s.rohitfork.%d", base::mac::BaseBundleID(), pid); | |
| 285 } | |
| 286 | |
| 287 void MachBroker::RegisterNotifications() { | 289 void MachBroker::RegisterNotifications() { |
| 288 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, | 290 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 289 NotificationService::AllBrowserContextsAndSources()); | 291 NotificationService::AllBrowserContextsAndSources()); |
| 290 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 292 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 291 NotificationService::AllBrowserContextsAndSources()); | 293 NotificationService::AllBrowserContextsAndSources()); |
| 292 | 294 |
| 293 // No corresponding StopObservingBrowserChildProcesses, | 295 // No corresponding StopObservingBrowserChildProcesses, |
| 294 // we leak this singleton. | 296 // we leak this singleton. |
| 295 BrowserChildProcessObserver::Add(this); | 297 BrowserChildProcessObserver::Add(this); |
| 296 } | 298 } |
| 297 | 299 |
| 298 } // namespace content | 300 } // namespace content |
| OLD | NEW |