[platforms=("chromeos"),
implemented_in="chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h"]
namespace fileSystemProvider {
- // Error codes used by providing extensions in response to requests. For
- // success, <code>OK</code> must be used.
+ // Error codes used by providing extensions in response to requests as well
+ // as in case of errors when calling methods of the API. For success, <code>
+ // OK</code> must be used.
enum ProviderError {
OK,
FAILED,
NOT_A_DIRECTORY,
INVALID_OPERATION,
SECURITY,
+ ABORT,
NOT_A_FILE,
NOT_EMPTY,
INVALID_URL,
WRITE
};
+ // Type of a change detected on the observed directory.
+ enum ChangeType {
+ CHANGED,
+ DELETED
+ };
+
// Represents metadata of a file or a directory.
dictionary EntryMetadata {
// True if it is a directory.
DOMString? thumbnail;
};
+ // Represents a watcher.
+ dictionary Watcher {
+ // The path of the entry being observed.
+ DOMString entryPath;
+
+ // Whether watching should include all child entries recursively. It can be
+ // true for directories only.
+ boolean recursive;
+
+ // Tag used by the last notification for the watcher.
+ DOMString? lastTag;
+ };
+
// Represents a mounted file system.
dictionary FileSystemInfo {
// The identifier of the file system.
// Whether the file system supports operations which may change contents
// of the file system (such as creating, deleting or writing to files).
boolean writable;
+
+ // Whether the file system supports the <code>tag</code> field for observing
+ // directories.
+ [nodoc] boolean? supportsNotifyTag;
+
+ // List of watchers.
+ [nodoc] Watcher[] watchers;
};
// Options for the <code>mount()</code> method.
// Whether the file system supports operations which may change contents
// of the file system (such as creating, deleting or writing to files).
boolean? writable;
+
+ // Whether the file system supports the <code>tag</code> field for observed
+ // directories. Required in order to enable the internal cache.
+ [nodoc] boolean? supportsNotifyTag;
};
// Options for the <code>unmount()</code> method.
long operationRequestId;
};
- // Callback to receive the result of mount() function.
- callback MountCallback = void([nodoc, instanceOf=DOMError] object error);
+ // Options for the <code>onAddWatcherRequested()</code> event.
+ dictionary AddWatcherRequestedOptions {
+ // The identifier of the file system related to this operation.
+ DOMString fileSystemId;
+
+ // The unique identifier of this request.
+ long requestId;
+
+ // The path of the entry to be observed.
+ DOMString entryPath;
+
+ // Whether observing should include all child entries recursively. It can be
+ // true for directories only.
+ boolean recursive;
+ };
+
+ // Options for the <code>onRemoveWatcherRequested()</code> event.
+ dictionary RemoveWatcherRequestedOptions {
+ // The identifier of the file system related to this operation.
+ DOMString fileSystemId;
- // Callback to receive the result of unmount() function.
- callback UnmountCallback = void([nodoc, instanceOf=DOMError] object error);
+ // The unique identifier of this request.
+ long requestId;
+
+ // The path of the watched entry.
+ DOMString entryPath;
+
+ // Mode of the watcher.
+ boolean recursive;
+ };
+
+ // Information about a change happened to an entry within the observed
+ // directory (including the entry itself).
+ dictionary Change {
+ // The path of the changed entry.
+ DOMString entryPath;
+
+ // The type of the change which happened to the entry.
+ ChangeType changeType;
+ };
+
+ // Options for the <code>Notify()</code> method.
+ dictionary NotifyOptions {
+ // The identifier of the file system related to this change.
+ DOMString fileSystemId;
+
+ // The path of the observed entry.
+ DOMString observedPath;
+
+ // Mode of the observed entry.
+ boolean recursive;
+
+ // The type of the change which happened to the observed entry. If it is
+ // DELETED, then the observed entry will be automatically removed from the
+ // list of observed entries.
+ ChangeType changeType;
+
+ // List of changes to entries within the observed directory (including the
+ // entry itself)
+ Change[]? changes;
+
+ // Tag for the notification. Required if the file system was mounted with
+ // the <code>supportsNotifyTag</code> option. Note, that this flag is
+ // necessary to provide notifications about changes which changed even
+ // when the system was shutdown.
+ DOMString? tag;
+ };
// Callback to receive the result of getAll() function.
callback GetAllCallback = void(FileSystemInfo[] fileSystems);
- // Callback to handle an error raised from the browser.
- [nocompile] callback ErrorCallback = void([instanceOf=DOMError] object error);
-
// Callback to be called by the providing extension in case of a success.
[nocompile] callback ProviderSuccessCallback = void();
[nocompile] callback FileDataCallback = void(
ArrayBuffer data, boolean hasMore);
+ // A generic result callback to indicate success or failure.
+ callback ResultCallback = void();
+
interface Functions {
// Mounts a file system with the given <code>fileSystemId</code> and <code>
// displayName</code>. <code>displayName</code> will be shown in the left
// panel of Files.app. <code>displayName</code> can contain any characters
// including '/', but cannot be an empty string. <code>displayName</code>
- // must be descriptive but doesn't have to be unique. Duplicate display
- // names are uniquified by adding suffix like "(1)" in the Files app UI.
- //
- // If a file system with the passed <code>fileSystemId</code> is already
- // mounted by this extension, then <code>errorCallback</code> will be called
- // with <code>ProviderError.EXISTS</code> value. The <code>fileSystemId
+ // must be descriptive but doesn't have to be unique. The <code>fileSystemId
// </code> must not be an empty string.
+ //
+ // In case of an error, <code>chrome.runtime.lastError</code> will be set
+ // will a corresponding error code.
static void mount(MountOptions options,
- MountCallback successCallback,
- [nocompile] ErrorCallback errorCallback);
+ optional ResultCallback callback);
// Unmounts a file system with the given <code>fileSystemId</code>. It
// must be called after <code>onUnmountRequested</code> is invoked. Also,
// the providing extension can decide to perform unmounting if not requested
- // (eg. in case of lost connection, or a file error). If there is no file
- // system with the requested id, or unmounting fails, then the
- // <code>errorCallback</code> will be called.
+ // (eg. in case of lost connection, or a file error).
+ //
+ // In case of an error, <code>chrome.runtime.lastError</code> will be set
+ // will a corresponding error code.
static void unmount(UnmountOptions options,
- UnmountCallback successCallback,
- [nocompile] ErrorCallback errorCallback);
+ optional ResultCallback callback);
// Returns all file systems mounted by the extension.
static void getAll(GetAllCallback callback);
+
+ // Notifies about changes in the watched directory at <code>
+ // observedPath</code> in <code>recursive</code mode. If the file system is
+ // mounted with <code>supportsNofityTag</code>, then <code>tag</code> must
+ // be provided, and all changes since the last notification always reported,
+ // even if the system was shutdown. The last tag can be obtained with <code>
+ // getAll()</code>. Note, that <code>tag</code> is required in order to
+ // enable the internal cache.
+ //
+ // Value of <code>tag</code> can be any string which is unique per call,
+ // so it's possible to identify the last registered notification. Eg. if
+ // the providing extension starts after a reboot, and the last registered
+ // notification's tag is equal to "123", then it should call notify() for
+ // all changes which happened since the change tagged as "123". It cannot
+ // be an empty string.
+ //
+ // Not all providers are able to provide a tag, but if the file system has
+ // a changelog, then the tag can be eg. a change number, or a revision
+ // number.
+ //
+ // Note that if a parent directory is removed, then all descendant entries
+ // are also removed, and if they are watched, then the API must be notified
+ // about the fact. Also, if a directory is renamed, then all descendant
+ // entries are in fact removed, as there is no entry under their original
+ // paths anymore.
+ //
+ // In case of an error, <code>chrome.runtime.lastError</code> will be set
+ // will a corresponding error code.
+ [nodoc] static void notify(NotifyOptions options,
+ optional ResultCallback callback);
};
interface Events {
AbortRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
+
+ // Raised when setting a new directory watcher is requested. If an error
+ // occurs, then <code>errorCallback</code> must be called.
+ [maxListeners=1, nodoc] static void onAddWatcherRequested(
+ AddWatcherRequestedOptions options,
+ ProviderSuccessCallback successCallback,
+ ProviderErrorCallback errorCallback);
+
+ // Raised when the watcher should be removed. If an error occurs, then
+ // <code>errorCallback</code> must be called.
+ [maxListeners=1, nodoc] static void onRemoveWatcherRequested(
+ RemoveWatcherRequestedOptions options,
+ ProviderSuccessCallback successCallback,
+ ProviderErrorCallback errorCallback);
};
};