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

Side by Side Diff: chrome/common/extensions/docs/templates/articles/offline_storage.html

Issue 1091683002: Docs: Update quota mgmt API docs to use methods that don't throw console warnings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <h1>Managing HTML5 Offline Storage</h1> 1 <h1>Managing HTML5 Offline Storage</h1>
2 2
3 <p> 3 <p>
4 HTML5 introduced many storage APIs that let you store a large amount of data lo cally in your users' browsers. But the amount of space allocated for each app is , by default, restricted to a few megabytes. Google Chrome lets you ask for a l arger storage quota, beyond the previous limit of just 5 MB. </p> 4 HTML5 introduced many storage APIs that let you store a large amount of data lo cally in your users' browsers. But the amount of space allocated for each app is , by default, restricted to a few megabytes. Google Chrome lets you ask for a l arger storage quota, beyond the previous limit of just 5 MB. </p>
5 <p>This document introduces you to the basic concepts around the types of storag e used in Chrome and describes the experimental Quota Management API, which lets you manage your storage quota. The document assumes that you are already famili ar with the general concepts of client-side storage and know how to use offli ne APIs. </p> 5 <p>This document introduces you to the basic concepts around the types of storag e used in Chrome and describes the experimental Quota Management API, which lets you manage your storage quota. The document assumes that you are already famili ar with the general concepts of client-side storage and know how to use offli ne APIs. </p>
6 <h2 id="contents">Contents</h2> 6 <h2 id="contents">Contents</h2>
7 <ol> 7 <ol>
8 <li><a href="#types">Types of storage</a> 8 <li><a href="#types">Types of storage</a>
9 <ol> 9 <ol>
10 <li><a href="#temporary">Temporary </a></li> 10 <li><a href="#temporary">Temporary </a></li>
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 <h3 id="query">Querying storage usage and availability</h3> 177 <h3 id="query">Querying storage usage and availability</h3>
178 <p>To query the storage size that is being used and the available space left for the host, call <code>queryUsageAndQuota()</code> with the following:</p> 178 <p>To query the storage size that is being used and the available space left for the host, call <code>queryUsageAndQuota()</code> with the following:</p>
179 <ul> 179 <ul>
180 <li>Type of storage you want to check</li> 180 <li>Type of storage you want to check</li>
181 <li>Success callback </li> 181 <li>Success callback </li>
182 </ul> 182 </ul>
183 <p>The usage reported by the API might not match with the actual size of the u ser data, as each storage might need some extra bytes to store its metadata. Als o, status updates can lag, resulting in the API not reflecting the most recent s torage status. </p> 183 <p>The usage reported by the API might not match with the actual size of the u ser data, as each storage might need some extra bytes to store its metadata. Als o, status updates can lag, resulting in the API not reflecting the most recent s torage status. </p>
184 <p>The following code snippet shows how you can ask about storage space:</p> 184 <p>The following code snippet shows how you can ask about storage space:</p>
185 <pre class="prettyprint"> 185 <pre class="prettyprint">
186 // Request storage usage and capacity left 186 // Request storage usage and capacity left
187 window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY, //the t ype can be either TEMPORARY or PERSISTENT 187 // choose either Temporary or Persistent
mkearney1 2015/04/16 00:25:27 Nit: Capitalize 'choose' in comment.
188 function(used, remaining) { 188 navigator.webkitTemporaryStorage.queryUsageAndQuota (
189 console.log("Used quota: " + used + ", remaining quota: " + remaining); 189 function(usedBytes, grantedBytes) {
190 }, function(e) { 190 console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
191 console.log('Error', e); 191 },
192 } );</pre> 192 function(e) { console.log('Error', e); }
193 );
194 </pre>
193 <p>If you want to ask for the status of persistent storage, simply replace <span class="prettyprint"><code>webkitStorageInfo.<strong>TEMPORARY</strong></code></ span> with <span class="prettyprint"><code>webkitStorageInfo.<strong>PERSISTENT< /strong></code></span>. The enum is also in the <code>window</code> object (glob al namespace), so you can also use <code>window.<strong>PERSISTENT</strong></cod e> and <code>window.<strong>TEMPORARY</strong></code>.</p> 195 <p>If you want to ask for the status of persistent storage, simply replace <span class="prettyprint"><code>webkitStorageInfo.<strong>TEMPORARY</strong></code></ span> with <span class="prettyprint"><code>webkitStorageInfo.<strong>PERSISTENT< /strong></code></span>. The enum is also in the <code>window</code> object (glob al namespace), so you can also use <code>window.<strong>PERSISTENT</strong></cod e> and <code>window.<strong>TEMPORARY</strong></code>.</p>
194 <p class="backtotop"><a href="#top">Back to top</a></p> 196 <p class="backtotop"><a href="#top">Back to top</a></p>
195 197
196 <h3 id="asking_more">Asking for more storage</h3> 198 <h3 id="asking_more">Asking for more storage</h3>
197 <p>You don't need to ask for more temporary storage as the allocation is automat ic, and you can't get beyond the maximum limit (as described in the <a href="#ta ble">table</a>). </p> 199 <p>You don't need to ask for more temporary storage as the allocation is automat ic, and you can't get beyond the maximum limit (as described in the <a href="#ta ble">table</a>). </p>
198 <p>For persistent storage for Files System API, the default quota is 0, so you need to explicitly request storage for your application. Call <code>requestQuota ()</code> with the following:</p> 200 <p>For persistent storage for Files System API, the default quota is 0, so you need to explicitly request storage for your application. Call <code>requestQuota ()</code> with the following:</p>
199 <ul> 201 <ul>
200 <li>Type of storage</li> 202 <li>Type of storage</li>
201 <li>Size</li> 203 <li>Size</li>
202 <li>Success callback</li> 204 <li>Success callback</li>
203 </ul> 205 </ul>
204 <p>Depending on what you ask for, the following happens:</p> 206 <p>Depending on what you ask for, the following happens:</p>
205 <ul> 207 <ul>
206 <li>If you ask for a larger quota, the browser presents an info bar to the use r and prompts them to either grant or deny permission for increased quota. In so me cases, the request might be silently rejected, and the current quota or small er quota is returned.</li> 208 <li>If you ask for a larger quota, the browser presents an info bar to the use r and prompts them to either grant or deny permission for increased quota. In so me cases, the request might be silently rejected, and the current quota or small er quota is returned.</li>
207 <li>If the amount of quota you request is less than the app's current allocati on, no prompt is shown. </li> 209 <li>If the amount of quota you request is less than the app's current allocati on, no prompt is shown. </li>
208 <li>If you ask for more storage than what is allowed, you get an error (<code> QUOTA_EXCEEDED_ERR</code>). </li> 210 <li>If you ask for more storage than what is allowed, you get an error (<code> QUOTA_EXCEEDED_ERR</code>). </li>
209 <li>If you call <code>requestQuota()</code> again after the user has already g ranted permission, nothing happens. So don't bother calling the method again.</l i> 211 <li>If you call <code>requestQuota()</code> again after the user has already g ranted permission, nothing happens. So don't bother calling the method again.</l i>
210 </ul> 212 </ul>
211 <p>The following shows how you can ask for more storage space:</p> 213 <p>The following shows how you can ask for more storage space:</p>
212 <pre class="prettyprint"> 214 <pre class="prettyprint">
213 // Request Quota (only for File System API) </span> 215 // Request Quota (only for File System API) </span>
214 window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedByt es) { 216 var requestedBytes = 1024*1024*10; // 10MB
215 window.webkitRequestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandle r); 217
216 }, function(e) { 218 navigator.webkitPersistentStorage.requestQuota (
217 console.log('Error', e); 219 requestedBytes, function(grantedBytes) {
220 window.requestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandle r);
221
222 }, function(e) { console.log('Error', e); }
223 );
218 });</pre> 224 });</pre>
219 <p class="backtotop"><a href="#top">Back to top</a></p> 225 <p class="backtotop"><a href="#top">Back to top</a></p>
220 226
221 <h3 id="reset">Resetting quota for testing</h3> 227 <h3 id="reset">Resetting quota for testing</h3>
222 <p>When you are testing storage in your app, you might want to clear the stored data so that you can test quota management afresh in your app. To do so:</p> 228 <p>When you are testing storage in your app, you might want to clear the stored data so that you can test quota management afresh in your app. To do so:</p>
223 <ol> 229 <ol>
224 <li>Enter <code>chrome://settings/cookies</code> in the omnibox (the address b ar). </li> 230 <li>Enter <code>chrome://settings/cookies</code> in the omnibox (the address b ar). </li>
225 <li>Search for your app.</li> 231 <li>Search for your app.</li>
226 <li>Select your app. </li> 232 <li>Select your app. </li>
227 <li>Click the <strong>X</strong> on the right side of the highlighted selecti on.</li> 233 <li>Click the <strong>X</strong> on the right side of the highlighted selecti on.</li>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 </tr> 269 </tr>
264 <tr> 270 <tr>
265 <td><code>void <a href="#requestQuota" title="#add">requestQuota</a> (in u nsigned short storageType, unsigned long long newQuotaInBytes, optional StorageI nfoQuotaCallback successCallback, optional StorageInfoErrorCallback errorCallbac k)</code></td> 271 <td><code>void <a href="#requestQuota" title="#add">requestQuota</a> (in u nsigned short storageType, unsigned long long newQuotaInBytes, optional StorageI nfoQuotaCallback successCallback, optional StorageInfoErrorCallback errorCallbac k)</code></td>
266 </tr> 272 </tr>
267 </tbody> 273 </tbody>
268 </table> 274 </table>
269 <h3 id="methods">Methods</h3> 275 <h3 id="methods">Methods</h3>
270 <h4 id="queryUsageAndQuota">queryUsageAndQuota</h4> 276 <h4 id="queryUsageAndQuota">queryUsageAndQuota</h4>
271 <p>Check the storage size that is being used and the available space left for th e host.</p> 277 <p>Check the storage size that is being used and the available space left for th e host.</p>
272 278
273 <pre class="prettyprint">webkitStorageInfo.queryUsageAndQuota( 279 <pre class="prettyprint"> // you could also use it from webkitPersistentStorage
274 webkitStorageInfo.TEMPORARY, // or PERSISTENT 280 navigator.webkitTemporaryStorage.queryUsageAndQuota(
275 usageCallback, 281 successCallback,
276 errorCallback);</pre> 282 errorCallback);</pre>
277
278
279 <h5>Parameters</h5>
280 <dl>
281 <dt>storageType</dt>
282 <dd>The type of storage for the current usage. The value could either be <code>T EMPORARY</code> or <code>PERSISTENT</code>. </dd>
283 </dl>
284 <dl> 283 <dl>
285 <dt>successCallback</dt> 284 <dt>successCallback</dt>
286 <dd>Optional callback with two parameters: <ul> 285 <dd>Optional callback with two parameters: <ul>
287 <li>The current number of bytes the app is using. </li> 286 <li>The current number of bytes the app is using. </li>
288 <li>The number of bytes left in the quota. </li> 287 <li>The number of bytes left in the quota. </li>
289 </ul> 288 </ul>
290 </dd> 289 </dd>
291 </dl> 290 </dl>
292 <dl> 291 <dl>
293 <dt>errorCallback</dt> 292 <dt>errorCallback</dt>
294 <dd>Optional error callback.</dd> 293 <dd>Optional error callback.</dd>
295 <dt>&nbsp;</dt> 294 <dt>&nbsp;</dt>
296 </dl> 295 </dl>
297 <p class="backtotop"><a href="#top">Back to top</a></p> 296 <p class="backtotop"><a href="#top">Back to top</a></p>
298 <hr /> 297 <hr />
299 <h4 id="requestQuota">requestQuota</h4> 298 <h4 id="requestQuota">requestQuota</h4>
300 299
301 <p>Ask for more storage. The browser presents an info bar to prompt user to gran t or deny the app the permission to have more storage.</p> 300 <p>Ask for more storage. The browser presents an info bar to prompt user to gran t or deny the app the permission to have more storage.</p>
302 301
303 <pre class="prettyprint">webkitStorageInfo.requestQuota( 302 <pre class="prettyprint"> // you could also use it from webkitTemporaryStorage
304 webkitStorageInfo.PERSISTENT // or TEMPORARY 303 navigator.webkitPersistentStorage.requestQuota (
305 newQuotaInBytes, 304 newQuotaInBytes,
306 quotaCallback, 305 quotaCallback,
307 errorCallback);</pre> 306 errorCallback);</pre>
308 307
309 <h5>Parameters</h5> 308 <h5>Parameters</h5>
310 <dl> 309 <dl>
311 <dt>storageType</dt> 310
312 <dd>The type of storage for the current usage. The value could either be <code >TEMPORARY</code> or <code>PERSISTENT</code>. Temporary storage is automatically allocated, so only call the method for <code>PERSISTENT</code> storage. </dd>
313 <dt>newQuotaInBytes</dt> 311 <dt>newQuotaInBytes</dt>
314 <dd>The amount of bytes you want in your storage quota. </dd> 312 <dd>The amount of bytes you want in your storage quota. </dd>
315 </dl> 313 </dl>
316 <dl> 314 <dl>
317 <dt>successCallback</dt> 315 <dt>successCallback</dt>
318 <dd>Optional callback that passes the amount of bytes granted. </dd> 316 <dd>Optional callback that passes the amount of bytes granted. </dd>
319 </dl> 317 </dl>
320 <dl> 318 <dl>
321 <dt>errorCallback</dt> 319 <dt>errorCallback</dt>
322 <dd>Optional error callback.</dd> 320 <dd>Optional error callback.</dd>
323 </dl> 321 </dl>
324 322
325 <h2 id="future">Future development</h2> 323 <h2 id="future">Future development</h2>
326 <p>The plan is to put all HTML5 offline storage APIs—including IndexedDB, Applic ation Cache, Files System,{# LocalStorage, SessionStorage,#} and other APIs that might be specified—under the Quota Management API. You will be able to manage a ll storage allocation with it. </p> 324 <p>The plan is to put all HTML5 offline storage APIs—including IndexedDB, Applic ation Cache, Files System,{# LocalStorage, SessionStorage,#} and other APIs that might be specified—under the Quota Management API. You will be able to manage a ll storage allocation with it. </p>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698