| OLD | NEW |
| 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 Loading... |
| 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 : lock_path_(user_data_dir.Append(chrome::kSingletonLockFilename)), |
| 45 foreground_window_(NULL), | |
| 46 lock_path_(user_data_dir.Append(chrome::kSingletonLockFilename)), | |
| 47 lock_fd_(-1) { | 45 lock_fd_(-1) { |
| 48 } | 46 } |
| 49 | 47 |
| 50 ProcessSingleton::~ProcessSingleton() { | 48 ProcessSingleton::~ProcessSingleton() { |
| 51 // Make sure the lock is released. Process death will also release | 49 // Make sure the lock is released. Process death will also release |
| 52 // it, even if this is not called. | 50 // it, even if this is not called. |
| 53 Cleanup(); | 51 Cleanup(); |
| 54 } | 52 } |
| 55 | 53 |
| 56 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { | 54 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 109 } |
| 112 | 110 |
| 113 void ProcessSingleton::Cleanup() { | 111 void ProcessSingleton::Cleanup() { |
| 114 // Closing the file also releases the lock. | 112 // Closing the file also releases the lock. |
| 115 if (lock_fd_ != -1) { | 113 if (lock_fd_ != -1) { |
| 116 int rc = HANDLE_EINTR(close(lock_fd_)); | 114 int rc = HANDLE_EINTR(close(lock_fd_)); |
| 117 DPCHECK(!rc) << "Closing lock_fd_:"; | 115 DPCHECK(!rc) << "Closing lock_fd_:"; |
| 118 } | 116 } |
| 119 lock_fd_ = -1; | 117 lock_fd_ = -1; |
| 120 } | 118 } |
| OLD | NEW |