Merge f-t to m-c
authorPhil Ringnalda <philringnalda@gmail.com>
Sun, 27 Oct 2013 21:44:49 -0700
changeset 166252 59ff3a2a708a6d95894e4bcf6c6ed8c75190e30c
parent 166249 e0c5c0f62aef5e8459d1d93ce5e9b3261f253c3f (current diff)
parent 166251 3685c303b72343849658ef2d22c3535648223a6c (diff)
child 166256 9e0dbf6786543397dcc34d7664aa5094164d7a9c
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge f-t to m-c
--- a/toolkit/components/osfile/modules/osfile_async_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_async_front.jsm
@@ -480,16 +480,32 @@ File.prototype = {
    * POS_END (from the end of the file) or POS_CUR (from the
    * current position in the file).
    *
    * @return {promise}
    */
   setPosition: function setPosition(pos, whence) {
     return Scheduler.post("File_prototype_setPosition",
       [this._fdmsg, pos, whence]);
+  },
+
+  /**
+   * Flushes the file's buffers and causes all buffered data
+   * to be written.
+   * Disk flushes are very expensive and therefore should be used carefully,
+   * sparingly and only in scenarios where it is vital that data survives
+   * system crashes. Even though the function will be executed off the
+   * main-thread, it might still affect the overall performance of any running
+   * application.
+   *
+   * @return {promise}
+   */
+  flush: function flush() {
+    return Scheduler.post("File_prototype_flush",
+      [this._fdmsg]);
   }
 };
 
 /**
  * Open a file asynchronously.
  *
  * @return {promise}
  * @resolves {OS.File}
--- a/toolkit/components/osfile/modules/osfile_async_worker.js
+++ b/toolkit/components/osfile/modules/osfile_async_worker.js
@@ -403,16 +403,22 @@ if (this.Components) {
        });
    },
    File_prototype_getPosition: function getPosition(fd) {
      return withFile(fd,
        function do_getPosition() {
          return this.getPosition();
        });
    },
+   File_prototype_flush: function flush(fd) {
+     return withFile(fd,
+       function do_flush() {
+         return this.flush();
+       });
+   },
    // Methods of OS.File.DirectoryIterator
    DirectoryIterator_prototype_next: function next(dir) {
      return withDir(dir,
        function do_next() {
          try {
            return File.DirectoryIterator.Entry.toMsg(this.next());
          } catch (x) {
            if (x == StopIteration) {
--- a/toolkit/components/osfile/modules/osfile_unix_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_unix_front.jsm
@@ -166,16 +166,21 @@
      File.prototype.stat = function stat() {
        throw_on_negative("stat", UnixFile.fstat(this.fd, gStatDataPtr));
          return new File.Info(gStatData);
      };
 
      /**
       * Flushes the file's buffers and causes all buffered data
       * to be written.
+      * Disk flushes are very expensive and therefore should be used carefully,
+      * sparingly and only in scenarios where it is vital that data survives
+      * system crashes. Even though the function will be executed off the
+      * main-thread, it might still affect the overall performance of any
+      * running application.
       *
       * @throws {OS.File.Error} In case of I/O error.
       */
      File.prototype.flush = function flush() {
        throw_on_negative("flush", UnixFile.fsync(this.fd));
      };
 
      // The default unix mode for opening (0600)
--- a/toolkit/components/osfile/modules/osfile_win_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_win_front.jsm
@@ -186,16 +186,21 @@
        throw_on_zero("stat",
          WinFile.GetFileInformationByHandle(this.fd, gFileInfoPtr));
        return new File.Info(gFileInfo);
      };
 
      /**
       * Flushes the file's buffers and causes all buffered data
       * to be written.
+      * Disk flushes are very expensive and therefore should be used carefully,
+      * sparingly and only in scenarios where it is vital that data survives
+      * system crashes. Even though the function will be executed off the
+      * main-thread, it might still affect the overall performance of any
+      * running application.
       *
       * @throws {OS.File.Error} In case of I/O error.
       */
      File.prototype.flush = function flush() {
        throw_on_zero("flush", WinFile.FlushFileBuffers(this.fd));
      };
 
      // The default sharing mode for opening files: files are not
new file mode 100644
--- /dev/null
+++ b/toolkit/components/osfile/tests/xpcshell/test_osfile_async_flush.js
@@ -0,0 +1,30 @@
+"use strict";
+
+Components.utils.import("resource://gre/modules/osfile.jsm");
+Components.utils.import("resource://gre/modules/Task.jsm");
+
+function run_test() {
+  do_test_pending();
+  run_next_test();
+}
+
+/**
+ * Test to ensure that |File.prototype.flush| is available in the async API.
+ */
+
+add_task(function test_flush() {
+  let path = OS.Path.join(OS.Constants.Path.tmpDir,
+                          "test_osfile_async_flush.tmp");
+  let file = yield OS.File.open(path, {trunc: true, write: true});
+  try {
+    try {
+      yield file.flush();
+    } finally {
+      yield file.close();
+    }
+  } finally {
+    yield OS.File.remove(path);
+  }
+});
+
+add_task(do_test_finished);
--- a/toolkit/components/osfile/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/osfile/tests/xpcshell/xpcshell.ini
@@ -3,16 +3,17 @@ head =
 tail =
 
 [test_osfile_closed.js]
 [test_path.js]
 [test_osfile_async.js]
 [test_osfile_async_append.js]
 [test_osfile_async_bytes.js]
 [test_osfile_async_copy.js]
+[test_osfile_async_flush.js]
 [test_profiledir.js]
 [test_logging.js]
 [test_creationDate.js]
 [test_exception.js]
 [test_path_constants.js]
 [test_removeDir.js]
 [test_reset.js]
 [test_shutdown.js]