Commit 848cef88 authored by mtomasz's avatar mtomasz Committed by Commit bot

Remove watchers spam from log.

Not supporting file watchers is not an error. It's expected from eg. file
systems exposed via File System Provider API, especially those which are
read only.

TEST=Tested manually that watchers work and there is no spam in the log.
BUG=461735

Review URL: https://codereview.chromium.org/1150473002

Cr-Commit-Position: refs/heads/master@{#330697}
parent a58d60c7
...@@ -945,9 +945,8 @@ DirectoryModel.prototype.changeDirectoryEntry = function( ...@@ -945,9 +945,8 @@ DirectoryModel.prototype.changeDirectoryEntry = function(
this.currentDirContents_.cancelScan(); this.currentDirContents_.cancelScan();
this.directoryChangeQueue_.run(function(sequence, queueTaskCallback) { this.directoryChangeQueue_.run(function(sequence, queueTaskCallback) {
this.fileWatcher_.changeWatchedDirectory( this.fileWatcher_.changeWatchedDirectory(dirEntry)
dirEntry, .then(function() {
function() {
if (this.changeDirectorySequence_ !== sequence) { if (this.changeDirectorySequence_ !== sequence) {
queueTaskCallback(); queueTaskCallback();
return; return;
......
...@@ -29,7 +29,7 @@ FileWatcher.prototype.dispose = function() { ...@@ -29,7 +29,7 @@ FileWatcher.prototype.dispose = function() {
chrome.fileManagerPrivate.onDirectoryChanged.removeListener( chrome.fileManagerPrivate.onDirectoryChanged.removeListener(
this.onDirectoryChangedBound_); this.onDirectoryChangedBound_);
if (this.watchedDirectoryEntry_) if (this.watchedDirectoryEntry_)
this.resetWatchedEntry_(function() {}, function() {}); this.resetWatchedEntry_();
}; };
/** /**
...@@ -71,87 +71,80 @@ FileWatcher.prototype.onDirectoryChanged_ = function(event) { ...@@ -71,87 +71,80 @@ FileWatcher.prototype.onDirectoryChanged_ = function(event) {
* *
* @param {!DirectoryEntry|!FakeEntry} entry Directory entry to be tracked, or * @param {!DirectoryEntry|!FakeEntry} entry Directory entry to be tracked, or
* the fake entry. * the fake entry.
* @param {function()} callback Completion callback. * @return {!Promise}
*/ */
FileWatcher.prototype.changeWatchedDirectory = function(entry, callback) { FileWatcher.prototype.changeWatchedDirectory = function(entry) {
if (!util.isFakeEntry(entry)) { if (!util.isFakeEntry(entry))
this.changeWatchedEntry_( return this.changeWatchedEntry_(/** @type {!DirectoryEntry} */ (entry));
/** @type {!DirectoryEntry} */ (entry), else
callback, return this.resetWatchedEntry_();
function() {
console.error(
'Unable to change the watched directory to: ' + entry.toURL());
callback();
});
} else {
this.resetWatchedEntry_(
callback,
function() {
console.error('Unable to reset the watched directory.');
callback();
});
}
}; };
/** /**
* Resets the watched entry to the passed directory. * Resets the watched entry. It's a best effort method.
* * @return {!Promise}
* @param {function()} onSuccess Success callback.
* @param {function()} onError Error callback.
* @private * @private
*/ */
FileWatcher.prototype.resetWatchedEntry_ = function(onSuccess, onError) { FileWatcher.prototype.resetWatchedEntry_ = function() {
// Run the tasks in the queue to avoid races. // Run the tasks in the queue to avoid races.
this.queue_.run(function(callback) { return new Promise(function(fulfill, reject) {
// Release the watched directory. this.queue_.run(function(callback) {
if (this.watchedDirectoryEntry_) { // Release the watched directory.
chrome.fileManagerPrivate.removeFileWatch( if (this.watchedDirectoryEntry_) {
this.watchedDirectoryEntry_.toURL(), chrome.fileManagerPrivate.removeFileWatch(
function(result) { this.watchedDirectoryEntry_.toURL(),
this.watchedDirectoryEntry_ = null; function(result) {
if (result) if (chrome.runtime.lastError) {
onSuccess(); console.error('Failed to remove the watcher because of: ' +
else chrome.runtime.lastError.message);
onError(); }
callback(); // Even on error reset the watcher locally, so at least the
}.bind(this)); // notifications are discarded.
} else { this.watchedDirectoryEntry_ = null;
onSuccess(); fulfill();
callback(); callback();
} }.bind(this));
} else {
fulfill();
callback();
}
}.bind(this));
}.bind(this)); }.bind(this));
}; };
/** /**
* Sets the watched entry to the passed directory. * Sets the watched entry to the passed directory. It's a best effort method.
*
* @param {!DirectoryEntry} entry Directory to be watched. * @param {!DirectoryEntry} entry Directory to be watched.
* @param {function()} onSuccess Success callback. * @return {!Promise}
* @param {function()} onError Error callback.
* @private * @private
*/ */
FileWatcher.prototype.changeWatchedEntry_ = function( FileWatcher.prototype.changeWatchedEntry_ = function(entry) {
entry, onSuccess, onError) { return new Promise(function(fulfill, reject) {
var setEntryClosure = function() { var setEntryClosure = function() {
// Run the tasks in the queue to avoid races. // Run the tasks in the queue to avoid races.
this.queue_.run(function(callback) { this.queue_.run(function(callback) {
chrome.fileManagerPrivate.addFileWatch( chrome.fileManagerPrivate.addFileWatch(
entry.toURL(), entry.toURL(),
function(result) { function(result) {
if (!result) { if (chrome.runtime.lastError) {
this.watchedDirectoryEntry_ = null; // Most probably setting the watcher is not supported on the
onError(); // file system type.
} else { console.info('File watchers not supported for: ' +
this.watchedDirectoryEntry_ = entry; entry.toURL());
onSuccess(); this.watchedDirectoryEntry_ = null;
} fulfill();
callback(); } else {
}.bind(this)); this.watchedDirectoryEntry_ = assert(entry);
}.bind(this)); fulfill();
}.bind(this); }
callback();
}.bind(this));
}.bind(this));
}.bind(this);
// Reset the watched directory first, then set the new watched directory. // Reset the watched directory first, then set the new watched directory.
this.resetWatchedEntry_(setEntryClosure, onError); return this.resetWatchedEntry_().then(setEntryClosure);
}.bind(this));
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment