Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsToolkitProfileService.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include "nsProfileLock.h"
#include "nsIToolkitProfileService.h"
#include "nsIToolkitProfile.h"
#include "nsIFactory.h"
#include "nsILocalFile.h"
#include "nsISimpleEnumerator.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsXULAppAPI.h"
#include "nsINIParser.h"
#include "nsXREDirProvider.h"
#include "nsAppRunner.h"
#include "nsString.h"
#include "nsReadableUtils.h"

Go to the source code of this file.

Classes

class  nsToolkitProfile
class  nsToolkitProfileLock
class  nsToolkitProfileService
class  nsToolkitProfileService::ProfileEnumerator

Functions

 NS_IMPL_ISUPPORTS2 (nsToolkitProfileService, nsIToolkitProfileService, nsIFactory) nsresult nsToolkitProfileService
 NS_IMPL_ISUPPORTS1 (nsToolkitProfileService::ProfileEnumerator, nsISimpleEnumerator) NS_IMETHODIMP nsToolkitProfileService
nsresult NS_LockProfilePath (nsILocalFile *aPath, nsILocalFile *aTempPath, nsIProfileUnlocker **aUnlocker, nsIProfileLock **aResult)
 Try to acquire exclusive access to the specified profile directory.
static void SaltProfileName (nsACString &aName)
nsresult NS_NewToolkitProfileService (nsIToolkitProfileService **aResult)
nsresult XRE_GetFileFromPath (const char *aPath, nsILocalFile **aResult)
 Given a path relative to the current working directory (or an absolute path), return an appropriate nsILocalFile object.

Variables

static const char kTable []

Function Documentation

Definition at line 520 of file nsToolkitProfileService.cpp.

{
    *aResult = mCurrent ? PR_TRUE : PR_FALSE;
    return NS_OK;
}

Definition at line 372 of file nsToolkitProfileService.cpp.

{
    NS_ASSERTION(gDirServiceProvider, "No dirserviceprovider!");
    nsresult rv;

    rv = gDirServiceProvider->GetUserAppDataDirectory(getter_AddRefs(mAppData));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = gDirServiceProvider->GetUserLocalDataDirectory(getter_AddRefs(mTempData));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIFile> listFile;
    rv = mAppData->Clone(getter_AddRefs(listFile));
    NS_ENSURE_SUCCESS(rv, rv);

    mListFile = do_QueryInterface(listFile);
    NS_ENSURE_TRUE(listFile, NS_ERROR_NO_INTERFACE);

    rv = mListFile->AppendNative(NS_LITERAL_CSTRING("profiles.ini"));
    NS_ENSURE_SUCCESS(rv, rv);

    PRBool exists;
    rv = mListFile->IsFile(&exists);
    if (NS_FAILED(rv) || !exists) {
        return NS_OK;
    }

    nsINIParser parser;
    rv = parser.Init(mListFile);
    // Init does not fail on parsing errors, only on OOM/really unexpected
    // conditions.
    if (NS_FAILED(rv))
        return rv;

    nsCAutoString buffer;
    rv = parser.GetString("General", "StartWithLastProfile", buffer);
    if (NS_SUCCEEDED(rv) && buffer.EqualsLiteral("0"))
        mStartWithLast = PR_FALSE;

    nsToolkitProfile* currentProfile = nsnull;

    unsigned int c = 0;
    for (c = 0; PR_TRUE; ++c) {
        nsCAutoString profileID("Profile");
        profileID.AppendInt(c);

        rv = parser.GetString(profileID.get(), "IsRelative", buffer);
        if (NS_FAILED(rv)) break;

        PRBool isRelative = buffer.EqualsLiteral("1");

        nsCAutoString filePath;

        rv = parser.GetString(profileID.get(), "Path", filePath);
        if (NS_FAILED(rv)) {
            NS_ERROR("Malformed profiles.ini: Path= not found");
            continue;
        }

        rv = parser.GetString(profileID.get(), "Name", buffer);
        if (NS_FAILED(rv)) {
            NS_ERROR("Malformed profiles.ini: Name= not found");
            continue;
        }

        nsCOMPtr<nsILocalFile> rootDir;
        rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE,
                                   getter_AddRefs(rootDir));
        NS_ENSURE_SUCCESS(rv, rv);

        if (isRelative) {
            rv = rootDir->SetRelativeDescriptor(mAppData, filePath);
        } else {
            rv = rootDir->SetPersistentDescriptor(filePath);
        }
        if (NS_FAILED(rv)) continue;

        nsCOMPtr<nsILocalFile> localDir;
        if (isRelative) {
            rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE,
                                       getter_AddRefs(localDir));
            NS_ENSURE_SUCCESS(rv, rv);

            rv = localDir->SetRelativeDescriptor(mTempData, filePath);
        } else {
            localDir = rootDir;
        }

        currentProfile = new nsToolkitProfile(buffer,
                                              rootDir, localDir,
                                              currentProfile);
        NS_ENSURE_TRUE(currentProfile, NS_ERROR_OUT_OF_MEMORY);

        rv = parser.GetString(profileID.get(), "Default", buffer);
        if (NS_SUCCEEDED(rv) && buffer.EqualsLiteral("1"))
            mChosen = currentProfile;
    }

    return NS_OK;
}

