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

Side by Side Diff: chrome/browser/process_singleton_mac.cc

Issue 12096114: Extract locking behaviour from ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment clarification. Created 7 years, 8 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/file.h> 7 #include <sys/file.h>
8 8
9 #include "chrome/browser/process_singleton.h" 9 #include "chrome/browser/process_singleton.h"
10 10
(...skipping 23 matching lines...) Expand all
34 // 34 //
35 // Neither of those cases apply on the Mac. Launch Services ensures that there 35 // Neither of those cases apply on the Mac. Launch Services ensures that there
36 // is only one instance of the process, and we get URLs to open via AppleEvents 36 // is only one instance of the process, and we get URLs to open via AppleEvents
37 // and, once again, the Launch Services system. We have no need to manage this 37 // and, once again, the Launch Services system. We have no need to manage this
38 // ourselves. An exclusive lock is used to flush out anyone making incorrect 38 // ourselves. An exclusive lock is used to flush out anyone making incorrect
39 // assumptions. 39 // assumptions.
40 40
41 ProcessSingleton::ProcessSingleton( 41 ProcessSingleton::ProcessSingleton(
42 const base::FilePath& user_data_dir, 42 const base::FilePath& user_data_dir,
43 const NotificationCallback& /* notification_callback */) 43 const NotificationCallback& /* notification_callback */)
44 : locked_(false), 44 : foreground_window_(NULL),
45 foreground_window_(NULL),
46 lock_path_(user_data_dir.Append(chrome::kSingletonLockFilename)), 45 lock_path_(user_data_dir.Append(chrome::kSingletonLockFilename)),
47 lock_fd_(-1) { 46 lock_fd_(-1) {
48 } 47 }
49 48
50 ProcessSingleton::~ProcessSingleton() { 49 ProcessSingleton::~ProcessSingleton() {
51 // Make sure the lock is released. Process death will also release 50 // Make sure the lock is released. Process death will also release
52 // it, even if this is not called. 51 // it, even if this is not called.
53 Cleanup(); 52 Cleanup();
54 } 53 }
55 54
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 110 }
112 111
113 void ProcessSingleton::Cleanup() { 112 void ProcessSingleton::Cleanup() {
114 // Closing the file also releases the lock. 113 // Closing the file also releases the lock.
115 if (lock_fd_ != -1) { 114 if (lock_fd_ != -1) {
116 int rc = HANDLE_EINTR(close(lock_fd_)); 115 int rc = HANDLE_EINTR(close(lock_fd_));
117 DPCHECK(!rc) << "Closing lock_fd_:"; 116 DPCHECK(!rc) << "Closing lock_fd_:";
118 } 117 }
119 lock_fd_ = -1; 118 lock_fd_ = -1;
120 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698