1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/importer/firefox_profile_lock.h" 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/file_path.h" 8ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/threading/thread_restrictions.h" 9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This class is based on Firefox code in: 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// profile/dirserviceprovider/src/nsProfileLock.cpp 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// The license block is: 13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch/* ***** BEGIN LICENSE BLOCK ***** 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Version: MPL 1.1/GPL 2.0/LGPL 2.1 16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* 17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* The contents of this file are subject to the Mozilla Public License Version 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* 1.1 (the "License"); you may not use this file except in compliance with 19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* the License. You may obtain a copy of the License at 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* http://www.mozilla.org/MPL/ 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Software distributed under the License is distributed on an "AS IS" basis, 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* for the specific language governing rights and limitations under the 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* License. 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* The Original Code is mozilla.org code. 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* The Initial Developer of the Original Code is 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Netscape Communications Corporation. 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Portions created by the Initial Developer are Copyright (C) 2002 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* the Initial Developer. All Rights Reserved. 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* 34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Contributor(s): 35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Conrad Carlen <ccarlen@netscape.com> 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Brendan Eich <brendan@mozilla.org> 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Colin Blake <colin@theblakes.com> 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Javier Pedemonte <pedemont@us.ibm.com> 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Mats Palmgren <mats.palmgren@bredband.net> 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* Alternatively, the contents of this file may be used under the terms of 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* either the GNU General Public License Version 2 or later (the "GPL"), or 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* in which case the provisions of the GPL or the LGPL are applicable instead 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* of those above. If you wish to allow use of your version of this file only 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* under the terms of either the GPL or the LGPL, and not to allow others to 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* use your version of this file under the terms of the MPL, indicate your 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* decision by deleting the provisions above and replace them with the notice 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* and other provisions required by the GPL or the LGPL. If you do not delete 50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* the provisions above, a recipient may use your version of this file under 51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* the terms of any one of the MPL, the GPL or the LGPL. 52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* 53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch* ***** END LICENSE BLOCK ***** */ 54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// static 56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(OS_MACOSX) 57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst FilePath::CharType* FirefoxProfileLock::kLockFileName = 58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch FILE_PATH_LITERAL(".parentlock"); 59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst FilePath::CharType* FirefoxProfileLock::kOldLockFileName = 60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch FILE_PATH_LITERAL("parent.lock"); 61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#elif defined(OS_POSIX) 62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// http://www.google.com/codesearch/p?hl=en#e_ObwTAVPyo/profile/dirserviceprovider/src/nsProfileLock.cpp&l=433 63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst FilePath::CharType* FirefoxProfileLock::kLockFileName = 64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch FILE_PATH_LITERAL(".parentlock"); 65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst FilePath::CharType* FirefoxProfileLock::kOldLockFileName = 66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch FILE_PATH_LITERAL("lock"); 67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#else 68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst FilePath::CharType* FirefoxProfileLock::kLockFileName = 69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch FILE_PATH_LITERAL("parent.lock"); 70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif 71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 72c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochFirefoxProfileLock::FirefoxProfileLock(const FilePath& path) { 73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Init(); 74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch lock_file_ = path.Append(kLockFileName); 75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Lock(); 76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 78c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochFirefoxProfileLock::~FirefoxProfileLock() { 79ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Because this destructor happens in first run on the profile import thread, 80ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // with no UI to jank, it's ok to allow deletion of the lock here. 81ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen base::ThreadRestrictions::ScopedAllowIO allow_io; 82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Unlock(); 83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 84