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

Unified 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: more clean up for mento 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/multi_process_lock_mac.cc
diff --git a/chrome/common/multi_process_lock_mac.cc b/chrome/common/multi_process_lock_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9a16d71a70760cd780b4e1f518170963e8625a8a
--- /dev/null
+++ b/chrome/common/multi_process_lock_mac.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/multi_process_lock.h"
+
+#include "base/logging.h"
+#include "base/mac/scoped_cftyperef.h"
+#include "base/sys_string_conversions.h"
+
+class MultiProcessLockMac : public MultiProcessLock {
+ public:
+ explicit MultiProcessLockMac(const std::string& name) : name_(name) { }
+
+ virtual ~MultiProcessLockMac() {
+ if (port_ != NULL) {
+ Unlock();
+ }
+ }
+
+ virtual bool TryLock() {
+ if (port_ != NULL) {
+ DLOG(ERROR) << "MultiProcessLock is already locked - " << name_;
+ return true;
+ }
+
+ if (name_.length() > MULTI_PROCESS_LOCK_NAME_MAX_LEN) {
+ LOG(ERROR) << "Socket name too long - " << name_;
+ return false;
+ }
+
+ CFStringRef cf_name(base::SysUTF8ToCFStringRef(name_));
+ base::mac::ScopedCFTypeRef<CFStringRef> scoped_cf_name(cf_name);
+ port_.reset(CFMessagePortCreateLocal(NULL, cf_name, NULL, NULL, NULL));
+ return port_ != NULL;
+ }
+
+ virtual void Unlock() {
+ if (port_ == NULL) {
+ DLOG(ERROR) << "Over-unlocked MultiProcessLock - " << name_;
+ return;
+ }
+ port_.reset();
+ }
+
+ private:
+ std::string name_;
+ base::mac::ScopedCFTypeRef<CFMessagePortRef> port_;
+ DISALLOW_COPY_AND_ASSIGN(MultiProcessLockMac);
+};
+
+MultiProcessLock* MultiProcessLock::Create(const std::string &name) {
+ return new MultiProcessLockMac(name);
+}

Powered by Google App Engine
This is Rietveld 408576698