WebAPI/ProposedDeviceStorageAPIWithNotifications: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
Line 34: Line 34:
   // Deletes a file
   // Deletes a file
   DOMRequest delete(DOMString name);
   DOMRequest delete(DOMString name);
  // Create a watcher which will call the callback function every time files are updated
  // callback will take the DeviceStorage, the file's name, and the update type, which will be one of "created", "deleted", or "modified"
  // If filter is passed, the watcher will only return
  // If time is passed, the watcher will immediately call callback on each request which occurred since the given time.
  // The time is measured in milliseconds since Midnight GMT (00:00), January 1st, 1970.
  // returns a DOMRequest whose .result is a PRUint32 specifying a unique ID for the added watcher.
  DOMRequest addFileWatcher(Function callback, optional DOMString filter, optional PRInt64 time);
   
   
   // Watches a file, or all files for updates
   // returns true if there was a watcher with this id, and false otherwise.
  // If name is specified, watches a file with that name
   boolean removeFileWatcher(PRUint32 id);
  // returns the DeviceStorageWatch for this request, through which future requests will be processed
   DeviceStorageWatch watchChanges(optional DOMString name);
   
   
   // See interface below for how to use this
   // See interface below for how to use this
Line 50: Line 56:
   void continue();
   void continue();
  };
  };
interface DeviceStorageWatch{
  // This enum represents the kinds of operations that an application can watch for
  enum UpdateType { DSWCreated, DSWModified, DSWDeleted };
  // this function is called whenever the file(s) addressed by the request are created, modified, or deleted
  // takes the file's name and type as its two arguments
  void (*onChange)(DOMString, UpdateType);
  // this function stops the watcher permanently
  void cancel();
}

Revision as of 23:48, 22 May 2012

This page contains a draft of the proposed modification to the DeviceStorage API to include onchanged notifications.

API

partial interface Navigator {
  /**
   * type is an arbitrary string. On OSs with predefined directories (pictures,
   * music, etc) we can match certain type names to certain folders.
   * To be figured out.
   *
   * Note that each value for the type represents a different directory.
   * I.e. passing "pictures" as type will yield a completely different set
   * of files from passing "movies" as the type.
   *
   * In other words, the type argument is not some sort of filter, but rather
   * simply a destination directory.
   */
  DeviceStorage getDeviceStorage(DOMString type);
};

interface DeviceStorage {
  // Name will be generated by the implementation and returned as result of request
  DOMRequest add(Blob blob);

  // Fails if a file with the given name already exists.
  DOMRequest addNamed(Blob blob, DOMString name);

  // Returns the result as a File object
  DOMRequest get(DOMString name);

  // Returns the result as a FileHandle object which enables writing
  DOMRequest getEditable(DOMString name);

  // Deletes a file
  DOMRequest delete(DOMString name);
  // Create a watcher which will call the callback function every time files are updated
  // callback will take the DeviceStorage, the file's name, and the update type, which will be one of "created", "deleted", or "modified"
  // If filter is passed, the watcher will only return
  // If time is passed, the watcher will immediately call callback on each request which occurred since the given time.
  // The time is measured in milliseconds since Midnight GMT (00:00), January 1st, 1970.
  // returns a DOMRequest whose .result is a PRUint32 specifying a unique ID for the added watcher.
  DOMRequest addFileWatcher(Function callback, optional DOMString filter, optional PRInt64 time);

  // returns true if there was a watcher with this id, and false otherwise.
  boolean removeFileWatcher(PRUint32 id);

  // See interface below for how to use this
  DeviceStorageCursor enumerate(optional DOMString directory)
  DeviceStorageCursor enumerateEditable(optional DOMString directory)
};

interface DeviceStorageCursor : DOMRequest {
  // .result is either a File or a FileHandle
  
  void continue();
};