Commit 78d56d54 authored by mtomasz's avatar mtomasz Committed by Commit bot

Fix examples for File System Provider API.

TEST=Manually tested both.
BUG=481670

Review URL: https://codereview.chromium.org/1138503005

Cr-Commit-Position: refs/heads/master@{#330461}
parent 15beb32b
...@@ -41,12 +41,13 @@ function onUnmountRequested(options, onSuccess, onError) { ...@@ -41,12 +41,13 @@ function onUnmountRequested(options, onSuccess, onError) {
chrome.fileSystemProvider.unmount( chrome.fileSystemProvider.unmount(
{fileSystemId: options.fileSystemId}, {fileSystemId: options.fileSystemId},
function() { function() {
if (chrome.runtime.lastError) {
onError(chrome.runtime.lastError.message);
return;
}
delete volumes[options.fileSystemId]; delete volumes[options.fileSystemId];
saveState(); // Remove volume from local storage state. saveState(); // Remove volume from local storage state.
onSuccess(); onSuccess();
},
function() {
onError('FAILED');
}); });
}; };
...@@ -202,8 +203,14 @@ chrome.app.runtime.onLaunched.addListener(function(event) { ...@@ -202,8 +203,14 @@ chrome.app.runtime.onLaunched.addListener(function(event) {
volumes[displayPath] = new Volume(item.entry, metadata); volumes[displayPath] = new Volume(item.entry, metadata);
chrome.fileSystemProvider.mount( chrome.fileSystemProvider.mount(
{fileSystemId: displayPath, displayName: item.entry.name}, {fileSystemId: displayPath, displayName: item.entry.name},
function() { saveState(); }, function() {
function() { console.error('Failed to mount.'); }); if (chrome.runtime.lastError) {
console.error('Failed to mount because of: ' +
chrome.runtime.lastError.message);
return;
};
saveState();
});
}); });
}, },
function(error) { function(error) {
......
{ {
"/": { "/": {
"isDirectory": true, "isDirectory": true,
"name": "/", "name": "",
"size": 0, "size": 0,
"modificationTime": "2014-06-26T08:47:11.591Z" "modificationTime": "2014-06-26T08:47:11.591Z"
}, },
......
{ {
"/": { "/": {
"isDirectory": true, "isDirectory": true,
"name": "/", "name": "",
"size": 0, "size": 0,
"modificationTime": "2014-06-26T08:47:11.591Z" "modificationTime": "2014-06-26T08:47:11.591Z"
}, },
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
"title": "Open fake archive" "title": "Open fake archive"
} }
}, },
"file_system_provider_capabilities": {
"multiple_mounts": true,
"source": "file"
},
"app": { "app": {
"background": { "background": {
"scripts": [ "scripts": [
......
...@@ -10,7 +10,7 @@ var SHORT_CONTENTS = 'Just another example.'; ...@@ -10,7 +10,7 @@ var SHORT_CONTENTS = 'Just another example.';
var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.'; var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.';
var METADATA = { var METADATA = {
'/': {isDirectory: true, name: '/', size: 0, '/': {isDirectory: true, name: '', size: 0,
modificationTime: MODIFICATION_DATE}, modificationTime: MODIFICATION_DATE},
'/file1.txt': {isDirectory: false, name: 'file1.txt', '/file1.txt': {isDirectory: false, name: 'file1.txt',
size: LONGER_CONTENTS.length, modificationTime: MODIFICATION_DATE, size: LONGER_CONTENTS.length, modificationTime: MODIFICATION_DATE,
...@@ -99,21 +99,41 @@ function onReadFileRequested(options, onSuccess, onError) { ...@@ -99,21 +99,41 @@ function onReadFileRequested(options, onSuccess, onError) {
onSuccess(buffer, false /* Last call. */); onSuccess(buffer, false /* Last call. */);
} }
// Mount the file system. function onMountRequested(onSuccess, onError) {
chrome.runtime.onInstalled.addListener(function(details) {
chrome.fileSystemProvider.mount( chrome.fileSystemProvider.mount(
{fileSystemId: 'sample-file-system', displayName: 'Sample File System'}, {fileSystemId: 'sample-file-system', displayName: 'Sample File System'},
function() {}, function() {
function() { console.error('Failed to mount.'); }); if (chrome.runtime.lastError) {
}); onError(chrome.runtime.lastError.message);
console.error('Failed to mount because of: ' +
chrome.runtime.lastError.message);
return;
}
onSuccess();
});
}
function onUnmountRequested(options, onSuccess, onError) {
chrome.fileSystemProvider.unmount(
{fileSystemId: options.fileSystemId},
function() {
if (chrome.runtime.lastError) {
onError(chrome.runtime.lastError.message);
console.error('Failed to unmount because of: ' +
chrome.runtime.lastError.message);
return;
}
onSuccess();
});
}
chrome.fileSystemProvider.onGetMetadataRequested.addListener( chrome.fileSystemProvider.onGetMetadataRequested.addListener(
onGetMetadataRequested); onGetMetadataRequested);
chrome.fileSystemProvider.onReadDirectoryRequested.addListener( chrome.fileSystemProvider.onReadDirectoryRequested.addListener(
onReadDirectoryRequested); onReadDirectoryRequested);
chrome.fileSystemProvider.onOpenFileRequested.addListener( chrome.fileSystemProvider.onOpenFileRequested.addListener(onOpenFileRequested);
onOpenFileRequested);
chrome.fileSystemProvider.onCloseFileRequested.addListener( chrome.fileSystemProvider.onCloseFileRequested.addListener(
onCloseFileRequested); onCloseFileRequested);
chrome.fileSystemProvider.onReadFileRequested.addListener( chrome.fileSystemProvider.onReadFileRequested.addListener(onReadFileRequested);
onReadFileRequested); chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested);
chrome.fileSystemProvider.onUnmountRequested.addListener(onUnmountRequested);
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
"permissions": [ "permissions": [
"fileSystemProvider" "fileSystemProvider"
], ],
"file_system_provider_capabilities": {
"source": "network"
},
"background": { "background": {
"scripts": [ "scripts": [
"background.js" "background.js"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment