| 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 /** | 5 /** |
| 6 * Object representing an image item (a photo). | 6 * Object representing an image item (a photo). |
| 7 * | 7 * |
| 8 * @param {!FileEntry} entry Image entry. | 8 * @param {!FileEntry} entry Image entry. |
| 9 * @param {!EntryLocation} locationInfo Entry location information. | 9 * @param {!EntryLocation} locationInfo Entry location information. |
| 10 * @param {!MetadataItem} metadataItem | 10 * @param {!MetadataItem} metadataItem |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 }).then(function() { | 299 }).then(function() { |
| 300 // Writes the blob of new image. | 300 // Writes the blob of new image. |
| 301 return new Promise(function(fulfill, reject) { | 301 return new Promise(function(fulfill, reject) { |
| 302 fileWriter.onerror = reject; | 302 fileWriter.onerror = reject; |
| 303 fileWriter.onwriteend = fulfill; | 303 fileWriter.onwriteend = fulfill; |
| 304 fileWriter.write(blob); | 304 fileWriter.write(blob); |
| 305 }); | 305 }); |
| 306 }).then(onSuccess.bind(null, fileEntry)) | 306 }).then(onSuccess.bind(null, fileEntry)) |
| 307 .catch(function(error) { | 307 .catch(function(error) { |
| 308 onError(error); | 308 onError(error); |
| 309 // Disable all callbacks on the first error. | 309 if (fileWriter) { |
| 310 fileWriter.onerror = null; | 310 // Disable all callbacks on the first error. |
| 311 fileWriter.onwriteend = null; | 311 fileWriter.onerror = null; |
| 312 fileWriter.onwriteend = null; |
| 313 } |
| 312 }); | 314 }); |
| 313 }.bind(this); | 315 }.bind(this); |
| 314 | 316 |
| 315 var getFile = function(dir, newFile) { | 317 var getFile = function(dir, newFile) { |
| 316 dir.getFile(name, {create: newFile, exclusive: newFile}, | 318 dir.getFile(name, {create: newFile, exclusive: newFile}, |
| 317 function(fileEntry) { | 319 function(fileEntry) { |
| 318 doSave(newFile, fileEntry); | 320 doSave(newFile, fileEntry); |
| 319 }.bind(this), onError); | 321 }.bind(this), onError); |
| 320 }.bind(this); | 322 }.bind(this); |
| 321 | 323 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 return Promise.reject(str('GALLERY_FILE_EXISTS')); | 375 return Promise.reject(str('GALLERY_FILE_EXISTS')); |
| 374 }, function() { | 376 }, function() { |
| 375 return new Promise( | 377 return new Promise( |
| 376 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); | 378 this.entry_.moveTo.bind(this.entry_, parentDirectory, newFileName)); |
| 377 }.bind(this)); | 379 }.bind(this)); |
| 378 }.bind(this)); | 380 }.bind(this)); |
| 379 }.bind(this)).then(function(entry) { | 381 }.bind(this)).then(function(entry) { |
| 380 this.entry_ = entry; | 382 this.entry_ = entry; |
| 381 }.bind(this)); | 383 }.bind(this)); |
| 382 }; | 384 }; |
| OLD | NEW |