| Index: ui/file_manager/file_manager/background/js/device_handler.js
|
| diff --git a/ui/file_manager/file_manager/background/js/device_handler.js b/ui/file_manager/file_manager/background/js/device_handler.js
|
| index ddbc46b1d7c4382ff69f971f88321156c2ea9934..95e114054bf61f8a80bca05609bfae2e4fc31c21 100644
|
| --- a/ui/file_manager/file_manager/background/js/device_handler.js
|
| +++ b/ui/file_manager/file_manager/background/js/device_handler.js
|
| @@ -19,14 +19,6 @@ function DeviceHandler() {
|
| */
|
| this.mountStatus_ = {};
|
|
|
| - /**
|
| - * Map of device path and volumeId of the volume that should be navigated to
|
| - * from the 'device inserted' notification.
|
| - * @type {Object.<string, DirectoryEntry>}
|
| - * @private
|
| - */
|
| - this.navigationVolumes_ = {};
|
| -
|
| chrome.fileManagerPrivate.onDeviceChanged.addListener(
|
| this.onDeviceChanged_.bind(this));
|
| chrome.fileManagerPrivate.onMountCompleted.addListener(
|
| @@ -175,23 +167,54 @@ DeviceHandler.Notification.FORMAT_FAIL = new DeviceHandler.Notification(
|
| DeviceHandler.Notification.prototype.show = function(devicePath, opt_message) {
|
| var notificationId = this.makeId_(devicePath);
|
| this.queue_.run(function(callback) {
|
| - var buttons =
|
| - this.buttonLabel ? [{title: str(this.buttonLabel)}] : undefined;
|
| - chrome.notifications.create(
|
| - notificationId,
|
| - {
|
| - type: 'basic',
|
| - title: str(this.title),
|
| - message: opt_message || str(this.message),
|
| - iconUrl: chrome.runtime.getURL('/common/images/icon96.png'),
|
| - buttons: buttons
|
| - },
|
| - callback);
|
| + this.showInternal_(notificationId, opt_message || null, callback);
|
| }.bind(this));
|
| return notificationId;
|
| };
|
|
|
| /**
|
| + * Shows the notification for the device path.
|
| + * If the existing notification has been already shown, it does not anything.
|
| + * @param {string} devicePath Device path.
|
| + */
|
| +DeviceHandler.Notification.prototype.showOnce = function(devicePath) {
|
| + var notificationId = this.makeId_(devicePath);
|
| + this.queue_.run(function(callback) {
|
| + chrome.notifications.getAll(function(idList) {
|
| + if (idList.indexOf(notificationId) !== -1) {
|
| + callback();
|
| + return;
|
| + }
|
| + this.showInternal_(notificationId, null, callback);
|
| + }.bind(this));
|
| + });
|
| +};
|
| +
|
| +/**
|
| + * Shows the notificaiton without using AsyncQueue.
|
| + * @param {string} notificaitonId Notification ID.
|
| + * @param {?message} message Message overriding the normal message.
|
| + * @param {function()} callback Callback to be invoked when the notification is
|
| + * created.
|
| + * @private
|
| + */
|
| +DeviceHandler.Notification.prototype.showInternal_ = function(
|
| + notificationId, message, callback) {
|
| + var buttons =
|
| + this.buttonLabel ? [{title: str(this.buttonLabel)}] : undefined;
|
| + chrome.notifications.create(
|
| + notificationId,
|
| + {
|
| + type: 'basic',
|
| + title: str(this.title),
|
| + message: message || str(this.message),
|
| + iconUrl: chrome.runtime.getURL('/common/images/icon96.png'),
|
| + buttons: buttons
|
| + },
|
| + callback);
|
| +};
|
| +
|
| +/**
|
| * Hides the notification for the device path.
|
| * @param {string} devicePath Device path.
|
| */
|
| @@ -283,34 +306,10 @@ DeviceHandler.prototype.onMountCompleted_ = function(event) {
|
|
|
| // If the current volume status is succeed and it should be handled in
|
| // Files.app, show the notification to navigate the volume.
|
| - if (event.eventType === 'mount' &&
|
| - event.status === 'success') {
|
| - if (this.navigationVolumes_[event.volumeMetadata.devicePath]) {
|
| - // The notification has already shown for the device. It seems the device
|
| - // has multiple volumes. The order of mount events of volumes are
|
| - // undetermind, so it compares the volume Id and uses the earier order ID
|
| - // to prevent Files.app from navigating to different volumes for each
|
| - // time.
|
| - if (event.volumeMetadata.volumeId <
|
| - this.navigationVolumes_[event.volumeMetadata.devicePath]) {
|
| - this.navigationVolumes_[event.volumeMetadata.devicePath] =
|
| - event.volumeMetadata.volumeId;
|
| - }
|
| - } else {
|
| - this.navigationVolumes_[event.volumeMetadata.devicePath] =
|
| - event.volumeMetadata.volumeId;
|
| - DeviceHandler.Notification.DEVICE_NAVIGATION.show(
|
| - event.volumeMetadata.devicePath);
|
| - }
|
| - } else if (event.status === 'error_unknown_filesystem') {
|
| - // The volume id is necessary to navigate when users click start
|
| - // format button.
|
| - this.navigationVolumes_[event.volumeMetadata.devicePath] =
|
| - event.volumeMetadata.volumeId;
|
| - }
|
| -
|
| - if (event.eventType === 'unmount') {
|
| - this.navigationVolumes_[volume.devicePath] = null;
|
| + if (event.eventType === 'mount' && event.status === 'success') {
|
| + DeviceHandler.Notification.DEVICE_NAVIGATION.show(
|
| + event.volumeMetadata.devicePath);
|
| + } else if (event.eventType === 'unmount') {
|
| DeviceHandler.Notification.DEVICE_NAVIGATION.hide(volume.devicePath);
|
| }
|
|
|
| @@ -402,11 +401,11 @@ DeviceHandler.prototype.onMountCompleted_ = function(event) {
|
| DeviceHandler.prototype.onNotificationButtonClicked_ = function(id) {
|
| var pos = id.indexOf(':');
|
| var type = id.substr(0, pos);
|
| - var path = id.substr(pos + 1);
|
| + var devicePath = id.substr(pos + 1);
|
| if (type === 'deviceNavigation' || type === 'deviceFail') {
|
| chrome.notifications.clear(id, function() {});
|
| var event = new Event(DeviceHandler.VOLUME_NAVIGATION_REQUESTED);
|
| - event.volumeId = this.navigationVolumes_[path];
|
| + event.devicePath = devicePath;
|
| this.dispatchEvent(event);
|
| }
|
| };
|
|
|