| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/importer/firefox_profile_lock.h" | 5 #include "chrome/browser/importer/firefox_profile_lock.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 old_lock_file_ = lock_file_.DirName().Append(kOldLockFileName); | 71 old_lock_file_ = lock_file_.DirName().Append(kOldLockFileName); |
| 72 lock_fd_ = open(old_lock_file_.value().c_str(), O_CREAT | O_EXCL, 0644); | 72 lock_fd_ = open(old_lock_file_.value().c_str(), O_CREAT | O_EXCL, 0644); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void FirefoxProfileLock::Unlock() { | 76 void FirefoxProfileLock::Unlock() { |
| 77 if (!HasAcquired()) | 77 if (!HasAcquired()) |
| 78 return; | 78 return; |
| 79 close(lock_fd_); | 79 close(lock_fd_); |
| 80 lock_fd_ = -1; | 80 lock_fd_ = -1; |
| 81 file_util::Delete(old_lock_file_, false); | 81 base::Delete(old_lock_file_, false); |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool FirefoxProfileLock::HasAcquired() { | 84 bool FirefoxProfileLock::HasAcquired() { |
| 85 return (lock_fd_ >= 0); | 85 return (lock_fd_ >= 0); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // This function tries to lock Firefox profile using fcntl(). The return | 88 // This function tries to lock Firefox profile using fcntl(). The return |
| 89 // value of this function together with HasAcquired() tells the current status | 89 // value of this function together with HasAcquired() tells the current status |
| 90 // of lock. | 90 // of lock. |
| 91 // if return == false: Another process has lock to the profile. | 91 // if return == false: Another process has lock to the profile. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 115 lock_fd_ = -1; | 115 lock_fd_ = -1; |
| 116 if (errno == EAGAIN || errno == EACCES) | 116 if (errno == EAGAIN || errno == EACCES) |
| 117 return false; | 117 return false; |
| 118 else | 118 else |
| 119 return true; | 119 return true; |
| 120 } else { | 120 } else { |
| 121 // We have the lock. | 121 // We have the lock. |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 } | 124 } |
| OLD | NEW |