| 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 #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__ | 5 #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__ |
| 6 #define CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__ | 6 #define CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 ~FirefoxProfileLock(); | 73 ~FirefoxProfileLock(); |
| 74 | 74 |
| 75 // Locks and releases the profile. | 75 // Locks and releases the profile. |
| 76 void Lock(); | 76 void Lock(); |
| 77 void Unlock(); | 77 void Unlock(); |
| 78 | 78 |
| 79 // Returns true if we lock the profile successfully. | 79 // Returns true if we lock the profile successfully. |
| 80 bool HasAcquired(); | 80 bool HasAcquired(); |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 FRIEND_TEST(FirefoxImporterTest, ProfileLock); | 83 FRIEND_TEST(FirefoxProfileLockTest, ProfileLock); |
| 84 FRIEND_TEST(FirefoxImporterTest, ProfileLockOrphaned); | 84 FRIEND_TEST(FirefoxProfileLockTest, ProfileLockOrphaned); |
| 85 | 85 |
| 86 static const FilePath::CharType* kLockFileName; | 86 static const FilePath::CharType* kLockFileName; |
| 87 static const FilePath::CharType* kOldLockFileName; | 87 static const FilePath::CharType* kOldLockFileName; |
| 88 | 88 |
| 89 void Init(); | 89 void Init(); |
| 90 | 90 |
| 91 // Full path of the lock file in the profile folder. | 91 // Full path of the lock file in the profile folder. |
| 92 FilePath lock_file_; | 92 FilePath lock_file_; |
| 93 | 93 |
| 94 // The handle of the lock file. | 94 // The handle of the lock file. |
| 95 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
| 96 HANDLE lock_handle_; | 96 HANDLE lock_handle_; |
| 97 #elif defined(OS_POSIX) | 97 #elif defined(OS_POSIX) |
| 98 int lock_fd_; | 98 int lock_fd_; |
| 99 | 99 |
| 100 // On Posix systems Firefox apparently first tries to put a fcntl lock | 100 // On Posix systems Firefox apparently first tries to put a fcntl lock |
| 101 // on a file and if that fails, it does a regular exculsive open on another | 101 // on a file and if that fails, it does a regular exculsive open on another |
| 102 // file. This variable contains the location of this other file. | 102 // file. This variable contains the location of this other file. |
| 103 FilePath old_lock_file_; | 103 FilePath old_lock_file_; |
| 104 | 104 |
| 105 // Method that tries to put a fcntl lock on file specified by |lock_file_|. | 105 // Method that tries to put a fcntl lock on file specified by |lock_file_|. |
| 106 // Returns false if lock is already help by another process. true in all | 106 // Returns false if lock is already held by another process. true in all |
| 107 // other cases. | 107 // other cases. |
| 108 bool LockWithFcntl(); | 108 bool LockWithFcntl(); |
| 109 #endif | 109 #endif |
| 110 | 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(FirefoxProfileLock); | 111 DISALLOW_COPY_AND_ASSIGN(FirefoxProfileLock); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 #endif // CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__ | 114 #endif // CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__ |
| OLD | NEW |