OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Custom binding for the fileSystemProvider API. | |
6 | |
7 var binding = require('binding').Binding.create('fileSystemProvider'); | |
8 var fileSystemProviderNatives = requireNative('file_system_provider'); | |
9 var GetDOMError = fileSystemProviderNatives.GetDOMError; | |
10 | |
11 binding.registerCustomHook(function(bindingsAPI) { | |
12 var apiFunctions = bindingsAPI.apiFunctions; | |
13 | |
14 apiFunctions.setUpdateArgumentsPostValidate( | |
15 'mount', | |
16 function(displayName, successCallback, errorCallback) { | |
17 // Piggyback the error callback onto the success callback, | |
18 // so we can use the error callback later. | |
satorux1
2013/11/07 07:37:02
kalman: I took another look at other APIs, but cou
not at google - send to devlin
2013/11/07 15:58:05
I think the piggybacking trick is fine for now. Wh
satorux1
2013/11/08 02:25:54
Thanks. Promise-based APIs sound good. Added trail
| |
19 successCallback.errorCallback = errorCallback; | |
20 return [displayName, successCallback]; | |
21 }); | |
22 | |
23 apiFunctions.setCustomCallback( | |
24 'mount', | |
25 function(name, request, response) { | |
26 var fileSystemId = null; | |
27 var domError = null; | |
28 if (request.callback && response) { | |
29 fileSystemId = response[0]; | |
30 // DOMError is present only if mount() failed. | |
31 if (response[1]) { | |
32 // Convert a Dictionary to a DOMError. | |
33 domError = GetDOMError(response[1].name, response[1].message); | |
34 response.length = 1; | |
35 } | |
36 | |
37 var successCallback = request.callback; | |
38 var errorCallback = request.callback.errorCallback; | |
39 delete request.callback; | |
40 | |
41 if (domError) | |
42 errorCallback(domError); | |
43 else | |
44 successCallback(fileSystemId); | |
45 } | |
46 }); | |
47 }); | |
48 | |
49 exports.binding = binding.generate(); | |
OLD | NEW |