| 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 // Metadata is stored in files as serialized to JSON maps. See contents of | 7 // Metadata is stored in files as serialized to JSON maps. See contents of |
| 8 // example1.fake and example2.fake. | 8 // example1.fake and example2.fake. |
| 9 | 9 |
| 10 // Multiple volumes can be opened at the same time. The key is the | 10 // Multiple volumes can be opened at the same time. The key is the |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 function onUnmountRequested(options, onSuccess, onError) { | 35 function onUnmountRequested(options, onSuccess, onError) { |
| 36 if (Object.keys(volumes[options.fileSystemId].openedFiles).length != 0) { | 36 if (Object.keys(volumes[options.fileSystemId].openedFiles).length != 0) { |
| 37 onError('IN_USE'); | 37 onError('IN_USE'); |
| 38 return; | 38 return; |
| 39 } | 39 } |
| 40 | 40 |
| 41 chrome.fileSystemProvider.unmount( | 41 chrome.fileSystemProvider.unmount( |
| 42 {fileSystemId: options.fileSystemId}, | 42 {fileSystemId: options.fileSystemId}, |
| 43 function() { | 43 function() { |
| 44 if (chrome.runtime.lastError) { |
| 45 onError(chrome.runtime.lastError.message); |
| 46 return; |
| 47 } |
| 44 delete volumes[options.fileSystemId]; | 48 delete volumes[options.fileSystemId]; |
| 45 saveState(); // Remove volume from local storage state. | 49 saveState(); // Remove volume from local storage state. |
| 46 onSuccess(); | 50 onSuccess(); |
| 47 }, | |
| 48 function() { | |
| 49 onError('FAILED'); | |
| 50 }); | 51 }); |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 function onGetMetadataRequested(options, onSuccess, onError) { | 54 function onGetMetadataRequested(options, onSuccess, onError) { |
| 54 restoreState(options.fileSystemId, function () { | 55 restoreState(options.fileSystemId, function () { |
| 55 var entryMetadata = | 56 var entryMetadata = |
| 56 volumes[options.fileSystemId].metadata[options.entryPath]; | 57 volumes[options.fileSystemId].metadata[options.entryPath]; |
| 57 if (!entryMetadata) | 58 if (!entryMetadata) |
| 58 error('NOT_FOUND'); | 59 error('NOT_FOUND'); |
| 59 else | 60 else |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 event.items.forEach(function(item) { | 196 event.items.forEach(function(item) { |
| 196 readMetadataFromFile(item.entry, | 197 readMetadataFromFile(item.entry, |
| 197 function(metadata) { | 198 function(metadata) { |
| 198 // Mount the volume and save its information in local storage | 199 // Mount the volume and save its information in local storage |
| 199 // in order to be able to recover the metadata in case of | 200 // in order to be able to recover the metadata in case of |
| 200 // restarts, system crashes, etc. | 201 // restarts, system crashes, etc. |
| 201 chrome.fileSystem.getDisplayPath(item.entry, function(displayPath) { | 202 chrome.fileSystem.getDisplayPath(item.entry, function(displayPath) { |
| 202 volumes[displayPath] = new Volume(item.entry, metadata); | 203 volumes[displayPath] = new Volume(item.entry, metadata); |
| 203 chrome.fileSystemProvider.mount( | 204 chrome.fileSystemProvider.mount( |
| 204 {fileSystemId: displayPath, displayName: item.entry.name}, | 205 {fileSystemId: displayPath, displayName: item.entry.name}, |
| 205 function() { saveState(); }, | 206 function() { |
| 206 function() { console.error('Failed to mount.'); }); | 207 if (chrome.runtime.lastError) { |
| 208 console.error('Failed to mount because of: ' + |
| 209 chrome.runtime.lastError.message); |
| 210 return; |
| 211 }; |
| 212 saveState(); |
| 213 }); |
| 207 }); | 214 }); |
| 208 }, | 215 }, |
| 209 function(error) { | 216 function(error) { |
| 210 console.error(error); | 217 console.error(error); |
| 211 }); | 218 }); |
| 212 }); | 219 }); |
| 213 }); | 220 }); |
| 214 | 221 |
| 215 // Event called on a profile startup. | 222 // Event called on a profile startup. |
| 216 chrome.runtime.onStartup.addListener(function () { | 223 chrome.runtime.onStartup.addListener(function () { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 238 chrome.fileSystemProvider.onGetMetadataRequested.addListener( | 245 chrome.fileSystemProvider.onGetMetadataRequested.addListener( |
| 239 onGetMetadataRequested); | 246 onGetMetadataRequested); |
| 240 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( | 247 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( |
| 241 onReadDirectoryRequested); | 248 onReadDirectoryRequested); |
| 242 chrome.fileSystemProvider.onOpenFileRequested.addListener( | 249 chrome.fileSystemProvider.onOpenFileRequested.addListener( |
| 243 onOpenFileRequested); | 250 onOpenFileRequested); |
| 244 chrome.fileSystemProvider.onCloseFileRequested.addListener( | 251 chrome.fileSystemProvider.onCloseFileRequested.addListener( |
| 245 onCloseFileRequested); | 252 onCloseFileRequested); |
| 246 chrome.fileSystemProvider.onReadFileRequested.addListener( | 253 chrome.fileSystemProvider.onReadFileRequested.addListener( |
| 247 onReadFileRequested); | 254 onReadFileRequested); |
| OLD | NEW |