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 return; |
| 111 } |
| 112 onSuccess(); |
| 113 }); |
| 114 } |
| 115 |
| 116 function onUnmountRequested(options, onSuccess, onError) { |
| 117 chrome.fileSystemProvider.unmount( |
| 118 {fileSystemId: options.fileSystemId}, |
| 119 function() { |
| 120 if (chrome.runtime.lastError) { |
| 121 onError(chrome.runtime.lastError.message); |
| 122 console.error('Failed to unmount because of: ' + |
| 123 chrome.runtime.lastError.message); |
| 124 return; |
| 125 } |
| 126 onSuccess(); |
| 127 }); |
| 128 } |
109 | 129 |
110 chrome.fileSystemProvider.onGetMetadataRequested.addListener( | 130 chrome.fileSystemProvider.onGetMetadataRequested.addListener( |
111 onGetMetadataRequested); | 131 onGetMetadataRequested); |
112 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( | 132 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( |
113 onReadDirectoryRequested); | 133 onReadDirectoryRequested); |
114 chrome.fileSystemProvider.onOpenFileRequested.addListener( | 134 chrome.fileSystemProvider.onOpenFileRequested.addListener(onOpenFileRequested); |
115 onOpenFileRequested); | |
116 chrome.fileSystemProvider.onCloseFileRequested.addListener( | 135 chrome.fileSystemProvider.onCloseFileRequested.addListener( |
117 onCloseFileRequested); | 136 onCloseFileRequested); |
118 chrome.fileSystemProvider.onReadFileRequested.addListener( | 137 chrome.fileSystemProvider.onReadFileRequested.addListener(onReadFileRequested); |
119 onReadFileRequested); | 138 chrome.fileSystemProvider.onMountRequested.addListener(onMountRequested); |
| 139 chrome.fileSystemProvider.onUnmountRequested.addListener(onUnmountRequested); |
OLD | NEW |