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

Side by Side Diff: chrome/common/extensions/docs/examples/api/systemInfo/main.js

Issue 10882059: Add examples for showing how to use systemInfo API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
OLDNEW
(Empty)
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.
4
5 var systemInfo = chrome.experimental.systemInfo;
6
7 var indicator = {}
8 var is_started = false;
Mihai Parparita -not on Chrome 2012/08/27 23:47:21 JavaScript naming conventions are to use camelCase
Hongbo Min 2012/08/28 01:54:03 Done.
9
10 function onStorageChanged(info) {
11 var elem = document.getElementById(info.id);
12 if (indicator[info.id]++ % 2)
13 elem.bgColor = "green";
14 else
15 elem.bgColor = "white";
16 elem.innerHTML = info.availableCapacity;
17 }
18
19 function startMonitor() {
20 if (is_started) return;
21 systemInfo.storage.onAvailableCapacityChanged.addListener(onStorageChanged);
22 is_started = true;
23 }
24
25 function stopMonitor() {
26 if (!is_started) return;
27 systemInfo.storage.onAvailableCapacityChanged.removeListener(
28 onStorageChanged);
29 is_started = false;
30 }
31
32 function init() {
33 document.getElementById("start-btn").onclick = startMonitor;
34 document.getElementById("stop-btn").onclick = stopMonitor;
35
36 chrome.experimental.systemInfo.storage.get(function(info) {
37 var table = "<table width=65% border=\"1\">\n" +
38 "<tr><td><b>ID</b></td>" +
39 "<td>Type</td>" +
40 "<td>Capacity (bytes)</td>" +
41 "<td>Available (bytes)</td>" +
42 "</tr>\n";
43 for (var i = 0; i < info.units.length; i++) {
44 indicator[info.units[i].id] = 0;
45 table = showStorageInfo(info.units[i], table);
Mihai Parparita -not on Chrome 2012/08/27 23:47:21 Why make table a parameter, when you can just say
Hongbo Min 2012/08/28 01:54:03 Done.
46 }
47 table += "</table>\n";
48 var div = document.getElementById("storage-list");
49 div.innerHTML = table;
50 });
51 }
52
53 function showStorageInfo(unit, table) {
54 table += "<tr><td>" + unit.id + "</td>" +
55 "<td>" + unit.type + "</td>" +
56 "<td>" + unit.capacity + "</td>" +
57 "<td id=" + "\"" + unit.id + "\">" + unit.availableCapacity + "</td>" +
58 "</tr>\n";
59 return table;
60 }
61
62 document.addEventListener('DOMContentLoaded', init);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698