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 26 matching lines...) Expand all Loading... |
37 modificationTime: annotateDate(metadata.modificationTime) | 37 modificationTime: annotateDate(metadata.modificationTime) |
38 }; | 38 }; |
39 return result; | 39 return result; |
40 } | 40 } |
41 | 41 |
42 binding.registerCustomHook(function(bindingsAPI) { | 42 binding.registerCustomHook(function(bindingsAPI) { |
43 var apiFunctions = bindingsAPI.apiFunctions; | 43 var apiFunctions = bindingsAPI.apiFunctions; |
44 | 44 |
45 apiFunctions.setUpdateArgumentsPostValidate( | 45 apiFunctions.setUpdateArgumentsPostValidate( |
46 'mount', | 46 'mount', |
47 function(displayName, successCallback, errorCallback) { | 47 function(fileSystemId, displayName, successCallback, errorCallback) { |
48 // Piggyback the error callback onto the success callback, | 48 // Piggyback the error callback onto the success callback, |
49 // so we can use the error callback later. | 49 // so we can use the error callback later. |
50 successCallback.errorCallback_ = errorCallback; | 50 successCallback.errorCallback_ = errorCallback; |
51 return [displayName, successCallback]; | 51 return [fileSystemId, displayName, successCallback]; |
52 }); | 52 }); |
53 | 53 |
54 apiFunctions.setCustomCallback( | 54 apiFunctions.setCustomCallback( |
55 'mount', | 55 'mount', |
56 function(name, request, response) { | 56 function(name, request, response) { |
57 var fileSystemId = null; | |
58 var domError = null; | 57 var domError = null; |
59 if (request.callback && response) { | 58 if (request.callback && response) { |
60 fileSystemId = response[0]; | |
61 // DOMError is present only if mount() failed. | 59 // DOMError is present only if mount() failed. |
62 if (response[1]) { | 60 if (response[0]) { |
63 // Convert a Dictionary to a DOMError. | 61 // Convert a Dictionary to a DOMError. |
64 domError = GetDOMError(response[1].name, response[1].message); | 62 domError = GetDOMError(response[0].name, response[0].message); |
65 response.length = 1; | 63 response.length = 1; |
66 } | 64 } |
67 | 65 |
68 var successCallback = request.callback; | 66 var successCallback = request.callback; |
69 var errorCallback = request.callback.errorCallback_; | 67 var errorCallback = request.callback.errorCallback_; |
70 delete request.callback; | 68 delete request.callback; |
71 | 69 |
72 if (domError) | 70 if (domError) |
73 errorCallback(domError); | 71 errorCallback(domError); |
74 else | 72 else |
75 successCallback(fileSystemId); | 73 successCallback(); |
76 } | 74 } |
77 }); | 75 }); |
78 | 76 |
79 apiFunctions.setUpdateArgumentsPostValidate( | 77 apiFunctions.setUpdateArgumentsPostValidate( |
80 'unmount', | 78 'unmount', |
81 function(fileSystemId, successCallback, errorCallback) { | 79 function(fileSystemId, successCallback, errorCallback) { |
82 // Piggyback the error callback onto the success callback, | 80 // Piggyback the error callback onto the success callback, |
83 // so we can use the error callback later. | 81 // so we can use the error callback later. |
84 successCallback.errorCallback_ = errorCallback; | 82 successCallback.errorCallback_ = errorCallback; |
85 return [fileSystemId, successCallback]; | 83 return [fileSystemId, successCallback]; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 }; | 211 }; |
214 var onErrorCallback = function(error) { | 212 var onErrorCallback = function(error) { |
215 fileSystemProviderInternal.readFileRequestedError( | 213 fileSystemProviderInternal.readFileRequestedError( |
216 fileSystemId, requestId, error); | 214 fileSystemId, requestId, error); |
217 } | 215 } |
218 dispatch([fileSystemId, openRequestId, offset, length, onSuccessCallback, | 216 dispatch([fileSystemId, openRequestId, offset, length, onSuccessCallback, |
219 onErrorCallback]); | 217 onErrorCallback]); |
220 }); | 218 }); |
221 | 219 |
222 exports.binding = binding.generate(); | 220 exports.binding = binding.generate(); |
OLD | NEW |