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 = |
| 9 require('binding').Binding.create('fileSystemProviderInternal').generate(); |
| 10 var eventBindings = require('event_bindings'); |
8 var fileSystemNatives = requireNative('file_system_natives'); | 11 var fileSystemNatives = requireNative('file_system_natives'); |
9 var GetDOMError = fileSystemNatives.GetDOMError; | 12 var GetDOMError = fileSystemNatives.GetDOMError; |
10 | 13 |
11 binding.registerCustomHook(function(bindingsAPI) { | 14 binding.registerCustomHook(function(bindingsAPI) { |
12 var apiFunctions = bindingsAPI.apiFunctions; | 15 var apiFunctions = bindingsAPI.apiFunctions; |
13 | 16 |
14 apiFunctions.setUpdateArgumentsPostValidate( | 17 apiFunctions.setUpdateArgumentsPostValidate( |
15 'mount', | 18 'mount', |
16 function(displayName, successCallback, errorCallback) { | 19 function(displayName, successCallback, errorCallback) { |
17 // Piggyback the error callback onto the success callback, | 20 // Piggyback the error callback onto the success callback, |
(...skipping 19 matching lines...) Expand all Loading... |
37 var successCallback = request.callback; | 40 var successCallback = request.callback; |
38 var errorCallback = request.callback.errorCallback_; | 41 var errorCallback = request.callback.errorCallback_; |
39 delete request.callback; | 42 delete request.callback; |
40 | 43 |
41 if (domError) | 44 if (domError) |
42 errorCallback(domError); | 45 errorCallback(domError); |
43 else | 46 else |
44 successCallback(fileSystemId); | 47 successCallback(fileSystemId); |
45 } | 48 } |
46 }); | 49 }); |
| 50 |
| 51 apiFunctions.setUpdateArgumentsPostValidate( |
| 52 'unmount', |
| 53 function(fileSystemId, successCallback, errorCallback) { |
| 54 // Piggyback the error callback onto the success callback, |
| 55 // so we can use the error callback later. |
| 56 successCallback.errorCallback_ = errorCallback; |
| 57 return [fileSystemId, successCallback]; |
| 58 }); |
| 59 |
| 60 apiFunctions.setCustomCallback( |
| 61 'unmount', |
| 62 function(name, request, response) { |
| 63 var domError = null; |
| 64 if (request.callback) { |
| 65 // DOMError is present only if mount() failed. |
| 66 if (response && response[0]) { |
| 67 // Convert a Dictionary to a DOMError. |
| 68 domError = GetDOMError(response[0].name, response[0].message); |
| 69 response.length = 1; |
| 70 } |
| 71 |
| 72 var successCallback = request.callback; |
| 73 var errorCallback = request.callback.errorCallback_; |
| 74 delete request.callback; |
| 75 |
| 76 if (domError) |
| 77 errorCallback(domError); |
| 78 else |
| 79 successCallback(); |
| 80 } |
| 81 }); |
47 }); | 82 }); |
48 | 83 |
| 84 eventBindings.registerArgumentMassager( |
| 85 'fileSystemProvider.onUnmountRequested', |
| 86 function(args, dispatch) { |
| 87 var fileSystemId = args[0]; |
| 88 var requestId = args[1]; |
| 89 var onSuccessCallback = function() { |
| 90 fileSystemProviderInternal.unmountRequestedSuccess( |
| 91 fileSystemId, requestId); |
| 92 }; |
| 93 var onErrorCallback = function(error) { |
| 94 fileSystemProviderInternal.unmountRequestedError( |
| 95 fileSystemId, requestId, error); |
| 96 } |
| 97 dispatch([fileSystemId, onSuccessCallback, onErrorCallback]); |
| 98 }); |
| 99 |
49 exports.binding = binding.generate(); | 100 exports.binding = binding.generate(); |
OLD | NEW |