Chromium Code Reviews| Index: ui/file_manager/file_manager/background/js/duplicate_finder.js |
| diff --git a/ui/file_manager/file_manager/background/js/duplicate_finder.js b/ui/file_manager/file_manager/background/js/duplicate_finder.js |
| index 25ac1574af6574271a5e93291990483546752b0f..05b44ea283e4c64d7c0bfe52852b6a50918f0bb5 100644 |
| --- a/ui/file_manager/file_manager/background/js/duplicate_finder.js |
| +++ b/ui/file_manager/file_manager/background/js/duplicate_finder.js |
| @@ -21,7 +21,17 @@ importer.DuplicateFinder = function() {}; |
| importer.DuplicateFinder.prototype.checkDuplicate; |
| /** |
| + * A factory for producing duplicate finders. |
| + * @interface |
| + */ |
| +importer.DuplicateFinder.Factory = function() {}; |
|
Steve McKay
2015/02/12 17:59:14
Don't introduce a factory, just use a function typ
Ben Kwa
2015/02/17 23:01:29
Discussed offline, and leaving as-is for now.
|
| + |
| +/** @return {!importer.DuplicateFinder} */ |
| +importer.DuplicateFinder.Factory.prototype.get; |
|
mtomasz
2015/02/12 01:51:03
nit: Does it create or get? Maybe get -> create?
Ben Kwa
2015/02/17 23:01:29
Done.
|
| + |
| +/** |
| * A duplicate finder for Google Drive. |
| + * |
| * @constructor |
| * @implements {importer.DuplicateFinder} |
| * @struct |
| @@ -29,11 +39,31 @@ importer.DuplicateFinder.prototype.checkDuplicate; |
| importer.DriveDuplicateFinder = function() { |
| /** @private {Promise<string>} */ |
| this.driveIdPromise_ = null; |
| + |
| + /** |
| + * Aggregate time spent computing content hashes (in ms). |
| + * @private {number} |
| + */ |
| + this.computeHashTime_ = 0; |
| + |
| + /** |
| + * Aggregate time spent performing content hash searches (in ms). |
| + * @private {number} |
| + */ |
| + this.searchHashTime_ = 0; |
| }; |
| +/** |
| + * @typedef {{ |
| + * computeHashTime: number, |
| + * searchHashTime: number |
| + * }} |
| + */ |
| +importer.DriveDuplicateFinder.Statistics; |
| + |
| /** @override */ |
| importer.DriveDuplicateFinder.prototype.checkDuplicate = function(entry) { |
| - return importer.DriveDuplicateFinder.computeHash_(entry) |
| + return this.computeHash_(entry) |
| .then(this.findByHash_.bind(this)) |
| .then( |
| /** |
| @@ -50,20 +80,24 @@ importer.DriveDuplicateFinder.prototype.checkDuplicate = function(entry) { |
| * @param {!FileEntry} entry |
| * @private |
| */ |
| -importer.DriveDuplicateFinder.computeHash_ = function(entry) { |
| +importer.DriveDuplicateFinder.prototype.computeHash_ = function(entry) { |
| return new Promise( |
| + /** @this {importer.DriveDuplicateFinder} */ |
| function(resolve, reject) { |
| + var startTime = new Date().getTime(); |
| chrome.fileManagerPrivate.computeChecksum( |
| entry.toURL(), |
| /** @param {string} result The content hash. */ |
| function(result) { |
| + var endTime = new Date().getTime(); |
| + this.searchHashTime_ += endTime - startTime; |
| if (chrome.runtime.lastError) { |
| reject(chrome.runtime.lastError); |
| } else { |
| resolve(result); |
| } |
| }); |
| - }); |
| + }.bind(this)); |
| }; |
| /** |
| @@ -75,7 +109,7 @@ importer.DriveDuplicateFinder.computeHash_ = function(entry) { |
| */ |
| importer.DriveDuplicateFinder.prototype.findByHash_ = function(hash) { |
| return this.getDriveId_() |
| - .then(importer.DriveDuplicateFinder.searchFilesByHash_.bind(null, hash)); |
| + .then(this.searchFilesByHash_.bind(this, hash)); |
| }; |
| /** |
| @@ -104,19 +138,46 @@ importer.DriveDuplicateFinder.prototype.getDriveId_ = function() { |
| * @param {string} volumeId The volume to search. |
| * @return <!Promise<Array<string>>> A list of file URLs. |
| */ |
| -importer.DriveDuplicateFinder.searchFilesByHash_ = function(hash, volumeId) { |
| +importer.DriveDuplicateFinder.prototype.searchFilesByHash_ = |
| + function(hash, volumeId) { |
| return new Promise( |
| + /** @this {importer.DriveDuplicateFinder} */ |
| function(resolve, reject) { |
| + var startTime = new Date().getTime(); |
| chrome.fileManagerPrivate.searchFilesByHashes( |
| volumeId, |
| [hash], |
| - /** @param {!Object<string, Array<string>>} urls */ |
| + /** |
| + * @param {!Object<string, Array<string>>} urls |
| + * @this {importer.DriveDuplicateFinder} |
| + */ |
| function(urls) { |
| + var endTime = new Date().getTime(); |
| + this.searchHashTime_ += endTime - startTime; |
| if (chrome.runtime.lastError) { |
| reject(chrome.runtime.lastError); |
| } else { |
| resolve(urls[hash]); |
| } |
| - }); |
| - }); |
| + }.bind(this)); |
| + }.bind(this)); |
| +}; |
| + |
| +/** @return {!importer.DriveDuplicateFinder.Statistics} */ |
| +importer.DriveDuplicateFinder.prototype.getStatistics = function() { |
| + return { |
| + computeHashTime: this.computeHashTime_, |
| + searchHashTime: this.searchHashTime_ |
| + }; |
| +}; |
| + |
| +/** |
| + * @constructor |
| + * @implements {importer.DuplicateFinder.Factory} |
| + */ |
| +importer.DriveDuplicateFinder.Factory = function() {}; |
| + |
| +/** @override */ |
| +importer.DriveDuplicateFinder.Factory.prototype.get = function() { |
|
Steve McKay
2015/02/12 17:59:14
/**
* @return {!importer.DriveDuplicateFinder}
*
Ben Kwa
2015/02/17 23:01:29
Acknowledged.
|
| + return new importer.DriveDuplicateFinder(); |
| }; |