Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/common/multi_process_lock_mac.cc

Issue 4721001: Add multi_process_lock to chrome/common (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix up silly linux compile issue Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/logging.h"
8 #include "base/mac/scoped_cftyperef.h"
9 #include "base/sys_string_conversions.h"
10
11 class MultiProcessLockMac : public MultiProcessLock {
12 public:
13 explicit MultiProcessLockMac(const std::string& name) : name_(name) { }
14
15 virtual ~MultiProcessLockMac() {
16 if (port_ != NULL) {
17 Unlock();
18 }
19 }
20
21 virtual bool TryLock() {
22 if (port_ != NULL) {
23 DLOG(ERROR) << "MultiProcessLock is already locked - " << name_;
24 return true;
25 }
26 CFStringRef cf_name(base::SysUTF8ToCFStringRef(name_));
27 base::mac::ScopedCFTypeRef<CFStringRef> scoped_cf_name(cf_name);
28 port_.reset(CFMessagePortCreateLocal(NULL, cf_name, NULL, NULL, NULL));
29 return port_ != NULL;
30 }
31
32 virtual void Unlock() {
33 if (port_ == NULL) {
34 DLOG(ERROR) << "Over unlocked MultiProcessLock - " << name_;
Mark Mentovai 2010/11/12 17:58:28 When I said “hyphenate,” I meant “over-unlocked”.
dmac 2010/11/15 23:02:13 Done.
35 return;
36 }
37 port_.reset();
38 }
39
40 private:
41 std::string name_;
42 base::mac::ScopedCFTypeRef<CFMessagePortRef> port_;
43 DISALLOW_COPY_AND_ASSIGN(MultiProcessLockMac);
44 };
45
46 MultiProcessLock* MultiProcessLock::Create(const std::string &name) {
47 return new MultiProcessLockMac(name);
48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698