Here is the call graph for this function:

nsresult NS_LockProfilePath ( nsILocalFile aPath,
nsILocalFile aTempPath,
nsIProfileUnlocker **  aUnlocker,
nsIProfileLock **  aResult 
)

Try to acquire exclusive access to the specified profile directory.

Parameters:
aPathThe profile directory to lock.
aTempPathThe corresponding profile temporary directory.
aUnlockerA callback interface used to attempt to unlock a profile that appears to be locked.
aResultThe resulting profile lock object (or null if the profile could not be locked).
Returns:
NS_ERROR_FILE_ACCESS_DENIED to indicate that the profile directory cannot be unlocked.

Definition at line 589 of file nsToolkitProfileService.cpp.

{
    nsCOMPtr<nsToolkitProfileLock> lock = new nsToolkitProfileLock();
    if (!lock) return NS_ERROR_OUT_OF_MEMORY;

    nsresult rv = lock->Init(aPath, aTempPath, aUnlocker);
    if (NS_FAILED(rv)) return rv;

    NS_ADDREF(*aResult = lock);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 847 of file nsToolkitProfileService.cpp.

{
    nsToolkitProfileService* aThis = new nsToolkitProfileService();
    nsresult rv = aThis->Init();
    if (NS_FAILED(rv)) {
        NS_ERROR("nsToolkitProfileService::Init failed!");
        delete aThis;
        return rv;
    }

    NS_ADDREF(*aResult = aThis);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void SaltProfileName ( nsACString &  aName) [static]

Definition at line 607 of file nsToolkitProfileService.cpp.

{
    double fpTime;
    LL_L2D(fpTime, PR_Now());

    // use 1e-6, granularity of PR_Now() on the mac is seconds
    srand((uint)(fpTime * 1e-6 + 0.5));

    char salt[9];

    int i;
    for (i = 0; i < 8; ++i)
        salt[i] = kTable[rand() % NS_ARRAY_LENGTH(kTable)];

    salt[8] = '.';

    aName.Insert(salt, 0, 9);
}

Here is the call graph for this function:

nsresult XRE_GetFileFromPath ( const char *  aPath,
nsILocalFile **  aResult 
)

Given a path relative to the current working directory (or an absolute path), return an appropriate nsILocalFile object.

Definition at line 862 of file nsToolkitProfileService.cpp.

{
#if defined(XP_MACOSX)
    PRInt32 pathLen = strlen(aPath);
    if (pathLen > MAXPATHLEN)
        return NS_ERROR_INVALID_ARG;

    CFURLRef fullPath =
        CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8 *) aPath,
                                                pathLen, true);
    if (!fullPath)
        return NS_ERROR_FAILURE;

    nsCOMPtr<nsILocalFile> lf;
    nsresult rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE,
                                        getter_AddRefs(lf));
    if (NS_SUCCEEDED(rv)) {
        nsCOMPtr<nsILocalFileMac> lfMac = do_QueryInterface(lf, &rv);
        if (NS_SUCCEEDED(rv)) {
            rv = lfMac->InitWithCFURL(fullPath);
            if (NS_SUCCEEDED(rv))
                NS_ADDREF(*aResult = lf);
        }
    }
    CFRelease(fullPath);
    return rv;

#elif defined(XP_UNIX)
    char fullPath[MAXPATHLEN];

    if (!realpath(aPath, fullPath))
        return NS_ERROR_FAILURE;

    return NS_NewNativeLocalFile(nsDependentCString(fullPath), PR_TRUE,
                                 aResult);
#elif defined(XP_OS2)
    char fullPath[MAXPATHLEN];

    if (!realpath(aPath, fullPath))
        return NS_ERROR_FAILURE;

    // realpath on OS/2 returns a unix-ized path, so re-native-ize
    for (char* ptr = strchr(fullPath, '/'); ptr; ptr = strchr(ptr, '/'))
        *ptr = '\\';

    return NS_NewNativeLocalFile(nsDependentCString(fullPath), PR_TRUE,
                                 aResult);

#elif defined(XP_WIN)
    char fullPath[MAXPATHLEN];

    if (!_fullpath(fullPath, aPath, MAXPATHLEN))
        return NS_ERROR_FAILURE;

    return NS_NewNativeLocalFile(nsDependentCString(fullPath), PR_TRUE,
                                 aResult);

#elif defined(XP_BEOS)
    BPath fullPath;
    if (fullPath.SetTo(aPath, NULL, true))
        return NS_ERROR_FAILURE;

    return NS_NewNativeLocalFile(nsDependentCString(fullPath.Leaf()), PR_TRUE,
                                 aResult);

#else
#error Platform-specific logic needed here.
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char kTable[] [static]
Initial value:
    { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
      'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
      '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' }

Definition at line 602 of file nsToolkitProfileService.cpp.