OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 syncFileSystem API. | 5 // Custom binding for the syncFileSystem API. |
6 | 6 |
7 var binding = require('binding').Binding.create('syncFileSystem'); | 7 var binding = require('binding').Binding.create('syncFileSystem'); |
8 | 8 |
9 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 9 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
10 var fileSystemNatives = requireNative('file_system_natives'); | 10 var fileSystemNatives = requireNative('file_system_natives'); |
| 11 var forEach = require('utils').forEach; |
11 var syncFileSystemNatives = requireNative('sync_file_system'); | 12 var syncFileSystemNatives = requireNative('sync_file_system'); |
12 | 13 |
13 binding.registerCustomHook(function(bindingsAPI) { | 14 binding.registerCustomHook(function(bindingsAPI) { |
14 var apiFunctions = bindingsAPI.apiFunctions; | 15 var apiFunctions = bindingsAPI.apiFunctions; |
15 | 16 |
16 // Functions which take in an [instanceOf=FileEntry]. | 17 // Functions which take in an [instanceOf=FileEntry]. |
17 function bindFileEntryFunction(functionName) { | 18 function bindFileEntryFunction(i, functionName) { |
18 apiFunctions.setUpdateArgumentsPostValidate( | 19 apiFunctions.setUpdateArgumentsPostValidate( |
19 functionName, function(entry, callback) { | 20 functionName, function(entry, callback) { |
20 var fileSystemUrl = entry.toURL(); | 21 var fileSystemUrl = entry.toURL(); |
21 return [fileSystemUrl, callback]; | 22 return [fileSystemUrl, callback]; |
22 }); | 23 }); |
23 } | 24 } |
24 ['getFileStatus'] | 25 forEach(['getFileStatus'], bindFileEntryFunction); |
25 .forEach(bindFileEntryFunction); | |
26 | 26 |
27 // Functions which take in an [instanceOf=DOMFileSystem]. | 27 // Functions which take in an [instanceOf=DOMFileSystem]. |
28 function bindFileSystemFunction(functionName) { | 28 function bindFileSystemFunction(i, functionName) { |
29 apiFunctions.setUpdateArgumentsPostValidate( | 29 apiFunctions.setUpdateArgumentsPostValidate( |
30 functionName, function(filesystem, callback) { | 30 functionName, function(filesystem, callback) { |
31 var fileSystemUrl = filesystem.root.toURL(); | 31 var fileSystemUrl = filesystem.root.toURL(); |
32 return [fileSystemUrl, callback]; | 32 return [fileSystemUrl, callback]; |
33 }); | 33 }); |
34 } | 34 } |
35 ['deleteFileSystem', 'getUsageAndQuota'] | 35 forEach(['deleteFileSystem', 'getUsageAndQuota'], bindFileSystemFunction); |
36 .forEach(bindFileSystemFunction); | |
37 | 36 |
38 // Functions which return an [instanceOf=DOMFileSystem]. | 37 // Functions which return an [instanceOf=DOMFileSystem]. |
39 apiFunctions.setCustomCallback('requestFileSystem', | 38 apiFunctions.setCustomCallback('requestFileSystem', |
40 function(name, request, response) { | 39 function(name, request, response) { |
41 var result = null; | 40 var result = null; |
42 if (response) { | 41 if (response) { |
43 result = syncFileSystemNatives.GetSyncFileSystemObject( | 42 result = syncFileSystemNatives.GetSyncFileSystemObject( |
44 response.name, response.root); | 43 response.name, response.root); |
45 } | 44 } |
46 if (request.callback) | 45 if (request.callback) |
(...skipping 17 matching lines...) Expand all Loading... |
64 fileInfo.fileEntry = fileEntry; | 63 fileInfo.fileEntry = fileEntry; |
65 fileInfo.status = args[4]; | 64 fileInfo.status = args[4]; |
66 if (fileInfo.status == "synced") { | 65 if (fileInfo.status == "synced") { |
67 fileInfo.action = args[5]; | 66 fileInfo.action = args[5]; |
68 fileInfo.direction = args[6]; | 67 fileInfo.direction = args[6]; |
69 } | 68 } |
70 dispatch([fileInfo]); | 69 dispatch([fileInfo]); |
71 }); | 70 }); |
72 | 71 |
73 exports.binding = binding.generate(); | 72 exports.binding = binding.generate(); |
OLD | NEW |