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