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

Unified Diff: ui/file_manager/file_manager/common/js/importer_common.js

Issue 954583004: Shrink space required by history log file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify some of the history initialization complexity added in earlier patch. Created 5 years, 10 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
Index: ui/file_manager/file_manager/common/js/importer_common.js
diff --git a/ui/file_manager/file_manager/common/js/importer_common.js b/ui/file_manager/file_manager/common/js/importer_common.js
index c38bdbad8aa476b820ba927bc8836cd43dd8cc48..11e2125162b67420bec63b8f51e1f4ce3e336fbe 100644
--- a/ui/file_manager/file_manager/common/js/importer_common.js
+++ b/ui/file_manager/file_manager/common/js/importer_common.js
@@ -367,6 +367,44 @@ importer.PromisingFileEntry.prototype.getMetadata = function() {
};
/**
+ * This prefix is stripped from URL used in import history. It is stripped
+ * to same on disk space, parsing time, and runtime memory.
+ * @private @const {string}
+ */
+importer.APP_URL_PREFIX_ =
+ 'filesystem:chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/external';
+
+/**
+ * Strips non-unique information from the URL. The resulting
+ * value can be reconstituted using {@code importer.inflateAppUrl}.
+ *
+ * @param {string} url
+ * @return {string}
+ */
+importer.deflateAppUrl = function(url) {
+ if (url.substring(0, importer.APP_URL_PREFIX_.length) ===
+ importer.APP_URL_PREFIX_) {
+ return '$' + url.substring(importer.APP_URL_PREFIX_.length);
+ }
+
+ return url;
+};
+
+/**
+ * Reconstitutes a url previous deflated by {@code deflateAppUrl}.
+ * Returns the original string if it can't be inflated.
+ *
+ * @param {string} deflated
+ * @return {string}
+ */
+importer.inflateAppUrl = function(deflated) {
+ if (deflated.substring(0, 1) === '$') {
+ return importer.APP_URL_PREFIX_ + deflated.substring(1);
+ }
+ return deflated;
+};
+
+/**
* @param {!FileEntry} fileEntry
* @return {!Promise.<string>} Resolves with a "hashcode" consisting of
* just the last modified time and the file size.
@@ -393,10 +431,27 @@ importer.createMetadataHashcode = function(fileEntry) {
} else if (!('size' in metadata)) {
reject('File entry missing "size" field.');
} else {
- resolve(metadata.modificationTime + '_' + metadata.size);
+ var secondsSinceEpoch =
+ importer.toSecondsFromEpoch(metadata.modificationTime);
+ resolve(secondsSinceEpoch + '_' + metadata.size);
}
}.bind(this));
- }.bind(this));
+ }.bind(this))
+ .catch(importer.getLogger().catcher('importer-common-create-hashcode'));
+};
+
+/**
+ * @param {string} date A date string in the form
+ * expected by Date.parse.
+ * @return {string} The number of seconds from epoch to the date...as a string.
+ */
+importer.toSecondsFromEpoch = function(date) {
+ // Since we're parsing a value that only has
+ // precision to the second, our last three digits
+ // will always be 000. We strip them and end up
+ // with seconds.
+ var milliseconds = String(Date.parse(date));
+ return milliseconds.substring(0, milliseconds.length - 3);
};
/**
@@ -408,14 +463,6 @@ importer.createMetadataHashcode = function(fileEntry) {
importer.SyncFileEntryProvider = function() {};
/**
- * Adds a listener to be notified when the the FileEntry owned/managed
- * by this class is updated via sync.
- *
- * @param {function()} syncListener
- */
-importer.SyncFileEntryProvider.prototype.addSyncListener;
-
-/**
* Provides accsess to the sync FileEntry owned/managed by this class.
*
* @return {!Promise.<!FileEntry>}
@@ -441,8 +488,6 @@ importer.ChromeSyncFileEntryProvider = function(fileName) {
/** @private {Promise.<!FileEntry>} */
this.fileEntryPromise_ = null;
-
- this.monitorSyncEvents_();
};
/**
@@ -460,25 +505,6 @@ importer.ChromeSyncFileEntryProvider.getFileEntry =
});
};
-/**
- * Wraps chrome.syncFileSystem.onFileStatusChanged
- * so that we can report to our listeners when our file has changed.
- * @private
- */
-importer.ChromeSyncFileEntryProvider.prototype.monitorSyncEvents_ =
- function() {
- chrome.syncFileSystem.onFileStatusChanged.addListener(
- this.handleSyncEvent_.bind(this));
-};
-
-/** @override */
-importer.ChromeSyncFileEntryProvider.prototype.addSyncListener =
- function(listener) {
- if (this.syncListeners_.indexOf(listener) === -1) {
- this.syncListeners_.push(listener);
- }
-};
-
/** @override */
importer.ChromeSyncFileEntryProvider.prototype.getSyncFileEntry = function() {
if (this.fileEntryPromise_) {
@@ -589,8 +615,8 @@ importer.ChromeSyncFileEntryProvider.prototype.handleSyncEvent_ =
}
if (event.action && event.action !== 'updated') {
- console.error(
- 'Unexpected sync event action for sync file: ' + event.action);
+ console.warn(
+ 'Unusual sync event action for sync file: ' + event.action);
return;
}

Powered by Google App Engine
This is Rietveld 408576698