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) {
chrome.fileSystemProvider.unmount(
{fileSystemId: options.fileSystemId},
function() {
if (chrome.runtime.lastError) {
onError(chrome.runtime.lastError.message);
return;
}
delete volumes[options.fileSystemId];
saveState(); // Remove volume from local storage state.
onSuccess();
},
function() {
onError('FAILED');
});
};
......@@ -202,8 +203,14 @@ chrome.app.runtime.onLaunched.addListener(function(event) {
volumes[displayPath] = new Volume(item.entry, metadata);
chrome.fileSystemProvider.mount(
{fileSystemId: displayPath, displayName: item.entry.name},
function() { saveState(); },
function() { console.error('Failed to mount.'); });
function() {
if (chrome.runtime.lastError) {
console.error('Failed to mount because of: ' +
chrome.runtime.lastError.message);
return;
};
saveState();
});
});
},
function(error) {
......
{
"/": {
"isDirectory": true,
"name": "/",
"name": "",
"size": 0,
"modificationTime": "2014-06-26T08:47:11.591Z"
},
......
{
"/": {
"isDirectory": true,
"name": "/",
"name": "",
"size": 0,
"modificationTime": "2014-06-26T08:47:11.591Z"
},
......
......@@ -15,6 +15,10 @@
"title": "Open fake archive"
}
},
"file_system_provider_capabilities": {
"multiple_mounts": true,
"source": "file"
},
"app": {
"background": {
"scripts": [
......
......@@ -10,7 +10,7 @@ var SHORT_CONTENTS = 'Just another example.';
var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.';
var METADATA = {
'/': {isDirectory: true, name: '/', size: 0,
'/': {isDirectory: true, name: '', size: 0,
modificationTime: MODIFICATION_DATE},
'/file1.txt': {isDirectory: false, name: 'file1.txt',
size: LONGER_CONTENTS.length, modificationTime: MODIFICATION_DATE,
......@@ -99,21 +99,41 @@ function onReadFileRequested(options, onSuccess, onError) {
onSuccess(buffer, false /* Last call. */);
}
// Mount the file system.
chrome.runtime.onInstalled.addListener(function(details) {
function onMountRequested(onSuccess, onError) {
chrome.fileSystemProvider.mount(
{fileSystemId: 'sample-file-system', displayName: 'Sample File System'},
function() {},
function() { console.error('Failed to mount.'); });
});
function() {
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(
onGetMetadataRequested);
chrome.fileSystemProvider.onReadDirectoryRequested.addListener(
onReadDirectoryRequested);
chrome.fileSystemProvider.onOpenFileRequested.addListener(
onOpenFileRequested);
chrome.fileSystemProvider.onOpenFileRequested.addListener(onOpenFileRequested);
chrome.fileSystemProvider.onCloseFileRequested.addListener(
onCloseFileRequested);
chrome.fileSystemProvider.onReadFileRequested.addListener(
onReadFileRequested);
chrome.fileSystemProvider.onReadFileRequested.addListener(onReadFileRequested);
chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested);
chrome.fileSystemProvider.onUnmountRequested.addListener(onUnmountRequested);
......@@ -7,6 +7,9 @@
"permissions": [
"fileSystemProvider"
],
"file_system_provider_capabilities": {
"source": "network"
},
"background": {
"scripts": [
"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