Bug 992894 - Add a native file watcher component to notify about file/directory changes (Windows). r=Yoric

This commit is contained in:
Alessio Placitelli 2014-09-02 06:34:00 -04:00
parent e6e294d232
commit 6bc6e16ab4
10 changed files with 1764 additions and 0 deletions

View File

@ -293,6 +293,7 @@
@BINPATH@/components/spellchecker.xpt
@BINPATH@/components/storage.xpt
@BINPATH@/components/telemetry.xpt
@BINPATH@/components/toolkit_filewatcher.xpt
@BINPATH@/components/toolkit_finalizationwitness.xpt
@BINPATH@/components/toolkit_formautofill.xpt
@BINPATH@/components/toolkit_osfile.xpt

View File

@ -300,6 +300,7 @@
@BINPATH@/components/shistory.xpt
@BINPATH@/components/spellchecker.xpt
@BINPATH@/components/storage.xpt
@BINPATH@/components/toolkit_filewatcher.xpt
@BINPATH@/components/toolkit_finalizationwitness.xpt
@BINPATH@/components/toolkit_formautofill.xpt
@BINPATH@/components/toolkit_osfile.xpt

View File

@ -246,6 +246,7 @@
@BINPATH@/components/spellchecker.xpt
@BINPATH@/components/storage.xpt
@BINPATH@/components/telemetry.xpt
@BINPATH@/components/toolkit_filewatcher.xpt
@BINPATH@/components/toolkit_finalizationwitness.xpt
@BINPATH@/components/toolkit_formautofill.xpt
@BINPATH@/components/toolkit_osfile.xpt

View File

@ -38,6 +38,12 @@
#include "mozilla/NativeOSFileInternals.h"
#include "mozilla/AddonPathService.h"
#if defined(XP_WIN)
#include "NativeFileWatcherWin.h"
#else
#include "NativeFileWatcherNotSupported.h"
#endif // (XP_WIN)
using namespace mozilla;
/////////////////////////////////////////////////////////////////////////////
@ -94,6 +100,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsUpdateProcessor)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR(FinalizationWitnessService)
NS_GENERIC_FACTORY_CONSTRUCTOR(NativeOSFileInternalsService)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NativeFileWatcherService, Init)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AddonPathService, AddonPathService::GetInstance)
@ -123,6 +130,7 @@ NS_DEFINE_NAMED_CID(NS_UPDATEPROCESSOR_CID);
NS_DEFINE_NAMED_CID(FINALIZATIONWITNESSSERVICE_CID);
NS_DEFINE_NAMED_CID(NATIVE_OSFILE_INTERNALS_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_ADDON_PATH_SERVICE_CID);
NS_DEFINE_NAMED_CID(NATIVE_FILEWATCHER_SERVICE_CID);
static const Module::CIDEntry kToolkitCIDs[] = {
{ &kNS_TOOLKIT_APPSTARTUP_CID, false, nullptr, nsAppStartupConstructor },
@ -151,6 +159,7 @@ static const Module::CIDEntry kToolkitCIDs[] = {
{ &kFINALIZATIONWITNESSSERVICE_CID, false, nullptr, FinalizationWitnessServiceConstructor },
{ &kNATIVE_OSFILE_INTERNALS_SERVICE_CID, false, nullptr, NativeOSFileInternalsServiceConstructor },
{ &kNS_ADDON_PATH_SERVICE_CID, false, nullptr, AddonPathServiceConstructor },
{ &kNATIVE_FILEWATCHER_SERVICE_CID, false, nullptr, NativeFileWatcherServiceConstructor },
{ nullptr }
};
@ -182,6 +191,7 @@ static const Module::ContractIDEntry kToolkitContracts[] = {
{ FINALIZATIONWITNESSSERVICE_CONTRACTID, &kFINALIZATIONWITNESSSERVICE_CID },
{ NATIVE_OSFILE_INTERNALS_SERVICE_CONTRACTID, &kNATIVE_OSFILE_INTERNALS_SERVICE_CID },
{ NS_ADDONPATHSERVICE_CONTRACTID, &kNS_ADDON_PATH_SERVICE_CID },
{ NATIVE_FILEWATCHER_SERVICE_CONTRACTID, &kNATIVE_FILEWATCHER_SERVICE_CID },
{ nullptr }
};

View File

@ -0,0 +1,52 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_nativefilewatcher_h__
#define mozilla_nativefilewatcher_h__
#include "nsINativeFileWatcher.h"
namespace mozilla {
class NativeFileWatcherService MOZ_FINAL : public nsINativeFileWatcherService
{
public:
NS_DECL_ISUPPORTS
NativeFileWatcherService()
{
};
nsresult Init()
{
return NS_OK;
};
NS_IMETHODIMP AddPath(const nsAString& aPathToWatch,
nsINativeFileWatcherCallback* aOnChange,
nsINativeFileWatcherErrorCallback* aOnError,
nsINativeFileWatcherSuccessCallback* aOnSuccess)
{
return NS_ERROR_NOT_IMPLEMENTED;
};
NS_IMETHODIMP RemovePath(const nsAString& aPathToRemove,
nsINativeFileWatcherCallback* aOnChange,
nsINativeFileWatcherErrorCallback* aOnError,
nsINativeFileWatcherSuccessCallback* aOnSuccess)
{
return NS_ERROR_NOT_IMPLEMENTED;
};
private:
~NativeFileWatcherService() { };
NativeFileWatcherService(const NativeFileWatcherService& other) MOZ_DELETE;
void operator=(const NativeFileWatcherService& other) MOZ_DELETE;
};
NS_IMPL_ISUPPORTS(NativeFileWatcherService, nsINativeFileWatcherService);
} // namespace mozilla
#endif // mozilla_nativefilewatcher_h__

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_nativefilewatcher_h__
#define mozilla_nativefilewatcher_h__
#include "nsINativeFileWatcher.h"
#include "nsIObserver.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsThreadUtils.h"
// We need to include this header here for HANDLE definition.
#include <windows.h>
namespace mozilla {
class NativeFileWatcherService MOZ_FINAL : public nsINativeFileWatcherService,
public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSINATIVEFILEWATCHERSERVICE
NS_DECL_NSIOBSERVER
NativeFileWatcherService();
nsresult Init();
private:
// The |HANDLE| to the I/O Completion Port, owned by the main thread.
HANDLE mIOCompletionPort;
nsCOMPtr<nsIThread> mIOThread;
// The instance of the runnable dealing with the I/O.
nsCOMPtr<nsIRunnable> mWorkerIORunnable;
nsresult Uninit();
void WakeUpWorkerThread();
// Make the dtor private to make this object only deleted via its ::Release() method.
~NativeFileWatcherService();
NativeFileWatcherService(const NativeFileWatcherService& other) MOZ_DELETE;
void operator=(const NativeFileWatcherService& other) MOZ_DELETE;
};
} // namespace mozilla
#endif // mozilla_nativefilewatcher_h__

