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

Unified Diff: ui/file_manager/file_manager/background/js/device_handler.js

Issue 490643005: Files.app: Start to use DeviceEventRouter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 4 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/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 c24ce08f5133ea430e4b2f778406c0f40655587b..d7ba6bfb044348d4a865fd5e61d11b25604368da 100644
--- a/ui/file_manager/file_manager/background/js/device_handler.js
+++ b/ui/file_manager/file_manager/background/js/device_handler.js
@@ -97,13 +97,6 @@ DeviceHandler.Notification = function(prefix, title, message, opt_buttonLabel) {
*/
this.queue_ = new AsyncUtil.Queue();
- /**
- * Timeout ID.
- * @type {number}
- * @private
- */
- this.pendingShowTimerId_ = 0;
-
Object.seal(this);
};
@@ -189,7 +182,6 @@ DeviceHandler.Notification.FORMAT_FAIL = new DeviceHandler.Notification(
* @return {string} Notification ID.
*/
DeviceHandler.Notification.prototype.show = function(devicePath, opt_message) {
- this.clearTimeout_();
var notificationId = this.makeId_(devicePath);
this.queue_.run(function(callback) {
var buttons =
@@ -209,20 +201,10 @@ DeviceHandler.Notification.prototype.show = function(devicePath, opt_message) {
};
/**
- * Shows the notification after 5 seconds.
- * @param {string} devicePath Device path.
- */
-DeviceHandler.Notification.prototype.showLater = function(devicePath) {
- this.clearTimeout_();
- this.pendingShowTimerId_ = setTimeout(this.show.bind(this, devicePath), 5000);
-};
-
-/**
* Hides the notification for the device path.
* @param {string} devicePath Device path.
*/
DeviceHandler.Notification.prototype.hide = function(devicePath) {
- this.clearTimeout_();
this.queue_.run(function(callback) {
chrome.notifications.clear(this.makeId_(devicePath), callback);
}.bind(this));
@@ -239,35 +221,22 @@ DeviceHandler.Notification.prototype.makeId_ = function(devicePath) {
};
/**
- * Cancels the timeout request.
- * @private
- */
-DeviceHandler.Notification.prototype.clearTimeout_ = function() {
- if (this.pendingShowTimerId_) {
- clearTimeout(this.pendingShowTimerId_);
- this.pendingShowTimerId_ = 0;
- }
-};
-
-/**
* Handles notifications from C++ sides.
* @param {DeviceEvent} event Device event.
* @private
*/
DeviceHandler.prototype.onDeviceChanged_ = function(event) {
switch (event.type) {
- case 'added':
- if (!this.isStartup_)
- DeviceHandler.Notification.DEVICE.showLater(event.devicePath);
- this.mountStatus_[event.devicePath] = DeviceHandler.MountStatus.NO_RESULT;
+ case 'scan_started':
+ DeviceHandler.Notification.DEVICE.show(event.devicePath);
+ break;
+ case 'scan_cancelled':
+ DeviceHandler.Notification.DEVICE.hide(event.devicePath);
break;
case 'disabled':
DeviceHandler.Notification.DEVICE_EXTERNAL_STORAGE_DISABLED.show(
event.devicePath);
break;
- case 'scan_canceled':
- DeviceHandler.Notification.DEVICE.hide(event.devicePath);
- break;
case 'removed':
DeviceHandler.Notification.DEVICE.hide(event.devicePath);
DeviceHandler.Notification.DEVICE_FAIL.hide(event.devicePath);
@@ -292,6 +261,9 @@ DeviceHandler.prototype.onDeviceChanged_ = function(event) {
DeviceHandler.Notification.FORMAT_START.hide(event.devicePath);
DeviceHandler.Notification.FORMAT_FAIL.show(event.devicePath);
break;
+ default:
+ console.error('Unknown event tyep: ' + event.type);
+ break;
}
};
@@ -324,12 +296,13 @@ DeviceHandler.prototype.onMountCompleted_ = function(event) {
// If this is remounting, which happens when resuming ChromeOS, the device has
// already inserted to the computer. So we suppress the notification.
var volume = event.volumeMetadata;
- if (!volume.deviceType || event.isRemounting)
+ if (!volume.deviceType || !event.shouldNotify)
return;
// If the current volume status is succeed and it should be handled in
// Files.app, show the notification to navigate the volume.
- if (event.status === 'success' && event.shouldNotify) {
+ 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
@@ -366,10 +339,9 @@ DeviceHandler.prototype.onMountCompleted_ = function(event) {
};
// Update the current status.
+ if (!this.mountStatus_[volume.devicePath])
+ this.mountStatus_[volume.devicePath] = DeviceHandler.MountStatus.NO_RESULT;
switch (this.mountStatus_[volume.devicePath]) {
- // If there is no related device, do nothing.
- case undefined:
- return;
// If the multipart error message has already shown, do nothing because the
// message does not changed by the following mount results.
case DeviceHandler.MountStatus.MULTIPART_ERROR:

Powered by Google App Engine
This is Rietveld 408576698