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

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

Issue 11312191: Update example code to show how to use systemInfo.cpu and systemInfo.memory API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 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
« no previous file with comments | « chrome/common/extensions/docs/examples/api/systemInfo/index.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/examples/api/systemInfo/main.js
diff --git a/chrome/common/extensions/docs/examples/api/systemInfo/main.js b/chrome/common/extensions/docs/examples/api/systemInfo/main.js
index 2e3bc7b9768867a9e0d0c7133dff7623d826afb5..0a5f1b19cb5db5ca4e078f3f0842d4cf4e0fb30a 100644
--- a/chrome/common/extensions/docs/examples/api/systemInfo/main.js
+++ b/chrome/common/extensions/docs/examples/api/systemInfo/main.js
@@ -29,16 +29,62 @@ function stopMonitor() {
isStarted = false;
}
+function showStorageInfo(unit) {
+ table = "<tr><td>" + unit.id + "</td>" +
+ "<td>" + unit.type + "</td>" +
+ "<td>" + Math.round(unit.capacity/1024) + "</td>" +
+ "<td id=" + "\"" + unit.id + "\">" +
+ Math.round(unit.availableCapacity/1024) +
+ "</td></tr>\n";
+ return table;
+}
+
function init() {
document.getElementById("start-btn").onclick = startMonitor;
document.getElementById("stop-btn").onclick = stopMonitor;
+ // Get CPU information.
+ chrome.experimental.systemInfo.cpu.get(function(cpu) {
+ var cpuInfo = "<b>Architecture:</b> " + cpu.archName +
+ "<br><b>Model Name: </b>" + cpu.modelName +
+ "<br><b>Number of Processors: </b>" + cpu.numOfProcessors;
+ var div = document.getElementById("cpu-info");
+ div.innerHTML = cpuInfo;
+ });
+ chrome.experimental.systemInfo.cpu.onUpdated.addListener(function(info) {
+ var table = "<br><table border=\"1\">\n" +
+ "<tr><td width=\"80px\"><b>Index</b></td>";
+ for (var i = 0; i < info.usagePerProcessor.length; i++) {
+ table += "<td width=\"120px\"><b>" + i + "</b></td>";
+ }
+ table += "<td width=\"120px\"><b>Total</b></td></tr>\n";
+ table += "<tr><td><b>History Usage</b></td>";
+ for (var i = 0; i < info.usagePerProcessor.length; i++) {
+ table += "<td>" + Math.round(info.usagePerProcessor[i]) + "</td>";
+ }
+ table += "<td>" + Math.round(info.averageUsage) + "</td></tr>";
+ table += "</table>\n";
+ var div = document.getElementById("cpu-cores");
+ div.innerHTML = table;
+ });
+
+ // Get memory information.
+ chrome.experimental.systemInfo.memory.get(function(memory) {
+ var memoryInfo =
+ "<b>Total Capacity:</b> " + Math.round(memory.capacity / 1024) + "KB" +
+ "<br><b>Available Capacity: </b>" +
+ Math.round(memory.availableCapacity / 1024) + "KB"
+ var div = document.getElementById("memory-info");
+ div.innerHTML = memoryInfo;
+ });
+
+ // Get storage information.
chrome.experimental.systemInfo.storage.get(function(units) {
var table = "<table width=65% border=\"1\">\n" +
"<tr><td><b>ID</b></td>" +
- "<td>Type</td>" +
- "<td>Capacity (bytes)</td>" +
- "<td>Available (bytes)</td>" +
+ "<td><b>Type</b></td>" +
+ "<td><b>Total Capacity (KB)</b></td>" +
+ "<td><b>Available Capacity (KB)</b></td>" +
"</tr>\n";
for (var i = 0; i < units.length; i++) {
indicator[units[i].id] = 0;
@@ -50,13 +96,4 @@ function init() {
});
}
-function showStorageInfo(unit) {
- table = "<tr><td>" + unit.id + "</td>" +
- "<td>" + unit.type + "</td>" +
- "<td>" + unit.capacity + "</td>" +
- "<td id=" + "\"" + unit.id + "\">" + unit.availableCapacity + "</td>" +
- "</tr>\n";
- return table;
-}
-
document.addEventListener('DOMContentLoaded', init);
« no previous file with comments | « chrome/common/extensions/docs/examples/api/systemInfo/index.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698