View File

@ -0,0 +1,23 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
EXPORTS += ['NativeFileWatcherWin.h']
UNIFIED_SOURCES += [
'NativeFileWatcherWin.cpp',
]
else:
EXPORTS += ['NativeFileWatcherNotSupported.h']
XPIDL_MODULE = 'toolkit_filewatcher'
XPIDL_SOURCES += [
'nsINativeFileWatcher.idl',
]
FINAL_LIBRARY = 'xul'
FAIL_ON_WARNINGS = True

View File

@ -0,0 +1,111 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
/**
* The interface for the callback invoked when there is an error.
*/
[scriptable, function, uuid(5DAEDDC3-FC94-4880-8A4F-26D910B92662)]
interface nsINativeFileWatcherErrorCallback: nsISupports
{
/**
* @param xpcomError The XPCOM error code.
* @param osError The native OS error (errno under Unix, GetLastError under Windows).
*/
void complete(in nsresult xpcomError, in long osError);
};
/**
* The interface for the callback invoked when a change on a watched
* resource is detected.
*/
[scriptable, function, uuid(FE4D86C9-243F-4195-B544-AECE3DF4B86A)]
interface nsINativeFileWatcherCallback: nsISupports
{
/**
* @param resourcePath
* The path of the changed resource. If there were too many changes,
* the string "*" is passed.
* @param flags Reserved for future uses, not currently used.
*/
void changed(in AString resourcePath, in int32_t flags);
};
/**
* The interface for the callback invoked when a file watcher operation
* successfully completes.
*/
[scriptable, function, uuid(C3D7F542-681B-4ABD-9D65-9D799B29A42B)]
interface nsINativeFileWatcherSuccessCallback: nsISupports
{
/**
* @param resourcePath
* The path of the resource for which the operation completes.
*/
void complete(in AString resourcePath);
};
/**
* A service providing native implementations of path changes notification.
*/
[scriptable, builtinclass, uuid(B3A4E8D8-7DC8-47DB-A8B4-83736D7AC1AA)]
interface nsINativeFileWatcherService: nsISupports
{
/**
* Watches the passed path for changes. If it's a directory, every file
* it contains is watched. Recursively watches subdirectories. If the
* resource is already being watched, does nothing. If the passed path
* is a file, the behaviour is not specified.
*
* @param pathToWatch The path to watch for changes.
* @param onChange
* The callback invoked whenever a change on a watched
* resource is detected.
* @param onError
* The optional callback invoked whenever an error occurs.
* @param onSuccess
* The optional callback invoked when the file watcher starts
* watching the resource for changes.
*/
void addPath(in AString pathToWatch,
in nsINativeFileWatcherCallback onChange,
[optional] in nsINativeFileWatcherErrorCallback onError,
[optional] in nsINativeFileWatcherSuccessCallback onSuccess);
/**
* Removes the provided path from the watched resources. If the path
* was not being watched or the callbacks were not registered, silently
* ignores the request.
* Please note that the file watcher only considers the onChange callbacks
* when deciding to close a watch on a resource. If there are no more onChange
* callbacks associated to the watch, it gets closed (even though it still has
* some error callbacks associated).
*
* @param pathToUnwatch The path to un-watch.
* @param onChange
* The registered callback invoked whenever a change on a watched
* resource is detected.
* @param onError
* The optionally registered callback invoked whenever an error
* occurs.
* @param onSuccess
* The optional callback invoked when the file watcher stops
* watching the resource for changes.
*/
void removePath(in AString pathToUnwatch,
in nsINativeFileWatcherCallback onChange,
[optional] in nsINativeFileWatcherErrorCallback onError,
[optional] in nsINativeFileWatcherSuccessCallback onSuccess);
};
%{ C++
#define NATIVE_FILEWATCHER_SERVICE_CID {0x6F488507, 0x469D, 0x4350, {0xA6, 0x8D, 0x99, 0xC8, 0x7, 0xBE, 0xA, 0x78}}
#define NATIVE_FILEWATCHER_SERVICE_CONTRACTID "@mozilla.org/toolkit/filewatcher/native-file-watcher;1"
%}

View File

@ -23,6 +23,7 @@ DIRS += [
'downloads',
'exthelper',
'filepicker',
'filewatcher',
'finalizationwitness',
'formautofill',
'find',