OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/firefox_profile_lock.h" | |
6 | |
7 #include "base/file_util.h" | |
8 | |
9 // This class is based on Firefox code in: | |
10 // profile/dirserviceprovider/src/nsProfileLock.cpp | |
11 // The license block is: | |
12 | |
13 /* ***** BEGIN LICENSE BLOCK ***** | |
14 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
15 * | |
16 * The contents of this file are subject to the Mozilla Public License Version | |
17 * 1.1 (the "License"); you may not use this file except in compliance with | |
18 * the License. You may obtain a copy of the License at | |
19 * http://www.mozilla.org/MPL/ | |
20 * | |
21 * Software distributed under the License is distributed on an "AS IS" basis, | |
22 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
23 * for the specific language governing rights and limitations under the | |
24 * License. | |
25 * | |
26 * The Original Code is mozilla.org code. | |
27 * | |
28 * The Initial Developer of the Original Code is | |
29 * Netscape Communications Corporation. | |
30 * Portions created by the Initial Developer are Copyright (C) 2002 | |
31 * the Initial Developer. All Rights Reserved. | |
32 * | |
33 * Contributor(s): | |
34 * Conrad Carlen <ccarlen@netscape.com> | |
35 * Brendan Eich <brendan@mozilla.org> | |
36 * Colin Blake <colin@theblakes.com> | |
37 * Javier Pedemonte <pedemont@us.ibm.com> | |
38 * Mats Palmgren <mats.palmgren@bredband.net> | |
39 * | |
40 * Alternatively, the contents of this file may be used under the terms of | |
41 * either the GNU General Public License Version 2 or later (the "GPL"), or | |
42 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
43 * in which case the provisions of the GPL or the LGPL are applicable instead | |
44 * of those above. If you wish to allow use of your version of this file only | |
45 * under the terms of either the GPL or the LGPL, and not to allow others to | |
46 * use your version of this file under the terms of the MPL, indicate your | |
47 * decision by deleting the provisions above and replace them with the notice | |
48 * and other provisions required by the GPL or the LGPL. If you do not delete | |
49 * the provisions above, a recipient may use your version of this file under | |
50 * the terms of any one of the MPL, the GPL or the LGPL. | |
51 * | |
52 * ***** END LICENSE BLOCK ***** */ | |
53 | |
54 // static | |
55 wchar_t FirefoxProfileLock::kLockFileName[] = L"parent.lock"; | |
56 | |
57 FirefoxProfileLock::FirefoxProfileLock(const std::wstring& path) | |
58 : lock_handle_(INVALID_HANDLE_VALUE) { | |
59 lock_file_ = path; | |
60 file_util::AppendToPath(&lock_file_, kLockFileName); | |
61 Lock(); | |
62 } | |
63 | |
64 FirefoxProfileLock::~FirefoxProfileLock() { | |
65 Unlock(); | |
66 } | |
67 | |
68 void FirefoxProfileLock::Lock() { | |
69 if (HasAcquired()) | |
70 return; | |
71 lock_handle_ = CreateFile(lock_file_.c_str(), GENERIC_READ | GENERIC_WRITE, | |
72 0, NULL, OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, | |
73 NULL); | |
74 } | |
75 | |
76 void FirefoxProfileLock::Unlock() { | |
77 if (!HasAcquired()) | |
78 return; | |
79 CloseHandle(lock_handle_); | |
80 lock_handle_ = INVALID_HANDLE_VALUE; | |
81 } | |
82 | |
83 bool FirefoxProfileLock::HasAcquired() { | |
84 return (lock_handle_ != INVALID_HANDLE_VALUE); | |
85 } | |
86 | |
87 | |
OLD | NEW |