50 #include <sbFileUtils.h>
53 #include <nsComponentManagerUtils.h>
54 #include <nsDirectoryServiceUtils.h>
55 #include <nsDirectoryServiceDefs.h>
82 const nsAString& aBaseName,
83 const nsAString& aExtension,
87 return mRootTemporaryFileFactory->CreateFile(aType,
104 sbTemporaryFileService::GetRootTemporaryDirectory
105 (nsIFile** aRootTemporaryDirectory)
107 NS_ENSURE_STATE(mInitialized);
108 return mRootTemporaryFileFactory->GetRootTemporaryDirectory
109 (aRootTemporaryDirectory);
125 sbTemporaryFileService::Observe(
nsISupports* aSubject,
127 const PRUnichar*
aData)
132 if (!strcmp(aTopic,
"app-startup")) {
135 NS_ENSURE_SUCCESS(rv, rv);
137 else if (!strcmp(aTopic,
"profile-after-change")) {
139 mProfileAvailable = PR_TRUE;
143 NS_ENSURE_SUCCESS(rv, rv);
145 else if (!strcmp(aTopic,
"quit-application")) {
167 mProfileAvailable(PR_FALSE)
195 if (!mObserverService) {
196 mObserverService = do_GetService(
"@mozilla.org/observer-service;1", &rv);
197 NS_ENSURE_SUCCESS(rv, rv);
198 rv = mObserverService->AddObserver(
this,
"profile-after-change", PR_FALSE);
199 NS_ENSURE_SUCCESS(rv, rv);
200 rv = mObserverService->AddObserver(
this,
"quit-application", PR_FALSE);
201 NS_ENSURE_SUCCESS(rv, rv);
205 if (!mProfileAvailable)
211 getter_AddRefs(rootTemporaryDirectory));
212 NS_ENSURE_SUCCESS(rv, rv);
216 rv = rootTemporaryDirectory->Append
218 NS_ENSURE_SUCCESS(rv, rv);
219 rv = rootTemporaryDirectory->Exists(&exists);
220 NS_ENSURE_SUCCESS(rv, rv);
222 rv = rootTemporaryDirectory->Create(nsIFile::DIRECTORY_TYPE,
224 NS_ENSURE_SUCCESS(rv, rv);
228 mRootTemporaryFileFactory =
229 do_CreateInstance(
"@songbirdnest.com/Songbird/TemporaryFileFactory;1", &rv);
230 NS_ENSURE_SUCCESS(rv, rv);
231 rv = mRootTemporaryFileFactory->SetRootTemporaryDirectory
232 (rootTemporaryDirectory);
233 NS_ENSURE_SUCCESS(rv, rv);
236 mInitialized = PR_TRUE;
251 mInitialized = PR_FALSE;
254 if (mObserverService) {
255 mObserverService->RemoveObserver(
this,
"profile-after-change");
256 mObserverService->RemoveObserver(
this,
"quit-application");
258 mObserverService = nsnull;
261 mRootTemporaryFileFactory = nsnull;
NS_IMPL_THREADSAFE_ISUPPORTS2(sbTemporaryFileService, sbITemporaryFileService, nsIObserver) NS_IMETHODIMP sbTemporaryFileService
NS_DECL_ISUPPORTS NS_DECL_SBITEMPORARYFILESERVICE NS_DECL_NSIOBSERVER sbTemporaryFileService()
readonly attribute nsIFile rootTemporaryDirectory
Root directory of temporary files and directories.
virtual ~sbTemporaryFileService()
#define SB_TEMPORARY_FILE_SERVICE_ROOT_DIR_NAME
Songbird Temporary File Service Definitions.
#define SB_DEFAULT_DIRECTORY_PERMISSIONS
_updateTextAndScrollDataForFrame aData