| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Custom binding for the fileSystemProvider API. | 5 // Custom binding for the fileSystemProvider API. |
| 6 | 6 |
| 7 var binding = require('binding').Binding.create('fileSystemProvider'); | 7 var binding = require('binding').Binding.create('fileSystemProvider'); |
| 8 var fileSystemProviderInternal = | 8 var fileSystemProviderInternal = |
| 9 require('binding').Binding.create('fileSystemProviderInternal').generate(); | 9 require('binding').Binding.create('fileSystemProviderInternal').generate(); |
| 10 var eventBindings = require('event_bindings'); | 10 var eventBindings = require('event_bindings'); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 isDirectory: metadata.isDirectory, | 34 isDirectory: metadata.isDirectory, |
| 35 name: metadata.name, | 35 name: metadata.name, |
| 36 size: metadata.size, | 36 size: metadata.size, |
| 37 modificationTime: annotateDate(metadata.modificationTime) | 37 modificationTime: annotateDate(metadata.modificationTime) |
| 38 }; | 38 }; |
| 39 if ('mimeType' in metadata) | 39 if ('mimeType' in metadata) |
| 40 result.mimeType = metadata.mimeType; | 40 result.mimeType = metadata.mimeType; |
| 41 return result; | 41 return result; |
| 42 } | 42 } |
| 43 | 43 |
| 44 /** |
| 45 * Massages arguments of an event raised by the File System Provider API. |
| 46 * @param {Array.<*>} args Input arguments. |
| 47 * @param {function(Array.<*>)} dispatch Closure to be called with massaged |
| 48 * arguments. |
| 49 */ |
| 50 function massageArgumentsDefault(args, dispatch) { |
| 51 var executionStart = Date.now(); |
| 52 var options = args[0]; |
| 53 var onSuccessCallback = function(hasNext) { |
| 54 fileSystemProviderInternal.operationRequestedSuccess( |
| 55 options.fileSystemId, options.requestId, Date.now() - executionStart); |
| 56 }; |
| 57 var onErrorCallback = function(error) { |
| 58 fileSystemProviderInternal.operationRequestedError( |
| 59 options.fileSystemId, options.requestId, error, |
| 60 Date.now() - executionStart); |
| 61 } |
| 62 dispatch([options, onSuccessCallback, onErrorCallback]); |
| 63 } |
| 64 |
| 65 |
| 44 binding.registerCustomHook(function(bindingsAPI) { | 66 binding.registerCustomHook(function(bindingsAPI) { |
| 45 var apiFunctions = bindingsAPI.apiFunctions; | 67 var apiFunctions = bindingsAPI.apiFunctions; |
| 46 | 68 |
| 47 apiFunctions.setUpdateArgumentsPostValidate( | 69 apiFunctions.setUpdateArgumentsPostValidate( |
| 48 'mount', | 70 'mount', |
| 49 function(options, successCallback, errorCallback) { | 71 function(options, successCallback, errorCallback) { |
| 50 // Piggyback the error callback onto the success callback, | 72 // Piggyback the error callback onto the success callback, |
| 51 // so we can use the error callback later. | 73 // so we can use the error callback later. |
| 52 successCallback.errorCallback_ = errorCallback; | 74 successCallback.errorCallback_ = errorCallback; |
| 53 return [options, successCallback]; | 75 return [options, successCallback]; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (domError) | 126 if (domError) |
| 105 errorCallback(domError); | 127 errorCallback(domError); |
| 106 else | 128 else |
| 107 successCallback(); | 129 successCallback(); |
| 108 } | 130 } |
| 109 }); | 131 }); |
| 110 }); | 132 }); |
| 111 | 133 |
| 112 eventBindings.registerArgumentMassager( | 134 eventBindings.registerArgumentMassager( |
| 113 'fileSystemProvider.onUnmountRequested', | 135 'fileSystemProvider.onUnmountRequested', |
| 114 function(args, dispatch) { | 136 massageArgumentsDefault); |
| 115 var executionStart = Date.now(); | |
| 116 var options = args[0]; | |
| 117 var onSuccessCallback = function() { | |
| 118 fileSystemProviderInternal.unmountRequestedSuccess( | |
| 119 options.fileSystemId, options.requestId, | |
| 120 Date.now() - executionStart); | |
| 121 }; | |
| 122 var onErrorCallback = function(error) { | |
| 123 fileSystemProviderInternal.operationRequestedError( | |
| 124 options.fileSystemId, options.requestId, error, | |
| 125 Date.now() - executionStart); | |
| 126 } | |
| 127 dispatch([options, onSuccessCallback, onErrorCallback]); | |
| 128 }); | |
| 129 | 137 |
| 130 eventBindings.registerArgumentMassager( | 138 eventBindings.registerArgumentMassager( |
| 131 'fileSystemProvider.onGetMetadataRequested', | 139 'fileSystemProvider.onGetMetadataRequested', |
| 132 function(args, dispatch) { | 140 function(args, dispatch) { |
| 133 var executionStart = Date.now(); | 141 var executionStart = Date.now(); |
| 134 var options = args[0]; | 142 var options = args[0]; |
| 135 var onSuccessCallback = function(metadata) { | 143 var onSuccessCallback = function(metadata) { |
| 136 fileSystemProviderInternal.getMetadataRequestedSuccess( | 144 fileSystemProviderInternal.getMetadataRequestedSuccess( |
| 137 options.fileSystemId, | 145 options.fileSystemId, |
| 138 options.requestId, | 146 options.requestId, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 161 var onErrorCallback = function(error) { | 169 var onErrorCallback = function(error) { |
| 162 fileSystemProviderInternal.operationRequestedError( | 170 fileSystemProviderInternal.operationRequestedError( |
| 163 options.fileSystemId, options.requestId, error, | 171 options.fileSystemId, options.requestId, error, |
| 164 Date.now() - executionStart); | 172 Date.now() - executionStart); |
| 165 } | 173 } |
| 166 dispatch([options, onSuccessCallback, onErrorCallback]); | 174 dispatch([options, onSuccessCallback, onErrorCallback]); |
| 167 }); | 175 }); |
| 168 | 176 |
| 169 eventBindings.registerArgumentMassager( | 177 eventBindings.registerArgumentMassager( |
| 170 'fileSystemProvider.onOpenFileRequested', | 178 'fileSystemProvider.onOpenFileRequested', |
| 171 function(args, dispatch) { | 179 massageArgumentsDefault); |
| 172 var executionStart = Date.now(); | |
| 173 var options = args[0]; | |
| 174 var onSuccessCallback = function() { | |
| 175 fileSystemProviderInternal.operationRequestedSuccess( | |
| 176 options.fileSystemId, options.requestId, | |
| 177 Date.now() - executionStart); | |
| 178 }; | |
| 179 var onErrorCallback = function(error) { | |
| 180 fileSystemProviderInternal.operationRequestedError( | |
| 181 options.fileSystemId, options.requestId, error, | |
| 182 Date.now() - executionStart); | |
| 183 } | |
| 184 dispatch([options, onSuccessCallback, onErrorCallback]); | |
| 185 }); | |
| 186 | 180 |
| 187 eventBindings.registerArgumentMassager( | 181 eventBindings.registerArgumentMassager( |
| 188 'fileSystemProvider.onCloseFileRequested', | 182 'fileSystemProvider.onCloseFileRequested', |
| 189 function(args, dispatch) { | 183 massageArgumentsDefault); |
| 190 var executionStart = Date.now(); | |
| 191 var options = args[0]; | |
| 192 var onSuccessCallback = function() { | |
| 193 fileSystemProviderInternal.operationRequestedSuccess( | |
| 194 options.fileSystemId, options.requestId, | |
| 195 Date.now() - executionStart); | |
| 196 }; | |
| 197 var onErrorCallback = function(error) { | |
| 198 fileSystemProviderInternal.operationRequestedError( | |
| 199 options.fileSystemId, options.requestId, error, | |
| 200 Date.now() - executionStart); | |
| 201 } | |
| 202 dispatch([options, onSuccessCallback, onErrorCallback]); | |
| 203 }); | |
| 204 | 184 |
| 205 eventBindings.registerArgumentMassager( | 185 eventBindings.registerArgumentMassager( |
| 206 'fileSystemProvider.onReadFileRequested', | 186 'fileSystemProvider.onReadFileRequested', |
| 207 function(args, dispatch) { | 187 function(args, dispatch) { |
| 208 var executionStart = Date.now(); | 188 var executionStart = Date.now(); |
| 209 var options = args[0]; | 189 var options = args[0]; |
| 210 var onSuccessCallback = function(data, hasNext) { | 190 var onSuccessCallback = function(data, hasNext) { |
| 211 fileSystemProviderInternal.readFileRequestedSuccess( | 191 fileSystemProviderInternal.readFileRequestedSuccess( |
| 212 options.fileSystemId, options.requestId, data, hasNext, | 192 options.fileSystemId, options.requestId, data, hasNext, |
| 213 Date.now() - executionStart); | 193 Date.now() - executionStart); |
| 214 }; | 194 }; |
| 215 var onErrorCallback = function(error) { | 195 var onErrorCallback = function(error) { |
| 216 fileSystemProviderInternal.operationRequestedError( | 196 fileSystemProviderInternal.operationRequestedError( |
| 217 options.fileSystemId, options.requestId, error, | 197 options.fileSystemId, options.requestId, error, |
| 218 Date.now() - executionStart); | 198 Date.now() - executionStart); |
| 219 } | 199 } |
| 220 dispatch([options, onSuccessCallback, onErrorCallback]); | 200 dispatch([options, onSuccessCallback, onErrorCallback]); |
| 221 }); | 201 }); |
| 222 | 202 |
| 203 eventBindings.registerArgumentMassager( |
| 204 'fileSystemProvider.onCreateDirectoryRequested', |
| 205 massageArgumentsDefault); |
| 206 |
| 223 exports.binding = binding.generate(); | 207 exports.binding = binding.generate(); |
| OLD | NEW |