Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // Interfaces Needed |
michael@0 | 7 | #include "nsIDirectoryService.h" |
michael@0 | 8 | #include "nsIFile.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsDirectoryServiceUtils.h" |
michael@0 | 12 | #include "nsComponentManagerUtils.h" |
michael@0 | 13 | #include "nsServiceManagerUtils.h" |
michael@0 | 14 | |
michael@0 | 15 | #ifdef MOZILLA_INTERNAL_API |
michael@0 | 16 | #include "nsString.h" |
michael@0 | 17 | #else |
michael@0 | 18 | #include "nsEmbedString.h" |
michael@0 | 19 | #endif |
michael@0 | 20 | |
michael@0 | 21 | // Forward Declarations |
michael@0 | 22 | class nsProfileLock; |
michael@0 | 23 | |
michael@0 | 24 | // -------------------------------------------------------------------------------------- |
michael@0 | 25 | // nsProfileDirServiceProvider - The nsIDirectoryServiceProvider implementation used for |
michael@0 | 26 | // profile-relative file locations. |
michael@0 | 27 | // -------------------------------------------------------------------------------------- |
michael@0 | 28 | |
michael@0 | 29 | class nsProfileDirServiceProvider: public nsIDirectoryServiceProvider |
michael@0 | 30 | { |
michael@0 | 31 | NS_DECL_ISUPPORTS |
michael@0 | 32 | NS_DECL_NSIDIRECTORYSERVICEPROVIDER |
michael@0 | 33 | |
michael@0 | 34 | friend nsresult NS_NewProfileDirServiceProvider(bool, nsProfileDirServiceProvider**); |
michael@0 | 35 | |
michael@0 | 36 | public: |
michael@0 | 37 | |
michael@0 | 38 | /** |
michael@0 | 39 | * SetProfileDir |
michael@0 | 40 | * |
michael@0 | 41 | * @param aProfileDir The directory containing the profile files. |
michael@0 | 42 | * It does not need to exist before calling this |
michael@0 | 43 | * method. If it does not, it will be created and |
michael@0 | 44 | * defaults will be copied to it. |
michael@0 | 45 | * @param aLocalProfileDir |
michael@0 | 46 | * Directory for local profile data, e.g. Cache. |
michael@0 | 47 | * If null, aProfileDir will be used for this purpose. |
michael@0 | 48 | */ |
michael@0 | 49 | |
michael@0 | 50 | virtual nsresult SetProfileDir(nsIFile* aProfileDir, |
michael@0 | 51 | nsIFile* aLocalProfileDir = nullptr); |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * Register |
michael@0 | 55 | * |
michael@0 | 56 | * Convenience method to register the provider with directory service. |
michael@0 | 57 | * The service holds strong references to registered providers so consumers |
michael@0 | 58 | * don't need to hold a reference to this object after calling Register(). |
michael@0 | 59 | */ |
michael@0 | 60 | |
michael@0 | 61 | virtual nsresult Register(); |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * Shutdown |
michael@0 | 65 | * |
michael@0 | 66 | * This method must be called before shutting down XPCOM if this object |
michael@0 | 67 | * was created with aNotifyObservers == true. If this object was |
michael@0 | 68 | * created with aNotifyObservers == false, this method is a no-op. |
michael@0 | 69 | */ |
michael@0 | 70 | |
michael@0 | 71 | virtual nsresult Shutdown(); |
michael@0 | 72 | |
michael@0 | 73 | protected: |
michael@0 | 74 | nsProfileDirServiceProvider(bool aNotifyObservers = true); |
michael@0 | 75 | virtual ~nsProfileDirServiceProvider(); |
michael@0 | 76 | |
michael@0 | 77 | nsresult Initialize(); |
michael@0 | 78 | nsresult InitProfileDir(nsIFile* profileDir); |
michael@0 | 79 | nsresult InitNonSharedProfileDir(); |
michael@0 | 80 | nsresult EnsureProfileFileExists(nsIFile *aFile, nsIFile *destDir); |
michael@0 | 81 | nsresult UndefineFileLocations(); |
michael@0 | 82 | |
michael@0 | 83 | protected: |
michael@0 | 84 | |
michael@0 | 85 | nsCOMPtr<nsIFile> mProfileDir; |
michael@0 | 86 | nsCOMPtr<nsIFile> mLocalProfileDir; |
michael@0 | 87 | nsProfileLock* mProfileDirLock; |
michael@0 | 88 | bool mNotifyObservers; |
michael@0 | 89 | |
michael@0 | 90 | bool mSharingEnabled; |
michael@0 | 91 | #ifndef MOZILLA_INTERNAL_API |
michael@0 | 92 | nsEmbedString mNonSharedDirName; |
michael@0 | 93 | #else |
michael@0 | 94 | nsString mNonSharedDirName; |
michael@0 | 95 | #endif |
michael@0 | 96 | nsCOMPtr<nsIFile> mNonSharedProfileDir; |
michael@0 | 97 | }; |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | // -------------------------------------------------------------------------------------- |
michael@0 | 101 | |
michael@0 | 102 | /** |
michael@0 | 103 | * Global method to create an instance of nsProfileDirServiceProvider |
michael@0 | 104 | * |
michael@0 | 105 | * @param aNotifyObservers If true, will send out profile startup |
michael@0 | 106 | * notifications when the profile directory is set. |
michael@0 | 107 | * See notifications.txt |
michael@0 | 108 | */ |
michael@0 | 109 | |
michael@0 | 110 | nsresult NS_NewProfileDirServiceProvider(bool aNotifyObservers, |
michael@0 | 111 | nsProfileDirServiceProvider** aProvider); |
michael@0 | 112 |