Bug 759416 - XPCOM FileWatcherService. Interface and stub impl. r=dougt

This commit is contained in:
Doug Turner 2012-08-01 23:29:34 -07:00
Родитель 4893263a15
Коммит c75d9afe6d
2 изменённых файлов: 73 добавлений и 2 удалений

Просмотреть файл

@ -16,6 +16,7 @@
[ptr] native FILE(FILE); [ptr] native FILE(FILE);
interface nsISimpleEnumerator; interface nsISimpleEnumerator;
interface nsIFileUpdateListener;
/** /**
* This is the only correct cross-platform way to specify a file. * This is the only correct cross-platform way to specify a file.
@ -30,7 +31,7 @@ interface nsISimpleEnumerator;
* be safely passed to javascript via xpconnect. Therefore, the "native * be safely passed to javascript via xpconnect. Therefore, the "native
* methods" are not scriptable. * methods" are not scriptable.
*/ */
[scriptable, uuid(272a5020-64f5-485c-a8c4-44b2882ae0a2), builtinclass] [scriptable, uuid(9117c043-c01b-487a-a7ad-32cb350b0971), builtinclass]
interface nsIFile : nsISupports interface nsIFile : nsISupports
{ {
/** /**
@ -447,6 +448,62 @@ interface nsIFile : nsISupports
* the relative descriptor obtained from getRelativeDescriptor * the relative descriptor obtained from getRelativeDescriptor
*/ */
void setRelativeDescriptor(in nsIFile fromFile, in ACString relativeDesc); void setRelativeDescriptor(in nsIFile fromFile, in ACString relativeDesc);
/**
* watch
*
* Watches this file for changes, or if this nsIFile is a
* directory, watch for changes in its children recursively, not
* dereferencing symlinks. Multiple listeners can be installed
* at once, and all will be called when any appropriate changes
* are made. If a child directory is created, that directory
* will automatically be watched. If the file is a symlink to a
* directory or another file, the target will be watched for
* changes, not the link.
*
* @param listener
* The listener to call out to when the file updates.
* Updated will be recieved on the main thread.
*
* @return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST if the file
* doesn't exist, NS_NOT_AVAILABLE if there is an
* out-of-memory or other resource failure, NS_OK
* otherwise.
*/
void watch(in nsIFileUpdateListener listener);
/**
*
* unwatch
*
* Removes the watch using the given listener from the file.
* After this function terminates, no more requests will call the
* given listener.
*
* @param listener
* the listener to stop calling out to
*
* @return NS_ERROR_ILLEGAL_VALUE if the file is not being
* watched with the given listener, NS_OK otherwise.
*/
void unwatch(in nsIFileUpdateListener listener);
};
[scriptable, uuid(8968aaba-0f95-436c-8baf-7092ccaa814c), function]
interface nsIFileUpdateListener : nsISupports
{
/**
* update
*
* This function will be called whenever there is an update to be
* processed.
*
* @param type
* The type of update that occured (one of "created" "deleted" "modified" or "unknown").
* @param file
* The file which has updated
*/
void update(in string type, in nsIFile file);
}; };
%{C++ %{C++

Просмотреть файл

@ -13,12 +13,12 @@
#include "nsCRT.h" #include "nsCRT.h"
#include "nsNativeCharsetUtils.h" #include "nsNativeCharsetUtils.h"
#include "nsUTF8Utils.h" #include "nsUTF8Utils.h"
#include "nsThreadUtils.h"
#ifdef XP_WIN #ifdef XP_WIN
#include <string.h> #include <string.h>
#endif #endif
void NS_StartupLocalFile() void NS_StartupLocalFile()
{ {
nsLocalFile::GlobalInit(); nsLocalFile::GlobalInit();
@ -288,3 +288,17 @@ nsLocalFile::SetRelativeDescriptor(nsIFile *fromFile, const nsACString& relative
return InitWithFile(targetFile); return InitWithFile(targetFile);
} }
NS_IMETHODIMP
nsLocalFile::Watch(nsIFileUpdateListener *listener)
{
NS_ASSERTION(NS_IsMainThread(), "Watch must be called from main thread!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsLocalFile::Unwatch(nsIFileUpdateListener *listener)
{
NS_ASSERTION(NS_IsMainThread(), "Unwatch must be called from main thread!");
return NS_ERROR_NOT_IMPLEMENTED;
}