29 #include <nsIUUIDGenerator.h>
30 #include <nsComponentManagerUtils.h>
31 #include <nsServiceManagerUtils.h>
46 mIsRecursive = PR_TRUE;
47 mIsWatching = PR_FALSE;
48 mIsSupported = PR_TRUE;
49 mShouldLoadSession = PR_FALSE;
57 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Error could not clear tree listener!");
66 const nsAString & aRootPath,
69 NS_ENSURE_ARG_POINTER(aListener);
71 TRACE(
"%s: initing, will watch [%s]",
73 NS_ConvertUTF16toUTF8(aRootPath).
get());
83 nsCOMPtr<nsIUUIDGenerator> uuidGen =
84 do_GetService(
"@mozilla.org/uuid-generator;1", &rv);
85 NS_ENSURE_SUCCESS(rv, rv);
87 rv = uuidGen->GenerateUUIDInPlace(&
mSessionID);
88 NS_ENSURE_SUCCESS(rv, rv);
94 sbBaseFileSystemWatcher::InitWithSession(
const nsACString & aSessionGuid,
97 NS_ENSURE_ARG_POINTER(aListener);
102 if (!
mSessionID.Parse(nsCString(aSessionGuid).
get())) {
103 return NS_ERROR_FAILURE;
112 sbBaseFileSystemWatcher::StartWatching()
115 return NS_ERROR_NOT_IMPLEMENTED;
122 TRACE(
"%s: starting to watch [%s]",
128 NS_ENSURE_TRUE(
mTree, NS_ERROR_OUT_OF_MEMORY);
131 nsresult rv =
mTree->SetListener(
this);
132 NS_ENSURE_SUCCESS(rv, rv);
138 NS_ENSURE_SUCCESS(rv, rv);
142 NS_ENSURE_SUCCESS(rv, rv);
149 sbBaseFileSystemWatcher::StopWatching(PRBool aShouldSaveSession)
151 nsRefPtr<sbBaseFileSystemWatcher> kungFuDeathGrip(
this);
157 if (aShouldSaveSession) {
159 NS_ENSURE_SUCCESS(rv, rv);
166 sbBaseFileSystemWatcher::DeleteSession(
const nsACString & aSessionGuid)
169 if (!sessionID.Parse(nsCString(aSessionGuid).
get())) {
170 return NS_ERROR_FAILURE;
174 NS_ENSURE_SUCCESS(rv, rv);
180 sbBaseFileSystemWatcher::GetIsWatching(PRBool *aIsWatching)
182 NS_ENSURE_ARG_POINTER(aIsWatching);
188 sbBaseFileSystemWatcher::GetWatchPath(nsAString & aWatchPath)
195 sbBaseFileSystemWatcher::GetSessionGuid(nsACString & aSessionGuid)
197 char idChars[NSID_LENGTH];
199 aSessionGuid.Assign(idChars);
204 sbBaseFileSystemWatcher::GetIsSupported(PRBool *aIsSupported)
206 NS_ENSURE_ARG_POINTER(aIsSupported);
220 TRACE(
"%s: Found change in %s of type %s",
222 NS_ConvertUTF16toUTF8(aChangePath).
get(),
223 (aChangeType ==
eChanged) ?
"change" :
224 (aChangeType ==
eAdded) ?
"add" :
225 (aChangeType ==
eRemoved) ?
"removed" :
227 switch (aChangeType) {
229 rv =
mListener->OnFileSystemChanged(aChangePath);
232 rv =
mListener->OnFileSystemAdded(aChangePath);
235 rv =
mListener->OnFileSystemRemoved(aChangePath);
238 rv = NS_ERROR_UNEXPECTED;
250 return NS_ERROR_NOT_IMPLEMENTED;
262 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
263 "Could not notify listener of OnWatcherError()!");
265 return StopWatching(PR_FALSE);
271 char idChars[NSID_LENGTH];
273 nsString sessionString;
274 sessionString.Append(NS_ConvertASCIItoUTF16(idChars));
nsCOMPtr< sbIFileSystemListener > mListener
#define SB_PRLOG_SETUP(x)
nsTArray< nsString > sbStringArray
NS_DECL_ISUPPORTS NS_DECL_SBIFILESYSTEMWATCHER NS_IMETHOD OnChangeFound(const nsAString &aChangePath, EChangeType aChangeType)
NS_IMETHOD OnTreeSessionLoadError()
virtual ~sbBaseFileSystemWatcher()
static nsresult DeleteSavedTreeState(const nsID &aSessionID)
nsRefPtr< sbFileSystemTree > mTree
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceCapsCompatibility, sbIDeviceCapsCompatibility) sbDeviceCapsCompatibility
NS_IMETHOD OnRootPathMissing()
const unsigned long ROOT_PATH_MISSING
NS_IMETHOD OnTreeReady(const nsAString &aTreeRootPath, sbStringArray &aDirPathArray)
const unsigned long SESSION_LOAD_ERROR
#define SB_UNUSED_IN_RELEASE(decl)
PRBool mShouldLoadSession