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 // Fake data similar to a file system structure. | 7 // Fake data similar to a file system structure. |
8 var MODIFICATION_DATE = new Date(); | 8 var MODIFICATION_DATE = new Date(); |
9 var SHORT_CONTENTS = 'Just another example.'; | 9 var SHORT_CONTENTS = 'Just another example.'; |
10 var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.'; | 10 var LONGER_CONTENTS = 'It works!\nEverything gets displayed correctly.'; |
11 | 11 |
12 var METADATA = { | 12 var METADATA = { |
13 '/': {isDirectory: true, name: '/', size: 0, | 13 '/': {isDirectory: true, name: '', size: 0, |
14 modificationTime: MODIFICATION_DATE}, | 14 modificationTime: MODIFICATION_DATE}, |
15 '/file1.txt': {isDirectory: false, name: 'file1.txt', | 15 '/file1.txt': {isDirectory: false, name: 'file1.txt', |
16 size: LONGER_CONTENTS.length, modificationTime: MODIFICATION_DATE, | 16 size: LONGER_CONTENTS.length, modificationTime: MODIFICATION_DATE, |
17 contents: LONGER_CONTENTS}, | 17 contents: LONGER_CONTENTS}, |
18 '/file2': {isDirectory: false, name: 'file2', size: 150, | 18 '/file2': {isDirectory: false, name: 'file2', size: 150, |
19 modificationTime: MODIFICATION_DATE}, | 19 modificationTime: MODIFICATION_DATE}, |
20 '/dir': {isDirectory: true, name: 'dir', size: 0, | 20 '/dir': {isDirectory: true, name: 'dir', size: 0, |
21 modificationTime: MODIFICATION_DATE}, | 21 modificationTime: MODIFICATION_DATE}, |
22 '/dir/file3.txt': {isDirectory: false, name: 'file3.txt', | 22 '/dir/file3.txt': {isDirectory: false, name: 'file3.txt', |
23 size: SHORT_CONTENTS.length, modificationTime: MODIFICATION_DATE, | 23 size: SHORT_CONTENTS.length, modificationTime: MODIFICATION_DATE, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // Write the contents as ASCII text. | 92 // Write the contents as ASCII text. |
93 var buffer = new ArrayBuffer(options.length); | 93 var buffer = new ArrayBuffer(options.length); |
94 var bufferView = new Uint8Array(buffer); | 94 var bufferView = new Uint8Array(buffer); |
95 for (var i = 0; i < options.length; i++) { | 95 for (var i = 0; i < options.length; i++) { |
96 bufferView[i] = contents.charCodeAt(i); | 96 bufferView[i] = contents.charCodeAt(i); |
97 } | 97 } |
98 | 98 |
99 onSuccess(buffer, false /* Last call. */); | 99 onSuccess(buffer, false /* Last call. */); |
100 } | 100 } |
101 | 101 |
102 // Mount the file system. | 102 function onMountRequested(onSuccess, onError) { |
103 chrome.runtime.onInstalled.addListener(function(details) { | |
104 chrome.fileSystemProvider.mount( | 103 chrome.fileSystemProvider.mount( |
105 {fileSystemId: 'sample-file-system', displayName: 'Sample File System'}, | 104 {fileSystemId: 'sample-file-system', displayName: 'Sample File System'}, |
106 function() {}, | 105 function() { |
107 function() { console.error('Failed to mount.'); }); | 106 if (chrome.runtime.lastError) { |
108 }); | 107 onError(chrome.runtime.lastError.message); |
108 console.error('Failed to mount because of: ' + | |
109 chrome.runtime.lastError.message); | |
110 } | |
111 }); | |
not at google - send to devlin
2015/05/18 20:00:54
do you want to call onSuccess anywhere here, and b
mtomasz
2015/05/19 00:42:54
Good catch, done.
| |
112 } | |
113 | |
114 function onUnmountRequested(options, onSuccess, onError) { | |
115 chrome.fileSystemProvider.unmount( | |
116 {fileSystemId: options.fileSystemId}, | |
117 function() { | |
118 if (chrome.runtime.lastError) { | |
119 onError(chrome.runtime.lastError.message); | |
120 console.error('Failed to unmount because of: ' + | |
121 chrome.runtime.lastError.message); | |
122 } | |
123 }); | |
124 } | |
109 | 125 |
110 chrome.fileSystemProvider.onGetMetadataRequested.addListener( | 126 chrome.fileSystemProvider.onGetMetadataRequested.addListener( |
111 onGetMetadataRequested); | 127 onGetMetadataRequested); |
112 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( | 128 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( |
113 onReadDirectoryRequested); | 129 onReadDirectoryRequested); |
114 chrome.fileSystemProvider.onOpenFileRequested.addListener( | 130 chrome.fileSystemProvider.onOpenFileRequested.addListener(onOpenFileRequested); |
115 onOpenFileRequested); | |
116 chrome.fileSystemProvider.onCloseFileRequested.addListener( | 131 chrome.fileSystemProvider.onCloseFileRequested.addListener( |
117 onCloseFileRequested); | 132 onCloseFileRequested); |
118 chrome.fileSystemProvider.onReadFileRequested.addListener( | 133 chrome.fileSystemProvider.onReadFileRequested.addListener(onReadFileRequested); |
119 onReadFileRequested); | 134 chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested); |
135 chrome.fileSystemProvider.onUnmountRequested.addListener(onUnmountRequested); | |
OLD | NEW |