2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Interfaces Needed
|
|
|
|
#include "nsIDirectoryService.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
#include "nsString.h"
|
|
|
|
#else
|
|
|
|
#include "nsEmbedString.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Forward Declarations
|
|
|
|
class nsProfileLock;
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// nsProfileDirServiceProvider - The nsIDirectoryServiceProvider implementation used for
|
|
|
|
// profile-relative file locations.
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsProfileDirServiceProvider: public nsIDirectoryServiceProvider
|
|
|
|
{
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
friend nsresult NS_NewProfileDirServiceProvider(bool, nsProfileDirServiceProvider**);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetProfileDir
|
|
|
|
*
|
|
|
|
* @param aProfileDir The directory containing the profile files.
|
|
|
|
* It does not need to exist before calling this
|
|
|
|
* method. If it does not, it will be created and
|
|
|
|
* defaults will be copied to it.
|
|
|
|
* @param aLocalProfileDir
|
|
|
|
* Directory for local profile data, e.g. Cache.
|
|
|
|
* If null, aProfileDir will be used for this purpose.
|
|
|
|
*/
|
|
|
|
|
|
|
|
virtual nsresult SetProfileDir(nsIFile* aProfileDir,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFile* aLocalProfileDir = nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register
|
|
|
|
*
|
|
|
|
* Convenience method to register the provider with directory service.
|
|
|
|
* The service holds strong references to registered providers so consumers
|
|
|
|
* don't need to hold a reference to this object after calling Register().
|
|
|
|
*/
|
|
|
|
|
|
|
|
virtual nsresult Register();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown
|
|
|
|
*
|
|
|
|
* This method must be called before shutting down XPCOM if this object
|
2011-10-17 07:59:28 -07:00
|
|
|
* was created with aNotifyObservers == true. If this object was
|
|
|
|
* created with aNotifyObservers == false, this method is a no-op.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
virtual nsresult Shutdown();
|
|
|
|
|
|
|
|
protected:
|
2011-09-28 23:19:26 -07:00
|
|
|
nsProfileDirServiceProvider(bool aNotifyObservers = true);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsProfileDirServiceProvider();
|
|
|
|
|
|
|
|
nsresult Initialize();
|
|
|
|
nsresult InitProfileDir(nsIFile* profileDir);
|
|
|
|
nsresult InitNonSharedProfileDir();
|
|
|
|
nsresult EnsureProfileFileExists(nsIFile *aFile, nsIFile *destDir);
|
|
|
|
nsresult UndefineFileLocations();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> mProfileDir;
|
|
|
|
nsCOMPtr<nsIFile> mLocalProfileDir;
|
|
|
|
nsProfileLock* mProfileDirLock;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mNotifyObservers;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mSharingEnabled;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifndef MOZILLA_INTERNAL_API
|
|
|
|
nsEmbedString mNonSharedDirName;
|
|
|
|
#else
|
|
|
|
nsString mNonSharedDirName;
|
|
|
|
#endif
|
|
|
|
nsCOMPtr<nsIFile> mNonSharedProfileDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Global method to create an instance of nsProfileDirServiceProvider
|
|
|
|
*
|
|
|
|
* @param aNotifyObservers If true, will send out profile startup
|
|
|
|
* notifications when the profile directory is set.
|
2012-12-13 09:20:56 -08:00
|
|
|
* See notifications.txt
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult NS_NewProfileDirServiceProvider(bool aNotifyObservers,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsProfileDirServiceProvider** aProvider);
|
|
|
|
|