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
3 // found in the LICENSE file.
5 // Custom binding for the syncFileSystem API.
7 var binding = require('binding').Binding.create('syncFileSystem');
9 var eventBindings = require('event_bindings');
10 var fileSystemNatives = requireNative('file_system_natives');
11 var syncFileSystemNatives = requireNative('sync_file_system');
13 binding.registerCustomHook(function(bindingsAPI) {
14 var apiFunctions = bindingsAPI.apiFunctions;
16 // Functions which take in an [instanceOf=FileEntry].
17 function bindFileEntryFunction(functionName) {
18 apiFunctions.setUpdateArgumentsPostValidate(
19 functionName, function(entry, callback) {
20 var fileSystemUrl = entry.toURL();
21 return [fileSystemUrl, callback];
24 $Array.forEach(['getFileStatus'], bindFileEntryFunction);
26 // Functions which take in a FileEntry array.
27 function bindFileEntryArrayFunction(functionName) {
28 apiFunctions.setUpdateArgumentsPostValidate(
29 functionName, function(entries, callback) {
30 var fileSystemUrlArray = [];
31 for (var i=0; i < entries.length; i++) {
32 $Array.push(fileSystemUrlArray, entries[i].toURL());
34 return [fileSystemUrlArray, callback];
37 $Array.forEach(['getFileStatuses'], bindFileEntryArrayFunction);
39 // Functions which take in an [instanceOf=DOMFileSystem].
40 function bindFileSystemFunction(functionName) {
41 apiFunctions.setUpdateArgumentsPostValidate(
42 functionName, function(filesystem, callback) {
43 var fileSystemUrl = filesystem.root.toURL();
44 return [fileSystemUrl, callback];
47 $Array.forEach(['getUsageAndQuota'], bindFileSystemFunction);
49 // Functions which return an [instanceOf=DOMFileSystem].
50 apiFunctions.setCustomCallback('requestFileSystem',
51 function(name, request, callback, response) {
54 result = syncFileSystemNatives.GetSyncFileSystemObject(
55 response.name, response.root);
61 // Functions which return an array of FileStatusInfo object
62 // which has [instanceOf=FileEntry].
63 apiFunctions.setCustomCallback('getFileStatuses',
64 function(name, request, callback, response) {
67 for (var i = 0; i < response.length; i++) {
69 var entry = response[i].entry;
70 result.fileEntry = fileSystemNatives.GetFileEntry(
76 result.status = response[i].status;
77 result.error = response[i].error;
78 $Array.push(results, result);
86 eventBindings.registerArgumentMassager(
87 'syncFileSystem.onFileStatusChanged', function(args, dispatch) {
88 // Make FileEntry object using all the base string fields.
89 var fileEntry = fileSystemNatives.GetFileEntry(
90 args[0].fileSystemType,
91 args[0].fileSystemName,
96 // Combine into a single dictionary.
97 var fileInfo = new Object();
98 fileInfo.fileEntry = fileEntry;
99 fileInfo.status = args[1];
100 if (fileInfo.status == "synced") {
101 fileInfo.action = args[2];
102 fileInfo.direction = args[3];
104 dispatch([fileInfo]);
107 exports.binding = binding.generate();