Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsXREDirProvider Class Reference

#include <nsXREDirProvider.h>

Inheritance diagram for nsXREDirProvider:
Inheritance graph
[legend]
Collaboration diagram for nsXREDirProvider:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_IMETHOD QueryInterface (REFNSIID aIID, void **aInstancePtr)
 NS_IMETHOD_ (nsrefcnt) AddRef(void)
 NS_IMETHOD_ (nsrefcnt) Release(void)
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
NS_DECL_NSIPROFILESTARTUP 
nsXREDirProvider ()
nsresult Initialize (nsIFile *aXULAppDir)
 ~nsXREDirProvider ()
nsresult SetProfile (nsIFile *aProfileDir, nsIFile *aProfileLocalDir)
void DoShutdown ()
nsresult GetProfileDefaultsDir (nsIFile **aResult)
nsIFileGetAppDir ()
nsresult GetUpdateRootDir (nsIFile **aResult)
 Get the directory under which update directory is created.
nsISimpleEnumerator getFiles (in string prop)
 getFiles
nsIFile getFile (in string prop, out PRBool persistent)
 getFile
void doStartup ()
 Do profile-startup by setting NS_APP_USER_PROFILE_50_DIR in the directory service and notifying the profile-startup observer topics.

Static Public Member Functions

static nsresult GetUserAppDataDirectory (nsILocalFile **aFile)
static nsresult GetUserLocalDataDirectory (nsILocalFile **aFile)

Public Attributes

readonly attribute nsIFile directory
 The root directory of the semi-current profile, during profile migration.

Protected Member Functions

void EnsureProfileFileExists (nsIFile *aFile)

Static Protected Member Functions

static nsresult GetUserDataDirectory (nsILocalFile **aFile, PRBool aLocal)
static nsresult EnsureDirectoryExists (nsIFile *aDirectory)

Protected Attributes

nsCOMPtr< nsILocalFilemAppDir
nsCOMPtr< nsIFilemXULAppDir
nsCOMPtr< nsIFilemProfileDir
nsCOMPtr< nsIFilemProfileLocalDir
PRBool mProfileNotified

Detailed Description

Definition at line 46 of file nsXREDirProvider.h.


Constructor & Destructor Documentation

Definition at line 102 of file nsXREDirProvider.cpp.

Definition at line 108 of file nsXREDirProvider.cpp.


Member Function Documentation

Definition at line 662 of file nsXREDirProvider.cpp.

{
  if (mProfileNotified) {
    nsCOMPtr<nsIObserverService> obssvc
      (do_GetService("@mozilla.org/observer-service;1"));
    NS_ASSERTION(obssvc, "No observer service?");
    if (obssvc) {
      nsCOMPtr<nsIProfileChangeStatus> cs = new ProfileChangeStatusImpl();
      static const PRUnichar kShutdownPersist[] =
        {'s','h','u','t','d','o','w','n','-','p','e','r','s','i','s','t','\0'};
      obssvc->NotifyObservers(cs, "profile-change-net-teardown", kShutdownPersist);
      obssvc->NotifyObservers(cs, "profile-change-teardown", kShutdownPersist);

      // Phase 2c: Now that things are torn down, force JS GC so that things which depend on
      // resources which are about to go away in "profile-before-change" are destroyed first.
      nsCOMPtr<nsIThreadJSContextStack> stack
        (do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
      if (stack)
      {
        JSContext *cx = nsnull;
        stack->GetSafeJSContext(&cx);
        if (cx)
          ::JS_GC(cx);
      }

      // Phase 3: Notify observers of a profile change
      obssvc->NotifyObservers(cs, "profile-before-change", kShutdownPersist);
    }
    mProfileNotified = PR_FALSE;
  }
}

Here is the call graph for this function:

Do profile-startup by setting NS_APP_USER_PROFILE_50_DIR in the directory service and notifying the profile-startup observer topics.

nsresult nsXREDirProvider::EnsureDirectoryExists ( nsIFile aDirectory) [static, protected]

Definition at line 955 of file nsXREDirProvider.cpp.

{
  PRBool exists;
  nsresult rv = aDirectory->Exists(&exists);
  NS_ENSURE_SUCCESS(rv, rv);
#ifdef DEBUG_jungshik
  if (!exists) {
    nsCAutoString cwd;
    aDirectory->GetNativePath(cwd);
    printf("nsXREDirProvider::EnsureDirectoryExists: %s does not\n", cwd.get());
  }
#endif
  if (!exists)
    rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700);
#ifdef DEBUG_jungshik
  if (NS_FAILED(rv))
    NS_WARNING("nsXREDirProvider::EnsureDirectoryExists: create failed");
#endif

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 978 of file nsXREDirProvider.cpp.

{
  nsresult rv;
  PRBool exists;
    
  rv = aFile->Exists(&exists);
  if (NS_FAILED(rv) || exists) return;
  
  nsCAutoString leafName;
  rv = aFile->GetNativeLeafName(leafName);
  if (NS_FAILED(rv)) return;

  nsCOMPtr<nsIFile> defaultsFile;
  rv = GetProfileDefaultsDir(getter_AddRefs(defaultsFile));
  if (NS_FAILED(rv)) return;

  rv = defaultsFile->AppendNative(leafName);
  if (NS_FAILED(rv)) return;
  
  defaultsFile->CopyToNative(mProfileDir, EmptyCString());
}

Here is the call graph for this function:

Definition at line 81 of file nsXREDirProvider.h.

{ return mAppDir; }

Here is the caller graph for this function:

nsIFile nsIDirectoryServiceProvider::getFile ( in string  prop,
out PRBool  persistent 
) [inherited]

getFile

Directory Service calls this when it gets the first request for a prop or on every request if the prop is not persistent.

Parameters:
propThe symbolic name of the file.
persistentTRUE - The returned file will be cached by Directory Service. Subsequent requests for this prop will bypass the provider and use the cache. FALSE - The provider will be asked for this prop each time it is requested.
Returns:
The file represented by the property.

getFiles

Directory Service calls this when it gets a request for a prop and the requested type is nsISimpleEnumerator.

Parameters:
propThe symbolic name of the file list.
Returns:
An enumerator for a list of file locations. The elements in the enumeration are nsIFile NS_SUCCESS_AGGREGATE_RESULT if this result should be aggregated with other "lower" providers.

Definition at line 1001 of file nsXREDirProvider.cpp.

{
  NS_ASSERTION(mAppDir, "nsXREDirProvider not initialized.");
  NS_PRECONDITION(aResult, "Null out-param");

  nsresult rv;
  nsCOMPtr<nsIFile> defaultsDir;

  rv = mAppDir->Clone(getter_AddRefs(defaultsDir));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = defaultsDir->AppendNative(NS_LITERAL_CSTRING("defaults"));
  rv |= defaultsDir->AppendNative(NS_LITERAL_CSTRING("profile"));
  NS_ENSURE_SUCCESS(rv, rv);

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

Here is the call graph for this function:

Here is the caller graph for this function:

Get the directory under which update directory is created.

This method may be called before XPCOM is started. aResult is a clone, it may be modified.

static nsresult nsXREDirProvider::GetUserAppDataDirectory ( nsILocalFile **  aFile) [inline, static]

Definition at line 73 of file nsXREDirProvider.h.

                                                                {
    return GetUserDataDirectory(aFile, PR_FALSE);
  }

Here is the call graph for this function:

nsresult nsXREDirProvider::GetUserDataDirectory ( nsILocalFile **  aFile,
PRBool  aLocal 
) [static, protected]

Definition at line 791 of file nsXREDirProvider.cpp.

{
  NS_ASSERTION(gAppData, "gAppData not initialized!");

  // Copied from nsAppFileLocationProvider (more or less)
  nsresult rv;
  nsCOMPtr<nsILocalFile> localDir;

#if defined(XP_MACOSX)
  FSRef fsRef;
  OSType folderType;
  if (aLocal) {
    folderType = kCachedDataFolderType;
  } else {
#ifdef MOZ_THUNDERBIRD 
    folderType = kDomainLibraryFolderType;
#else
    folderType = kApplicationSupportFolderType;
#endif 
  }
  OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
  NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);

  rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(localDir));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
  NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED);

  rv = dirFileMac->InitWithFSRef(&fsRef);
  NS_ENSURE_SUCCESS(rv, rv);

  // Note that MacOS ignores the vendor when creating the profile hierarchy - all
  // application preferences directories live alongside one another in 
  // ~/Library/Application Support/
  rv = dirFileMac->AppendNative(nsDependentCString(gAppData->name));
  NS_ENSURE_SUCCESS(rv, rv);
#elif defined(XP_WIN)
  char path[MAXPATHLEN];

  // CSIDL_LOCAL_APPDATA is only defined on newer versions of Windows.  If the
  // OS does not understand it, then we'll fallback to the regular APPDATA
  // location.  If neither is defined, then we fallback to the Windows folder.

  if (aLocal)
    rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path);
  if (!aLocal || NS_FAILED(rv))
    rv = GetShellFolderPath(CSIDL_APPDATA, path);

  if (NS_FAILED(rv) && !GetWindowsDirectory(path, sizeof(path))) {
    NS_WARNING("Aaah, no windows directory!");
    return NS_ERROR_FAILURE;
  }

  rv = NS_NewNativeLocalFile(nsDependentCString(path),
                             PR_TRUE, getter_AddRefs(localDir));
  NS_ENSURE_SUCCESS(rv, rv);

  if (gAppData->vendor) {
    rv = localDir->AppendNative(nsDependentCString(gAppData->vendor));
    NS_ENSURE_SUCCESS(rv, rv);
  }
  rv = localDir->AppendNative(nsDependentCString(gAppData->name));
  NS_ENSURE_SUCCESS(rv, rv);

#elif defined(XP_OS2)
#if 0 /* For OS/2 we want to always use MOZILLA_HOME */
  // we want an environment variable of the form
  // FIREFOX_HOME, etc
  nsDependentCString envVar(nsDependentCString(gAppData->name));
  envVar.Append("_HOME");
  char *pHome = getenv(envVar.get());
#endif
  char *pHome = getenv("MOZILLA_HOME");
  if (pHome && *pHome) {
    rv = NS_NewNativeLocalFile(nsDependentCString(pHome), PR_TRUE,
                               getter_AddRefs(localDir));
  } else {
    PPIB ppib;
    PTIB ptib;
    char appDir[CCHMAXPATH];

    DosGetInfoBlocks(&ptib, &ppib);
    DosQueryModuleName(ppib->pib_hmte, CCHMAXPATH, appDir);
    *strrchr(appDir, '\\') = '\0';
    rv = NS_NewNativeLocalFile(nsDependentCString(appDir), PR_TRUE, getter_AddRefs(localDir));
  }
  NS_ENSURE_SUCCESS(rv, rv);

  if (gAppData->vendor) {
    rv = localDir->AppendNative(nsDependentCString(gAppData->vendor));
    NS_ENSURE_SUCCESS(rv, rv);
  }
  rv = localDir->AppendNative(nsDependentCString(gAppData->name));
  NS_ENSURE_SUCCESS(rv, rv);

#elif defined(XP_BEOS)
  char appDir[MAXPATHLEN];
  if (find_directory(B_USER_SETTINGS_DIRECTORY, NULL, true, appDir, MAXPATHLEN))
    return NS_ERROR_FAILURE;

  int len = strlen(appDir);
  appDir[len]   = '/';
  appDir[len+1] = '\0';

  rv = NS_NewNativeLocalFile(nsDependentCString(appDir), PR_TRUE,
                             getter_AddRefs(localDir));
  NS_ENSURE_SUCCESS(rv, rv);

  if (gAppData->vendor) {
    rv = localDir->AppendNative(nsDependentCString(gAppData->vendor));
    NS_ENSURE_SUCCESS(rv, rv);
  }
  rv = localDir->AppendNative(nsDependentCString(gAppData->name));
  NS_ENSURE_SUCCESS(rv, rv);

#elif defined(XP_UNIX)
  const char* homeDir = getenv("HOME");
  if (!homeDir || !*homeDir)
    return NS_ERROR_FAILURE;

  rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), PR_TRUE,
                             getter_AddRefs(localDir));
  NS_ENSURE_SUCCESS(rv, rv);
 
  char* appNameFolder = nsnull;
  char profileFolderName[MAXPATHLEN] = ".";
 
  // Offset 1 for the outermost folder to make it hidden (i.e. using the ".")
  char* writing = profileFolderName + 1;
  if (gAppData->vendor) {
    GetProfileFolderName(writing, gAppData->vendor);
    
    rv = localDir->AppendNative(nsDependentCString(profileFolderName));
    NS_ENSURE_SUCCESS(rv, rv);
 
    char temp[MAXPATHLEN];
    GetProfileFolderName(temp, gAppData->name);
    appNameFolder = temp;
  }
  else {
    GetProfileFolderName(writing, gAppData->name);
    appNameFolder = profileFolderName;
  }
  rv = localDir->AppendNative(nsDependentCString(appNameFolder));
  NS_ENSURE_SUCCESS(rv, rv);
#else
#error dont_know_how_to_get_product_dir_on_your_platform
#endif

#ifdef DEBUG_jungshik
  nsCAutoString cwd;
  localDir->GetNativePath(cwd);
  printf("nsXREDirProvider::GetUserDataDirectory: %s\n", cwd.get());
#endif
  rv = EnsureDirectoryExists(localDir);
  NS_ENSURE_SUCCESS(rv, rv);

  *aFile = localDir;
  NS_ADDREF(*aFile);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsXREDirProvider::GetUserLocalDataDirectory ( nsILocalFile **  aFile) [inline, static]

Definition at line 76 of file nsXREDirProvider.h.

                                                                  {
    return GetUserDataDirectory(aFile, PR_TRUE);
  }

Here is the call graph for this function:

Definition at line 114 of file nsXREDirProvider.cpp.

{ 
  mXULAppDir = aXULAppDir;

  nsCOMPtr<nsILocalFile> lf;
  nsresult rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIFile> appDir;
  rv = lf->GetParent(getter_AddRefs(appDir));
  if (NS_FAILED(rv))
    return rv;

  mAppDir = do_QueryInterface(appDir);
  if (!mAppDir)
    return NS_ERROR_FAILURE;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHOD nsXREDirProvider::QueryInterface ( REFNSIID  aIID,
void **  aInstancePtr 
)
nsresult nsXREDirProvider::SetProfile ( nsIFile aProfileDir,
nsIFile aProfileLocalDir 
)

Definition at line 136 of file nsXREDirProvider.cpp.

{
  NS_ASSERTION(aDir && aLocalDir, "We don't support no-profile apps yet!");

  nsresult rv;
  
  rv = EnsureDirectoryExists(aDir);
  if (NS_FAILED(rv))
    return rv;

  rv = EnsureDirectoryExists(aLocalDir);
  if (NS_FAILED(rv))
    return rv;

  mProfileDir = aDir;
  mProfileLocalDir = aLocalDir;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

The root directory of the semi-current profile, during profile migration.

After nsIProfileMigrator.migrate has returned, this object will not be useful.

Definition at line 56 of file nsIProfileMigrator.idl.

Definition at line 95 of file nsXREDirProvider.h.

Definition at line 97 of file nsXREDirProvider.h.

Definition at line 98 of file nsXREDirProvider.h.

Definition at line 99 of file nsXREDirProvider.h.

Definition at line 96 of file nsXREDirProvider.h.


The documentation for this class was generated from the following files: