зеркало из https://github.com/mozilla/pjs.git
Bug 76431 - Protect profiles from multiple instances sharing the same profile. r=brendan/sr=darin
This commit is contained in:
Родитель
49cab2d6dc
Коммит
32e3832782
|
@ -397,7 +397,7 @@ extern "C" void ProfileMigrationController(void *data)
|
|||
|
||||
if (migrator->mErrorCode != 0)
|
||||
{
|
||||
if (migrator->mErrorCode == RETRY)
|
||||
if (migrator->mErrorCode == MIGRATION_RETRY)
|
||||
{
|
||||
rv = prefProxy->ShowSpaceDialog(&choice);
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -409,7 +409,7 @@ extern "C" void ProfileMigrationController(void *data)
|
|||
}
|
||||
}
|
||||
|
||||
} while (choice == RETRY);
|
||||
} while (choice == MIGRATION_RETRY);
|
||||
|
||||
prefProxy->WindowCloseCallback();
|
||||
migrator->mErrorCode = choice;
|
||||
|
@ -823,7 +823,7 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char
|
|||
|
||||
if (!enoughSpace)
|
||||
{
|
||||
mErrorCode = RETRY;
|
||||
mErrorCode = MIGRATION_RETRY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,10 +53,10 @@
|
|||
#include "nsVoidArray.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#define SUCCESS 0
|
||||
#define RETRY 1
|
||||
#define CREATE_NEW 2
|
||||
#define CANCEL 3
|
||||
#define MIGRATION_SUCCESS 0
|
||||
#define MIGRATION_RETRY 1
|
||||
#define MIGRATION_CREATE_NEW 2
|
||||
#define MIGRATION_CANCEL 3
|
||||
|
||||
#define MAX_DRIVES 4
|
||||
|
||||
|
|
|
@ -159,6 +159,8 @@ function onStart()
|
|||
{
|
||||
var profileList = document.getElementById("profiles");
|
||||
var selected = profileList.selectedItems[0];
|
||||
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
|
||||
getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
var profilename = selected.getAttribute("profile_name");
|
||||
if( selected.getAttribute("rowMigrate") == "no" ) {
|
||||
|
@ -168,8 +170,6 @@ function onStart()
|
|||
gBrandBundle.getString("brandShortName"));
|
||||
var title = gProfileManagerBundle.getString("migratetitle");
|
||||
|
||||
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
|
||||
promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService);
|
||||
if (promptService.confirm(window, title, lString)) {
|
||||
var profileDir = profile.getProfileDir(profilename);
|
||||
if (profileDir) {
|
||||
|
@ -196,34 +196,30 @@ function onStart()
|
|||
ioService.offline = offlineState.checked;
|
||||
|
||||
try {
|
||||
|
||||
var dirExists;
|
||||
|
||||
try {
|
||||
var profileDir = profile.getProfileDir(profilename);
|
||||
dirExists = profileDir.exists();
|
||||
}
|
||||
catch (e) {
|
||||
dirExists = false;
|
||||
}
|
||||
|
||||
if (dirExists == false) {
|
||||
var brandName = gBrandBundle.getString("brandShortName");
|
||||
var alertString = gProfileManagerBundle.getFormattedString("profDirMissing", [brandName, profilename]);
|
||||
alertString = alertString.replace(/\s*<html:br\/>/g,"\n");
|
||||
alert(alertString);
|
||||
return;
|
||||
}
|
||||
|
||||
// All this really does is set the current profile.
|
||||
// It has nothing to do with starting the application.
|
||||
profile.startApprunner(profilename);
|
||||
}
|
||||
catch (ex) {
|
||||
//var stringA = gProfileManagerBundle.getString(failProfileStartA);
|
||||
//var stringB = gProfileManagerBundle.getString(failProfileStartB);
|
||||
//alert(stringA + " " + profilename + " " + stringB);
|
||||
var brandName = gBrandBundle.getString("brandShortName");
|
||||
var message;
|
||||
switch (ex.result) {
|
||||
case Components.results.NS_ERROR_FILE_ACCESS_DENIED:
|
||||
message = gProfileManagerBundle.getFormattedString("profDirLocked", [brandName, profilename]);
|
||||
message = message.replace(/\s*<html:br\/>/g,"\n");
|
||||
break;
|
||||
case Components.results.NS_ERROR_FILE_NOT_FOUND:
|
||||
message = gProfileManagerBundle.getFormattedString("profDirMissing", [brandName, profilename]);
|
||||
message = message.replace(/\s*<html:br\/>/g,"\n");
|
||||
break;
|
||||
default:
|
||||
message = ex.message;
|
||||
break;
|
||||
}
|
||||
promptService.alert(window, null, message);
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ invalidCharB="<html:br/><html:br/>Please choose a different name for the profile
|
|||
profileExists=A profile with this name already exists. Please choose another name.
|
||||
profileExistsTitle=Profile Exists
|
||||
profDirMissing=%S cannot use the profile "%S" because the directory containing the profile cannot be found.<html:br/><html:br/> Please choose another profile or create a new one.
|
||||
profDirLocked=%S cannot use the profile "%S" because it is in use.<html:br/><html:br/> Please choose another profile or create a new one.
|
||||
|
||||
|
||||
sourceProfileDirMissing=This profile cannot be migrated because the directory containing the profile information could not be found. Choose another profile or create a new one.
|
||||
sourceProfileDirMissingTitle=Profile Directory Missing
|
||||
|
|
|
@ -64,3 +64,7 @@ EXTRA_DSO_LDOPTS = \
|
|||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
DEFINES += -D_BSD_SOURCE
|
||||
endif
|
||||
|
||||
|
|
|
@ -537,13 +537,22 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr, PRBool canInteract)
|
|||
{
|
||||
// Make sure the profile dir exists. If not, we need the UI
|
||||
nsCOMPtr<nsIFile> curProfileDir;
|
||||
PRBool exists;
|
||||
PRBool exists = PR_FALSE;
|
||||
|
||||
rv = GetCurrentProfileDir(getter_AddRefs(curProfileDir));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = curProfileDir->Exists(&exists);
|
||||
if (NS_FAILED(rv) || !exists)
|
||||
profileURLStr = PROFILE_MANAGER_URL;
|
||||
if (exists)
|
||||
{
|
||||
// If the profile is locked, we need the UI
|
||||
nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(curProfileDir));
|
||||
nsProfileLock tempLock;
|
||||
rv = tempLock.Lock(localFile);
|
||||
if (NS_FAILED(rv))
|
||||
profileURLStr = PROFILE_MANAGER_URL;
|
||||
}
|
||||
}
|
||||
else
|
||||
profileURLStr = PROFILE_SELECTION_URL;
|
||||
|
@ -1180,6 +1189,16 @@ nsProfile::SetCurrentProfile(const PRUnichar * aCurrentProfile)
|
|||
else
|
||||
isSwitch = PR_FALSE;
|
||||
|
||||
nsProfileLock localLock;
|
||||
nsCOMPtr<nsILocalFile> localProfileDir(do_QueryInterface(profileDir, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = localLock.Lock(localProfileDir);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_ERROR("Could not get profile directory lock.");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
do_GetService("@mozilla.org/observer-service;1", &rv);
|
||||
NS_ENSURE_TRUE(observerService, NS_ERROR_FAILURE);
|
||||
|
@ -1214,6 +1233,7 @@ nsProfile::SetCurrentProfile(const PRUnichar * aCurrentProfile)
|
|||
gProfileDataAccess->SetCurrentProfile(aCurrentProfile);
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
mCurrentProfileLock = localLock;
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mCurrentProfileAvailable = PR_TRUE;
|
||||
|
@ -1300,6 +1320,7 @@ NS_IMETHODIMP nsProfile::ShutDownCurrentProfile(PRUint32 shutDownType)
|
|||
UpdateCurrentProfileModTime(PR_TRUE);
|
||||
mCurrentProfileAvailable = PR_FALSE;
|
||||
mCurrentProfileName.Truncate(0);
|
||||
mCurrentProfileLock.Unlock();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -2188,7 +2209,7 @@ nsProfile::MigrateProfileInternal(const PRUnichar* profileName,
|
|||
|
||||
// In either of the cases below we have to return error to make
|
||||
// app understand that migration has failed.
|
||||
if (errorCode == CREATE_NEW)
|
||||
if (errorCode == MIGRATION_CREATE_NEW)
|
||||
{
|
||||
PRInt32 numProfiles = 0;
|
||||
ShowProfileWizard();
|
||||
|
@ -2212,7 +2233,7 @@ nsProfile::MigrateProfileInternal(const PRUnichar* profileName,
|
|||
mOutofDiskSpace = PR_TRUE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
else if (errorCode == CANCEL)
|
||||
else if (errorCode == MIGRATION_CANCEL)
|
||||
{
|
||||
// When the automigration process fails because of disk space error,
|
||||
// user may choose to simply quit the app from the dialog presented
|
||||
|
@ -2229,7 +2250,7 @@ nsProfile::MigrateProfileInternal(const PRUnichar* profileName,
|
|||
mOutofDiskSpace = PR_TRUE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
else if (errorCode != SUCCESS)
|
||||
else if (errorCode != MIGRATION_SUCCESS)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@ private:
|
|||
|
||||
nsString mCurrentProfileName;
|
||||
PRBool mCurrentProfileAvailable;
|
||||
nsProfileLock mCurrentProfileLock;
|
||||
|
||||
PRBool mIsUILocaleSpecified;
|
||||
nsString mUILocaleName;
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -29,6 +29,9 @@
|
|||
#include "nsIFile.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
class ProfileStruct
|
||||
{
|
||||
|
@ -165,5 +168,43 @@ private:
|
|||
nsresult ResetProfileMembers();
|
||||
};
|
||||
|
||||
|
||||
#include "prclist.h"
|
||||
|
||||
class nsProfileLock
|
||||
#if defined (XP_UNIX)
|
||||
: public PRCList
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
nsProfileLock();
|
||||
nsProfileLock(nsProfileLock& src);
|
||||
|
||||
~nsProfileLock();
|
||||
|
||||
nsProfileLock& operator=(nsProfileLock& rhs);
|
||||
|
||||
nsresult Lock(nsILocalFile* aFile);
|
||||
nsresult Unlock();
|
||||
|
||||
private:
|
||||
PRPackedBool mHaveLock;
|
||||
|
||||
#if defined (XP_MAC)
|
||||
nsCOMPtr<nsILocalFile> mLockFile;
|
||||
#elif defined (XP_WIN)
|
||||
HANDLE mLockFileHandle;
|
||||
#elif defined (XP_OS2)
|
||||
LHANDLE mLockFileHandle;
|
||||
#elif defined (XP_UNIX)
|
||||
static void RemovePidLockFiles();
|
||||
static void FatalSignalHandler(int signo);
|
||||
static PRCList mPidLockList;
|
||||
char* mPidLockFileName;
|
||||
int mLockFileDesc;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif // __nsProfileAccess_h___
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче