OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/common/multi_process_lock.h" |
| 6 |
| 7 #include "base/mac/scoped_cftyperef.h" |
| 8 #include "base/sys_string_conversions.h" |
| 9 |
| 10 class MultiProcessLockMac : public MultiProcessLock { |
| 11 public: |
| 12 explicit MultiProcessLockMac(const std::string& name) |
| 13 : MultiProcessLock(name) { } |
| 14 |
| 15 virtual ~MultiProcessLockMac() { Unlock(); } |
| 16 |
| 17 virtual bool TryLock() { |
| 18 CFStringRef cf_name(base::SysUTF8ToCFStringRef(name_)); |
| 19 base::mac::ScopedCFTypeRef<CFStringRef> scoped_cf_name(cf_name); |
| 20 port_.reset(CFMessagePortCreateLocal(NULL, cf_name, NULL, NULL, NULL)); |
| 21 return port_ != NULL; |
| 22 } |
| 23 |
| 24 virtual void Unlock() { |
| 25 port_.reset(); |
| 26 } |
| 27 |
| 28 private: |
| 29 base::mac::ScopedCFTypeRef<CFMessagePortRef> port_; |
| 30 DISALLOW_COPY_AND_ASSIGN(MultiProcessLockMac); |
| 31 }; |
| 32 |
| 33 MultiProcessLock* MultiProcessLock::Create(const std::string &name) { |
| 34 return new MultiProcessLockMac(name); |
| 35 } |
OLD | NEW |