Chromium Code Reviews| 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.<*>)} Closure to be called with massaged arguments. | |
|
hirono
2014/07/07 03:00:52
nit: 'dispatch'
mtomasz
2014/07/07 05:53:54
Done.
| |
| 48 */ | |
| 49 function massageArgumentsDefault(args, dispatch) { | |
| 50 var executionStart = Date.now(); | |
| 51 var options = args[0]; | |
| 52 var onSuccessCallback = function(hasNext) { | |
| 53 fileSystemProviderInternal.operationRequestedSuccess( | |
| 54 options.fileSystemId, options.requestId, Date.now() - executionStart); | |
| 55 }; | |
| 56 var onErrorCallback = function(error) { | |
| 57 fileSystemProviderInternal.operationRequestedError( | |
| 58 options.fileSystemId, options.requestId, error, | |
| 59 Date.now() - executionStart); | |
| 60 } | |
| 61 dispatch([options, onSuccessCallback, onErrorCallback]); | |
| 62 } | |
| 63 | |
| 64 | |
| 44 binding.registerCustomHook(function(bindingsAPI) { | 65 binding.registerCustomHook(function(bindingsAPI) { |
| 45 var apiFunctions = bindingsAPI.apiFunctions; | 66 var apiFunctions = bindingsAPI.apiFunctions; |
| 46 | 67 |
| 47 apiFunctions.setUpdateArgumentsPostValidate( | 68 apiFunctions.setUpdateArgumentsPostValidate( |
| 48 'mount', | 69 'mount', |
| 49 function(options, successCallback, errorCallback) { | 70 function(options, successCallback, errorCallback) { |
| 50 // Piggyback the error callback onto the success callback, | 71 // Piggyback the error callback onto the success callback, |
| 51 // so we can use the error callback later. | 72 // so we can use the error callback later. |
| 52 successCallback.errorCallback_ = errorCallback; | 73 successCallback.errorCallback_ = errorCallback; |
| 53 return [options, successCallback]; | 74 return [options, successCallback]; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 if (domError) | 125 if (domError) |
| 105 errorCallback(domError); | 126 errorCallback(domError); |
| 106 else | 127 else |
| 107 successCallback(); | 128 successCallback(); |
| 108 } | 129 } |
| 109 }); | 130 }); |
| 110 }); | 131 }); |
| 111 | 132 |
| 112 eventBindings.registerArgumentMassager( | 133 eventBindings.registerArgumentMassager( |
| 113 'fileSystemProvider.onUnmountRequested', | 134 'fileSystemProvider.onUnmountRequested', |
| 114 function(args, dispatch) { | 135 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 | 136 |
| 130 eventBindings.registerArgumentMassager( | 137 eventBindings.registerArgumentMassager( |
| 131 'fileSystemProvider.onGetMetadataRequested', | 138 'fileSystemProvider.onGetMetadataRequested', |
| 132 function(args, dispatch) { | 139 function(args, dispatch) { |
| 133 var executionStart = Date.now(); | 140 var executionStart = Date.now(); |
| 134 var options = args[0]; | 141 var options = args[0]; |
| 135 var onSuccessCallback = function(metadata) { | 142 var onSuccessCallback = function(metadata) { |
| 136 fileSystemProviderInternal.getMetadataRequestedSuccess( | 143 fileSystemProviderInternal.getMetadataRequestedSuccess( |
| 137 options.fileSystemId, | 144 options.fileSystemId, |
| 138 options.requestId, | 145 options.requestId, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 161 var onErrorCallback = function(error) { | 168 var onErrorCallback = function(error) { |
| 162 fileSystemProviderInternal.operationRequestedError( | 169 fileSystemProviderInternal.operationRequestedError( |
| 163 options.fileSystemId, options.requestId, error, | 170 options.fileSystemId, options.requestId, error, |
| 164 Date.now() - executionStart); | 171 Date.now() - executionStart); |
| 165 } | 172 } |
| 166 dispatch([options, onSuccessCallback, onErrorCallback]); | 173 dispatch([options, onSuccessCallback, onErrorCallback]); |
| 167 }); | 174 }); |
| 168 | 175 |
| 169 eventBindings.registerArgumentMassager( | 176 eventBindings.registerArgumentMassager( |
| 170 'fileSystemProvider.onOpenFileRequested', | 177 'fileSystemProvider.onOpenFileRequested', |
| 171 function(args, dispatch) { | 178 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 | 179 |
| 187 eventBindings.registerArgumentMassager( | 180 eventBindings.registerArgumentMassager( |
| 188 'fileSystemProvider.onCloseFileRequested', | 181 'fileSystemProvider.onCloseFileRequested', |
| 189 function(args, dispatch) { | 182 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 | 183 |
| 205 eventBindings.registerArgumentMassager( | 184 eventBindings.registerArgumentMassager( |
| 206 'fileSystemProvider.onReadFileRequested', | 185 'fileSystemProvider.onReadFileRequested', |
| 207 function(args, dispatch) { | 186 function(args, dispatch) { |
| 208 var executionStart = Date.now(); | 187 var executionStart = Date.now(); |
| 209 var options = args[0]; | 188 var options = args[0]; |
| 210 var onSuccessCallback = function(data, hasNext) { | 189 var onSuccessCallback = function(data, hasNext) { |
| 211 fileSystemProviderInternal.readFileRequestedSuccess( | 190 fileSystemProviderInternal.readFileRequestedSuccess( |
| 212 options.fileSystemId, options.requestId, data, hasNext, | 191 options.fileSystemId, options.requestId, data, hasNext, |
| 213 Date.now() - executionStart); | 192 Date.now() - executionStart); |
| 214 }; | 193 }; |
| 215 var onErrorCallback = function(error) { | 194 var onErrorCallback = function(error) { |
| 216 fileSystemProviderInternal.operationRequestedError( | 195 fileSystemProviderInternal.operationRequestedError( |
| 217 options.fileSystemId, options.requestId, error, | 196 options.fileSystemId, options.requestId, error, |
| 218 Date.now() - executionStart); | 197 Date.now() - executionStart); |
| 219 } | 198 } |
| 220 dispatch([options, onSuccessCallback, onErrorCallback]); | 199 dispatch([options, onSuccessCallback, onErrorCallback]); |
| 221 }); | 200 }); |
| 222 | 201 |
| 202 eventBindings.registerArgumentMassager( | |
| 203 'fileSystemProvider.onCreateDirectoryRequested', | |
| 204 massageArgumentsDefault); | |
| 205 | |
| 223 exports.binding = binding.generate(); | 206 exports.binding = binding.generate(); |
| OLD | NEW |