Dart Documentationchrome.syncFileSystemChromeSyncFileSystem

ChromeSyncFileSystem class

class ChromeSyncFileSystem extends ChromeApi {
 static final JsObject _syncFileSystem = chrome['syncFileSystem'];

 ChromeSyncFileSystem._();

 bool get available => _syncFileSystem != null;

 /**
  * Returns a syncable filesystem backed by Google Drive. The returned
  * `FileSystem` instance can be operated on in the same way as the
  * Temporary and Persistant file systems (see <a
  * href="http://www.w3.org/TR/file-system-api/">http://www.w3.org/TR/file-system-api/</a>).
  * Calling this multiple times from the same app will return the same handle
  * to the same file system.
  * 
  * Returns:
  * A callback type for requestFileSystem.
  */
 Future<FileSystem> requestFileSystem() {
   if (_syncFileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<FileSystem>.oneArg(_createDOMFileSystem);
   _syncFileSystem.callMethod('requestFileSystem', [completer.callback]);
   return completer.future;
 }

 /**
  * Sets the default conflict resolution policy for the `'syncable'` file
  * storage for the app. By default it is set to `'last_write_win'`. When
  * conflict resolution policy is set to `'last_write_win'` conflicts for
  * existing files are automatically resolved next time the file is updated.
  * [callback] can be optionally given to know if the request has succeeded or
  * not.
  */
 Future setConflictResolutionPolicy(ConflictResolutionPolicy policy) {
   if (_syncFileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter.noArgs();
   _syncFileSystem.callMethod('setConflictResolutionPolicy', [jsify(policy), completer.callback]);
   return completer.future;
 }

 /**
  * Gets the current conflict resolution policy.
  * 
  * Returns:
  * A callback type for getConflictResolutionPolicy.
  */
 Future<ConflictResolutionPolicy> getConflictResolutionPolicy() {
   if (_syncFileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<ConflictResolutionPolicy>.oneArg(_createConflictResolutionPolicy);
   _syncFileSystem.callMethod('getConflictResolutionPolicy', [completer.callback]);
   return completer.future;
 }

 /**
  * Returns the current usage and quota in bytes for the `'syncable'` file
  * storage for the app.
  * 
  * Returns:
  * A callback type for getUsageAndQuota.
  */
 Future<StorageInfo> getUsageAndQuota(FileSystem fileSystem) {
   if (_syncFileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<StorageInfo>.oneArg(_createStorageInfo);
   _syncFileSystem.callMethod('getUsageAndQuota', [jsify(fileSystem), completer.callback]);
   return completer.future;
 }

 /**
  * Returns the [FileStatus] for the given `fileEntry`. The status value can be
  * `'synced'`, `'pending'` or `'conflicting'`. Note that `'conflicting'` state
  * only happens when the service's conflict resolution policy is set to
  * `'manual'`.
  * 
  * Returns:
  * A callback type for getFileStatus.
  */
 Future<FileStatus> getFileStatus(Entry fileEntry) {
   if (_syncFileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<FileStatus>.oneArg(_createFileStatus);
   _syncFileSystem.callMethod('getFileStatus', [jsify(fileEntry), completer.callback]);
   return completer.future;
 }

 /**
  * Returns each [FileStatus] for the given `fileEntry` array. Typically called
  * with the result from dirReader.readEntries().
  * 
  * Returns:
  * A callback type for getFileStatuses.
  */
 Future<List<FileStatusInfo>> getFileStatuses(List<dynamic> fileEntries) {
   if (_syncFileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<FileStatusInfo>>.oneArg((e) => listify(e, _createFileStatusInfo));
   _syncFileSystem.callMethod('getFileStatuses', [jsify(fileEntries), completer.callback]);
   return completer.future;
 }

 /**
  * Returns the current sync backend status.
  * 
  * Returns:
  * A callback type for getServiceStatus.
  */
 Future<ServiceStatus> getServiceStatus() {
   if (_syncFileSystem == null) _throwNotAvailable();

   var completer = new ChromeCompleter<ServiceStatus>.oneArg(_createServiceStatus);
   _syncFileSystem.callMethod('getServiceStatus', [completer.callback]);
   return completer.future;
 }

 Stream<ServiceInfo> get onServiceStatusChanged => _onServiceStatusChanged.stream;

 final ChromeStreamController<ServiceInfo> _onServiceStatusChanged =
     new ChromeStreamController<ServiceInfo>.oneArg(_syncFileSystem, 'onServiceStatusChanged', _createServiceInfo);

 Stream<FileInfo> get onFileStatusChanged => _onFileStatusChanged.stream;

 final ChromeStreamController<FileInfo> _onFileStatusChanged =
     new ChromeStreamController<FileInfo>.oneArg(_syncFileSystem, 'onFileStatusChanged', _createFileInfo);

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.syncFileSystem' is not available");
 }
}

Extends

ChromeApi > ChromeSyncFileSystem

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _syncFileSystem != null;

final Stream<FileInfo> onFileStatusChanged #

Stream<FileInfo> get onFileStatusChanged => _onFileStatusChanged.stream;

final Stream<ServiceInfo> onServiceStatusChanged #

Stream<ServiceInfo> get onServiceStatusChanged => _onServiceStatusChanged.stream;

Methods

Future<ConflictResolutionPolicy> getConflictResolutionPolicy() #

Gets the current conflict resolution policy.

Returns: A callback type for getConflictResolutionPolicy.

Future<ConflictResolutionPolicy> getConflictResolutionPolicy() {
 if (_syncFileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<ConflictResolutionPolicy>.oneArg(_createConflictResolutionPolicy);
 _syncFileSystem.callMethod('getConflictResolutionPolicy', [completer.callback]);
 return completer.future;
}

Future<FileStatus> getFileStatus(Entry fileEntry) #

Returns the FileStatus for the given fileEntry. The status value can be 'synced', 'pending' or 'conflicting'. Note that 'conflicting' state only happens when the service's conflict resolution policy is set to 'manual'.

Returns: A callback type for getFileStatus.

Future<FileStatus> getFileStatus(Entry fileEntry) {
 if (_syncFileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<FileStatus>.oneArg(_createFileStatus);
 _syncFileSystem.callMethod('getFileStatus', [jsify(fileEntry), completer.callback]);
 return completer.future;
}

Future<List<FileStatusInfo>> getFileStatuses(List<dynamic> fileEntries) #

Returns each FileStatus for the given fileEntry array. Typically called with the result from dirReader.readEntries().

Returns: A callback type for getFileStatuses.

Future<List<FileStatusInfo>> getFileStatuses(List<dynamic> fileEntries) {
 if (_syncFileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<FileStatusInfo>>.oneArg((e) => listify(e, _createFileStatusInfo));
 _syncFileSystem.callMethod('getFileStatuses', [jsify(fileEntries), completer.callback]);
 return completer.future;
}

Future<ServiceStatus> getServiceStatus() #

Returns the current sync backend status.

Returns: A callback type for getServiceStatus.

Future<ServiceStatus> getServiceStatus() {
 if (_syncFileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<ServiceStatus>.oneArg(_createServiceStatus);
 _syncFileSystem.callMethod('getServiceStatus', [completer.callback]);
 return completer.future;
}

Future<StorageInfo> getUsageAndQuota(FileSystem fileSystem) #

Returns the current usage and quota in bytes for the 'syncable' file storage for the app.

Returns: A callback type for getUsageAndQuota.

Future<StorageInfo> getUsageAndQuota(FileSystem fileSystem) {
 if (_syncFileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<StorageInfo>.oneArg(_createStorageInfo);
 _syncFileSystem.callMethod('getUsageAndQuota', [jsify(fileSystem), completer.callback]);
 return completer.future;
}

Future<FileSystem> requestFileSystem() #

Returns a syncable filesystem backed by Google Drive. The returned FileSystem instance can be operated on in the same way as the Temporary and Persistant file systems (see <a href="http://www.w3.org/TR/file-system-api/">http://www.w3.org/TR/file-system-api/</a>). Calling this multiple times from the same app will return the same handle to the same file system.

Returns: A callback type for requestFileSystem.

Future<FileSystem> requestFileSystem() {
 if (_syncFileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter<FileSystem>.oneArg(_createDOMFileSystem);
 _syncFileSystem.callMethod('requestFileSystem', [completer.callback]);
 return completer.future;
}

Future setConflictResolutionPolicy(ConflictResolutionPolicy policy) #

Sets the default conflict resolution policy for the 'syncable' file storage for the app. By default it is set to 'last_write_win'. When conflict resolution policy is set to 'last_write_win' conflicts for existing files are automatically resolved next time the file is updated. callback can be optionally given to know if the request has succeeded or not.

Future setConflictResolutionPolicy(ConflictResolutionPolicy policy) {
 if (_syncFileSystem == null) _throwNotAvailable();

 var completer = new ChromeCompleter.noArgs();
 _syncFileSystem.callMethod('setConflictResolutionPolicy', [jsify(policy), completer.callback]);
 return completer.future;
}