OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Handler of the background page for the drive sync events. | 8 * Handler of the background page for the drive sync events. |
9 * @param {ProgressCenter} progressCenter Progress center to submit the | 9 * @param {ProgressCenter} progressCenter Progress center to submit the |
10 * progressing items. | 10 * progressing items. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 get syncing() { | 77 get syncing() { |
78 return this.syncing_; | 78 return this.syncing_; |
79 } | 79 } |
80 }; | 80 }; |
81 | 81 |
82 /** | 82 /** |
83 * Handles file transfer updated events. | 83 * Handles file transfer updated events. |
84 * @param {Array.<FileTransferStatus>} statusList List of drive status. | 84 * @param {Array.<FileTransferStatus>} statusList List of drive status. |
85 * @private | 85 * @private |
86 */ | 86 */ |
87 DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) { | 87 DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(status) { |
88 var completed = false; | 88 switch (status.transferState) { |
89 for (var i = 0; i < statusList.length; i++) { | 89 case 'added': |
90 var status = statusList[i]; | 90 case 'in_progress': |
91 switch (status.transferState) { | 91 case 'started': |
92 case 'added': | 92 this.updateItem_(status); |
93 case 'in_progress': | 93 break; |
94 case 'started': | 94 case 'completed': |
95 this.updateItem_(status); | 95 case 'failed': |
96 break; | 96 if (status.num_total_jobs === 1) |
97 case 'completed': | 97 this.removeItem_(status); |
98 case 'failed': | 98 break; |
99 if (status.num_total_jobs === 1) | 99 default: |
100 this.removeItem_(status); | 100 throw new Error( |
101 break; | 101 'Invalid transfer state: ' + status.transferState + '.'); |
102 default: | |
103 throw new Error( | |
104 'Invalid transfer state: ' + status.transferState + '.'); | |
105 } | |
106 } | 102 } |
107 }; | 103 }; |
108 | 104 |
109 /** | 105 /** |
110 * Updates the item involved with the given status. | 106 * Updates the item involved with the given status. |
111 * @param {FileTransferStatus} status Transfer status. | 107 * @param {FileTransferStatus} status Transfer status. |
112 * @private | 108 * @private |
113 */ | 109 */ |
114 DriveSyncHandler.prototype.updateItem_ = function(status) { | 110 DriveSyncHandler.prototype.updateItem_ = function(status) { |
115 this.queue_.run(function(callback) { | 111 this.queue_.run(function(callback) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 case 'service_unavailable': | 178 case 'service_unavailable': |
183 item.message = str('SYNC_SERVICE_UNAVAILABLE_ERROR'); | 179 item.message = str('SYNC_SERVICE_UNAVAILABLE_ERROR'); |
184 break; | 180 break; |
185 case 'misc': | 181 case 'misc': |
186 item.message = strf('SYNC_MISC_ERROR', entry.name); | 182 item.message = strf('SYNC_MISC_ERROR', entry.name); |
187 break; | 183 break; |
188 } | 184 } |
189 this.progressCenter_.updateItem(item); | 185 this.progressCenter_.updateItem(item); |
190 }.bind(this)); | 186 }.bind(this)); |
191 }; | 187 }; |
OLD | NEW |