Commit 22091668 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Hide the Drive sync progress when the connection state becomes offline.

Bug: 797709
Change-Id: I7d0be2bd48d0ff5fd5288f1abd23657f5a77a7fe
Reviewed-on: https://chromium-review.googlesource.com/c/1341769
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609548}
parent 37b6a864
...@@ -82,6 +82,8 @@ function DriveSyncHandler(progressCenter) { ...@@ -82,6 +82,8 @@ function DriveSyncHandler(progressCenter) {
this.onNotificationButtonClicked_.bind(this)); this.onNotificationButtonClicked_.bind(this));
chrome.fileManagerPrivate.onPreferencesChanged.addListener( chrome.fileManagerPrivate.onPreferencesChanged.addListener(
this.onPreferencesChanged_.bind(this)); this.onPreferencesChanged_.bind(this));
chrome.fileManagerPrivate.onDriveConnectionStatusChanged.addListener(
this.onDriveConnectionStatusChanged_.bind(this));
// Set initial values. // Set initial values.
this.onPreferencesChanged_(); this.onPreferencesChanged_();
...@@ -284,3 +286,22 @@ DriveSyncHandler.prototype.onPreferencesChanged_ = function() { ...@@ -284,3 +286,22 @@ DriveSyncHandler.prototype.onPreferencesChanged_ = function() {
this.cellularDisabled_ = pref.cellularDisabled; this.cellularDisabled_ = pref.cellularDisabled;
}.bind(this)); }.bind(this));
}; };
/**
* Handles connection state change.
* @private
*/
DriveSyncHandler.prototype.onDriveConnectionStatusChanged_ = function() {
chrome.fileManagerPrivate.getDriveConnectionState((state) => {
// If offline, hide any sync progress notifications. When online again, the
// Drive sync client may retry syncing and trigger onFileTransfersUpdated
// events, causing it to be shown again.
if (state.type == 'offline' && state.reason == 'no_network' &&
this.syncing_) {
this.syncing_ = false;
this.item_.state = ProgressItemState.CANCELED;
this.progressCenter_.updateItem(this.item_);
this.dispatchEvent(new Event(DriveSyncHandler.COMPLETED_EVENT));
}
});
};
...@@ -42,8 +42,22 @@ chrome.fileManagerPrivate = { ...@@ -42,8 +42,22 @@ chrome.fileManagerPrivate = {
}, },
listener_: null listener_: null
}, },
onDriveConnectionStatusChanged: {
addListener: function(callback) {
chrome.fileManagerPrivate.onDriveConnectionStatusChanged.listener_ =
callback;
},
removeListener: function() {
chrome.fileManagerPrivate.onDriveConnectionStatusChanged.listener_ = null;
},
listener_: null
},
getPreferences: function() {}, getPreferences: function() {},
setPreferences: function() {}, setPreferences: function() {},
getDriveConnectionState: function(callback) {
callback({type: 'offline', reason: 'no_network'});
},
}; };
/** /**
...@@ -122,3 +136,29 @@ function testErrorDedupe() { ...@@ -122,3 +136,29 @@ function testErrorDedupe() {
// Check that this created second item. // Check that this created second item.
assertEquals(1, Object.keys(progressCenter.items).length); assertEquals(1, Object.keys(progressCenter.items).length);
} }
// Test offline.
function testOffline() {
// Start a transfer.
chrome.fileManagerPrivate.onFileTransfersUpdated.listener_({
fileUrl: 'name',
transferState: 'in_progress',
processed: 50.0,
total: 100.0,
numTotalJobs: 1,
hideWhenZeroJobs: true,
});
// Check that this created one item.
assertEquals(1, Object.keys(progressCenter.items).length);
assertEquals(
ProgressItemState.PROGRESSING, progressCenter.items['drive-sync'].state);
assertTrue(handler.syncing);
chrome.fileManagerPrivate.onDriveConnectionStatusChanged.listener_();
assertEquals(1, Object.keys(progressCenter.items).length);
assertEquals(
ProgressItemState.CANCELED, progressCenter.items['drive-sync'].state);
assertFalse(handler.syncing);
}
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