| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/mach_broker_mac.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 // Constructor. | |
| 10 MachBroker::MachBroker() {} | |
| 11 | |
| 12 // Returns the global MachBroker. | |
| 13 MachBroker* MachBroker::instance() { | |
| 14 return Singleton<MachBroker>::get(); | |
| 15 } | |
| 16 | |
| 17 // Returns the mach task belonging to |pid|. | |
| 18 mach_port_t MachBroker::MachTaskForPid(base::ProcessHandle pid) const { | |
| 19 AutoLock lock(lock_); | |
| 20 MachBroker::MachMap::const_iterator it = mach_map_.find(pid); | |
| 21 if (it == mach_map_.end()) | |
| 22 return 0; | |
| 23 return it->second.mach_task_; | |
| 24 } | |
| 25 | |
| 26 // Returns the mach host belonging to |pid|. | |
| 27 mach_port_t MachBroker::MachHostForPid(base::ProcessHandle pid) const { | |
| 28 AutoLock lock(lock_); | |
| 29 MachMap::const_iterator it = mach_map_.find(pid); | |
| 30 if (it == mach_map_.end()) | |
| 31 return 0; | |
| 32 return it->second.mach_host_; | |
| 33 } | |
| 34 | |
| 35 // Adds mach info for a given pid. | |
| 36 void MachBroker::RegisterPid( | |
| 37 base::ProcessHandle pid, const MachInfo& mach_info) { | |
| 38 AutoLock lock(lock_); | |
| 39 DCHECK(mach_map_.count(pid) == 0); | |
| 40 mach_map_[pid] = mach_info; | |
| 41 } | |
| 42 | |
| 43 // Removes all mappings belonging to |pid| from the broker. | |
| 44 void MachBroker::Invalidate(base::ProcessHandle pid) { | |
| 45 AutoLock lock(lock_); | |
| 46 mach_map_.erase(pid); | |
| 47 } | |
| OLD | NEW |