Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: ui/file_manager/file_manager/background/js/import_history.js

Issue 868133004: Serialize reading and writing in the import history storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/file_manager/file_manager/background/js/import_history_unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/background/js/import_history.js
diff --git a/ui/file_manager/file_manager/background/js/import_history.js b/ui/file_manager/file_manager/background/js/import_history.js
index 5f5caf7b368f402bc97d86388323f05f9447c039..39acc350f06cf2c931f5e15396db31fd11d2a8c2 100644
--- a/ui/file_manager/file_manager/background/js/import_history.js
+++ b/ui/file_manager/file_manager/background/js/import_history.js
@@ -763,13 +763,27 @@ importer.RecordStorage.prototype.readAll;
importer.FileEntryRecordStorage = function(fileEntry) {
/** @private {!importer.PromisingFileEntry} */
this.fileEntry_ = new importer.PromisingFileEntry(fileEntry);
+
+ /**
+ * Serializes all writes and reads.
+ * @private {!Promise.<?>}
+ * */
+ this.latestOperation_ = Promise.resolve(null);
};
/** @override */
importer.FileEntryRecordStorage.prototype.write = function(record) {
- // TODO(smckay): should we make an effort to reuse a file writer?
- return this.fileEntry_.createWriter()
- .then(this.writeRecord_.bind(this, record));
+ return this.latestOperation_ = this.latestOperation_
+ .then(
+ /**
+ * @param {?} ignore
+ * @this {importer.FileEntryRecordStorage}
+ */
+ function(ignore) {
+ return this.fileEntry_.createWriter();
+ }.bind(this))
+ .then(this.writeRecord_.bind(this, record))
+ .catch(importer.getLogger().catcher('record-writing'));
};
/**
@@ -802,26 +816,35 @@ importer.FileEntryRecordStorage.prototype.writeRecord_ =
/** @override */
importer.FileEntryRecordStorage.prototype.readAll = function() {
- return this.fileEntry_.file()
- .then(
- this.readFileAsText_.bind(this),
- /**
- * @return {string}
- * @this {importer.FileEntryRecordStorage}
- */
- function() {
- console.error('Unable to read from history file.');
- return '';
- }.bind(this))
- .then(
- /**
- * @param {string} fileContents
- * @this {importer.FileEntryRecordStorage}
- */
- function(fileContents) {
- return this.parse_(fileContents);
- }.bind(this))
- .catch(importer.getLogger().catcher('record-reading'));
+ return /** @type {!Promise.<!Array.<!Array.<*>>>} */ (this.latestOperation_ =
+ this.latestOperation_
+ .then(
+ /**
+ * @param {?} ignore
+ * @this {importer.FileEntryRecordStorage}
+ */
+ function(ignore) {
+ return this.fileEntry_.file();
+ }.bind(this))
+ .then(
+ this.readFileAsText_.bind(this),
+ /**
+ * @return {string}
+ * @this {importer.FileEntryRecordStorage}
+ */
+ function() {
+ console.error('Unable to read from history file.');
+ return '';
+ }.bind(this))
+ .then(
+ /**
+ * @param {string} fileContents
+ * @this {importer.FileEntryRecordStorage}
+ */
+ function(fileContents) {
+ return this.parse_(fileContents);
+ }.bind(this))
+ .catch(importer.getLogger().catcher('record-reading')));
};
/**
« no previous file with comments | « no previous file | ui/file_manager/file_manager/background/js/import_history_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698