50 #include <sbFileUtils.h>
51 #include <sbITemporaryFileService.h>
55 #include <nsServiceManagerUtils.h>
80 const nsAString& aBaseName,
81 const nsAString& aExtension,
85 NS_ENSURE_ARG_POINTER(_retval);
91 rv = EnsureRootTemporaryDirectory();
92 NS_ENSURE_SUCCESS(rv, rv);
95 nsCOMPtr<nsIFile>
file;
96 rv = mRootTemporaryDirectory->Clone(getter_AddRefs(file));
97 NS_ENSURE_SUCCESS(rv, rv);
101 nsAutoString fileName;
102 if (!aBaseName.IsEmpty()) {
103 fileName.Assign(aBaseName);
106 fileName.Assign(NS_LITERAL_STRING(
"tmp"));
109 if (!aExtension.IsEmpty()) {
110 fileName.Append(NS_LITERAL_STRING(
"."));
111 fileName.Append(aExtension);
113 rv = file->Append(fileName);
114 NS_ENSURE_SUCCESS(rv, rv);
117 PRUint32 permissions;
118 if (aType == nsIFile::DIRECTORY_TYPE)
124 rv = file->CreateUnique(aType, permissions);
125 NS_ENSURE_SUCCESS(rv, rv);
128 file.forget(_retval);
135 sbTemporaryFileFactory::Clear()
138 if (mRootTemporaryDirectory)
139 mRootTemporaryDirectory->Remove(PR_TRUE);
140 mRootTemporaryDirectory = nsnull;
156 sbTemporaryFileFactory::SetRootTemporaryDirectory
157 (nsIFile* aRootTemporaryDirectory)
159 mRootTemporaryDirectory = aRootTemporaryDirectory;
164 sbTemporaryFileFactory::GetRootTemporaryDirectory
165 (nsIFile** aRootTemporaryDirectory)
167 NS_ENSURE_ARG_POINTER(aRootTemporaryDirectory);
168 nsresult rv = EnsureRootTemporaryDirectory();
169 NS_ENSURE_SUCCESS(rv, rv);
170 NS_ADDREF(*aRootTemporaryDirectory = mRootTemporaryDirectory);
215 sbTemporaryFileFactory::EnsureRootTemporaryDirectory()
220 if (!mRootTemporaryDirectory) {
222 nsCOMPtr<sbITemporaryFileService>
223 temporaryFileService =
224 do_GetService(
"@songbirdnest.com/Songbird/TemporaryFileService;1", &rv);
225 NS_ENSURE_SUCCESS(rv, rv);
228 rv = temporaryFileService->CreateFile
229 (nsIFile::DIRECTORY_TYPE,
232 getter_AddRefs(mRootTemporaryDirectory));
233 NS_ENSURE_SUCCESS(rv, rv);
#define SB_DEFAULT_FILE_PERMISSIONS
virtual ~sbTemporaryFileFactory()
NS_DECL_ISUPPORTS NS_DECL_SBITEMPORARYFILEFACTORY sbTemporaryFileFactory()
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceCapsCompatibility, sbIDeviceCapsCompatibility) sbDeviceCapsCompatibility
Songbird Temporary File Factory Definitions.
#define SB_DEFAULT_DIRECTORY_PERMISSIONS