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

Side by Side Diff: extensions/renderer/resources/storage_area.js

Issue 1928193002: Revert of [Extensions] Finish freezing schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « extensions/renderer/resources/schema_utils.js ('k') | extensions/renderer/resources/utils.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 var normalizeArgumentsAndValidate = 5 var normalizeArgumentsAndValidate =
6 require('schemaUtils').normalizeArgumentsAndValidate 6 require('schemaUtils').normalizeArgumentsAndValidate
7 var sendRequest = require('sendRequest').sendRequest; 7 var sendRequest = require('sendRequest').sendRequest;
8 8
9 function extendSchema(schema) { 9 function extendSchema(schema) {
10 var extendedSchema = $Array.slice(schema); 10 var extendedSchema = $Array.slice(schema);
11 $Array.unshift(extendedSchema, {'type': 'string'}); 11 extendedSchema.unshift({'type': 'string'});
12 return extendedSchema; 12 return extendedSchema;
13 } 13 }
14 14
15 function StorageArea(namespace, schema) { 15 function StorageArea(namespace, schema) {
16 // Binds an API function for a namespace to its browser-side call, e.g. 16 // Binds an API function for a namespace to its browser-side call, e.g.
17 // storage.sync.get('foo') -> (binds to) -> 17 // storage.sync.get('foo') -> (binds to) ->
18 // storage.get('sync', 'foo'). 18 // storage.get('sync', 'foo').
19 // 19 //
20 // TODO(kalman): Put as a method on CustombindingObject and re-use (or 20 // TODO(kalman): Put as a method on CustombindingObject and re-use (or
21 // even generate) for other APIs that need to do this. Same for other 21 // even generate) for other APIs that need to do this. Same for other
22 // callers of registerCustomType(). 22 // callers of registerCustomType().
23 var self = this; 23 var self = this;
24 function bindApiFunction(functionName) { 24 function bindApiFunction(functionName) {
25 self[functionName] = function() { 25 self[functionName] = function() {
26 var funSchema = this.functionSchemas[functionName]; 26 var funSchema = this.functionSchemas[functionName];
27 var args = $Array.slice(arguments); 27 var args = $Array.slice(arguments);
28 args = normalizeArgumentsAndValidate(args, funSchema); 28 args = normalizeArgumentsAndValidate(args, funSchema);
29 return sendRequest( 29 return sendRequest(
30 'storage.' + functionName, 30 'storage.' + functionName,
31 $Array.concat([namespace], args), 31 $Array.concat([namespace], args),
32 extendSchema(funSchema.definition.parameters), 32 extendSchema(funSchema.definition.parameters),
33 {preserveNullInObjects: true}); 33 {preserveNullInObjects: true});
34 }; 34 };
35 } 35 }
36 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse']; 36 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse'];
37 $Array.forEach(apiFunctions, bindApiFunction); 37 $Array.forEach(apiFunctions, bindApiFunction);
38 } 38 }
39 39
40 exports.$set('StorageArea', StorageArea); 40 exports.$set('StorageArea', StorageArea);
OLDNEW
« no previous file with comments | « extensions/renderer/resources/schema_utils.js ('k') | extensions/renderer/resources/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698