Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7829)

Unified Diff: chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js

Issue 50703013: fileSystemProvider: First cut at implementing fileSystemProvider API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: switch to two-callback approach Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js
diff --git a/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js b/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js
new file mode 100644
index 0000000000000000000000000000000000000000..510fddc69572ade1db52f06f9e4f2779a7c95064
--- /dev/null
+++ b/chrome/renderer/resources/extensions/file_system_provider_custom_bindings.js
@@ -0,0 +1,49 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Custom binding for the fileSystemProvider API.
+
+var binding = require('binding').Binding.create('fileSystemProvider');
+var fileSystemProviderNatives = requireNative('file_system_provider');
+var GetDOMError = fileSystemProviderNatives.GetDOMError;
+
+binding.registerCustomHook(function(bindingsAPI) {
+ var apiFunctions = bindingsAPI.apiFunctions;
+
+ apiFunctions.setUpdateArgumentsPostValidate(
+ 'mount',
+ function(displayName, successCallback, errorCallback) {
+ // Piggyback the error callback onto the success callback,
+ // 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
+ successCallback.errorCallback = errorCallback;
+ return [displayName, successCallback];
+ });
+
+ apiFunctions.setCustomCallback(
+ 'mount',
+ function(name, request, response) {
+ var fileSystemId = null;
+ var domError = null;
+ if (request.callback && response) {
+ fileSystemId = response[0];
+ // DOMError is present only if mount() failed.
+ if (response[1]) {
+ // Convert a Dictionary to a DOMError.
+ domError = GetDOMError(response[1].name, response[1].message);
+ response.length = 1;
+ }
+
+ var successCallback = request.callback;
+ var errorCallback = request.callback.errorCallback;
+ delete request.callback;
+
+ if (domError)
+ errorCallback(domError);
+ else
+ successCallback(fileSystemId);
+ }
+ });
+});
+
+exports.binding = binding.generate();

Powered by Google App Engine
This is Rietveld 408576698