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
3// found in the LICENSE file.
4
5[
6  {
7    "namespace": "storage",
8    "description": "Use the <code>chrome.storage</code> API to store, retrieve, and track changes to user data.",
9    "unprivileged": true,
10    "types": [
11      {
12        "id": "StorageChange",
13        "type": "object",
14        "properties": {
15          "oldValue": {
16            "type": "any",
17            "description": "The old value of the item, if there was an old value.",
18            "optional": true
19          },
20          "newValue": {
21            "type": "any",
22            "description": "The new value of the item, if there is a new value.",
23            "optional": true
24          }
25        }
26      },
27      {
28        "id": "StorageArea",
29        "type": "object",
30        "js_module": "StorageArea",
31        "functions": [
32          {
33            "name": "get",
34            "type": "function",
35            "description": "Gets one or more items from storage.",
36            "parameters": [
37              {
38                "name": "keys",
39                "choices": [
40                  { "type": "string" },
41                  { "type": "array", "items": { "type": "string" } },
42                  {
43                    "type": "object",
44                    "description": "Storage items to return in the callback, where the values are replaced with those from storage if they exist.",
45                    "additionalProperties": { "type": "any" }
46                  }
47                ],
48                "description": "A single key to get, list of keys to get, or a dictionary specifying default values (see description of the object).  An empty list or object will return an empty result object.  Pass in <code>null</code> to get the entire contents of storage.",
49                "optional": true
50              },
51              {
52                "name": "callback",
53                "type": "function",
54                "description": "Callback with storage items, or on failure (in which case $(ref:runtime.lastError) will be set).",
55                "parameters": [
56                  {
57                    "name": "items",
58                    "type": "object",
59                    "additionalProperties": { "type": "any" },
60                    "description": "Object with items in their key-value mappings."
61                  }
62                ]
63              }
64            ]
65          },
66          {
67            "name": "getBytesInUse",
68            "type": "function",
69            "description": "Gets the amount of space (in bytes) being used by one or more items.",
70            "parameters": [
71              {
72                "name": "keys",
73                "choices": [
74                  { "type": "string" },
75                  { "type": "array", "items": { "type": "string" } }
76                ],
77                "description": "A single key or list of keys to get the total usage for. An empty list will return 0. Pass in <code>null</code> to get the total usage of all of storage.",
78                "optional": true
79              },
80              {
81                "name": "callback",
82                "type": "function",
83                "description": "Callback with the amount of space being used by storage, or on failure (in which case $(ref:runtime.lastError) will be set).",
84                "parameters": [
85                  {
86                    "name": "bytesInUse",
87                    "type": "integer",
88                    "description": "Amount of space being used in storage, in bytes."
89                  }
90                ]
91              }
92            ]
93          },
94          {
95            "name": "set",
96            "type": "function",
97            "description": "Sets multiple items.",
98            "parameters": [
99              {
100                "name": "items",
101                "type": "object",
102                "additionalProperties": { "type": "any" },
103                "description": "<p>An object which gives each key/value pair to update storage with. Any other key/value pairs in storage will not be affected.</p><p>Primitive values such as numbers will serialize as expected. Values with a <code>typeof</code> <code>\"object\"</code> and <code>\"function\"</code> will typically serialize to <code>{}</code>, with the exception of <code>Array</code> (serializes as expected), <code>Date</code>, and <code>Regex</code> (serialize using their <code>String</code> representation).</p>"
104              },
105              {
106                "name": "callback",
107                "type": "function",
108                "description": "Callback on success, or on failure (in which case $(ref:runtime.lastError) will be set).",
109                "parameters": [],
110                "optional": true
111              }
112            ]
113          },
114          {
115            "name": "remove",
116            "type": "function",
117            "description": "Removes one or more items from storage.",
118            "parameters": [
119              {
120                "name": "keys",
121                "choices": [
122                  {"type": "string"},
123                  {"type": "array", "items": {"type": "string"}}
124                ],
125                "description": "A single key or a list of keys for items to remove."
126              },
127              {
128                "name": "callback",
129                "type": "function",
130                "description": "Callback on success, or on failure (in which case $(ref:runtime.lastError) will be set).",
131                "parameters": [],
132                "optional": true
133              }
134            ]
135          },
136          {
137            "name": "clear",
138            "type": "function",
139            "description": "Removes all items from storage.",
140            "parameters": [
141              {
142                "name": "callback",
143                "type": "function",
144                "description": "Callback on success, or on failure (in which case $(ref:runtime.lastError) will be set).",
145                "parameters": [],
146                "optional": true
147              }
148            ]
149          }
150        ]
151      }
152    ],
153    "events": [
154      {
155        "name": "onChanged",
156        "type": "function",
157        "description": "Fired when one or more items change.",
158        "parameters": [
159          {
160            "name": "changes",
161            "type": "object",
162            "additionalProperties": { "$ref": "StorageChange" },
163            "description": "Object mapping each key that changed to its corresponding $(ref:storage.StorageChange) for that item."
164          },
165          {
166            "name": "areaName",
167            "type": "string",
168            "description": "The name of the storage area (<code>\"sync\"</code>, <code>\"local\"</code> or <code>\"managed\"</code>) the changes are for."
169          }
170        ]
171      }
172    ],
173    "properties": {
174      "sync": {
175        "$ref": "StorageArea",
176        "description": "Items in the <code>sync</code> storage area are synced using Chrome Sync.",
177        "value": [ "sync" ],
178        "properties": {
179          "QUOTA_BYTES": {
180            "value": 102400,
181            "description": "The maximum total amount (in bytes) of data that can be stored in sync storage, as measured by the JSON stringification of every value plus every key's length. Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError)."
182          },
183          "QUOTA_BYTES_PER_ITEM": {
184            "value": 8192,
185            "description": "The maximum size (in bytes) of each individual item in sync storage, as measured by the JSON stringification of its value plus its key length. Updates containing items larger than this limit will fail immediately and set $(ref:runtime.lastError)."
186          },
187          "MAX_ITEMS": {
188            "value": 512,
189            "description": "The maximum number of items that can be stored in sync storage. Updates that would cause this limit to be exceeded will fail immediately and set $(ref:runtime.lastError)."
190          },
191          "MAX_WRITE_OPERATIONS_PER_HOUR": {
192            "value": 1000,
193            "description": "The maximum number of <code>set</code>, <code>remove</code>, or <code>clear</code> operations that can be performed each hour. Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError)."
194          },
195          "MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE": {
196            "value": 10,
197            "description": "The maximum number of <code>set</code>, <code>remove</code>, or <code>clear</code> operations that can be performed each minute, sustained over 10 minutes. Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError)."
198          }
199        }
200      },
201      "local": {
202        "$ref": "StorageArea",
203        "description": "Items in the <code>local</code> storage area are local to each machine.",
204        "value": [ "local" ],
205        "properties": {
206          "QUOTA_BYTES": {
207            "value": 5242880,
208            "description": "The maximum amount (in bytes) of data that can be stored in local storage, as measured by the JSON stringification of every value plus every key's length. This value will be ignored if the extension has the <code>unlimitedStorage</code> permission. Updates that would cause this limit to be exceeded fail immediately and set $(ref:runtime.lastError)."
209          }
210        }
211      },
212      "managed": {
213        "$ref": "StorageArea",
214        "description": "Items in the <code>managed</code> storage area are set by the domain administrator, and are read-only for the extension; trying to modify this namespace results in an error.",
215        "value": [ "managed" ]
216      }
217    }
218  }
219]
220