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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 systemInfo = chrome.experimental.systemInfo; 5 var systemInfo = chrome.experimental.systemInfo;
6 6
7 var indicator = {} 7 var indicator = {}
8 var isStarted = false; 8 var isStarted = false;
9 9
10 function onStorageChanged(info) { 10 function onStorageChanged(info) {
(...skipping 11 matching lines...) Expand all
22 isStarted = true; 22 isStarted = true;
23 } 23 }
24 24
25 function stopMonitor() { 25 function stopMonitor() {
26 if (!isStarted) return; 26 if (!isStarted) return;
27 systemInfo.storage.onAvailableCapacityChanged.removeListener( 27 systemInfo.storage.onAvailableCapacityChanged.removeListener(
28 onStorageChanged); 28 onStorageChanged);
29 isStarted = false; 29 isStarted = false;
30 } 30 }
31 31
32 function showStorageInfo(unit) {
33 table = "<tr><td>" + unit.id + "</td>" +
34 "<td>" + unit.type + "</td>" +
35 "<td>" + Math.round(unit.capacity/1024) + "</td>" +
36 "<td id=" + "\"" + unit.id + "\">" +
37 Math.round(unit.availableCapacity/1024) +
38 "</td></tr>\n";
39 return table;
40 }
41
32 function init() { 42 function init() {
33 document.getElementById("start-btn").onclick = startMonitor; 43 document.getElementById("start-btn").onclick = startMonitor;
34 document.getElementById("stop-btn").onclick = stopMonitor; 44 document.getElementById("stop-btn").onclick = stopMonitor;
35 45
46 // Get CPU information.
47 chrome.experimental.systemInfo.cpu.get(function(cpu) {
48 var cpuInfo = "<b>Architecture:</b> " + cpu.archName +
49 "<br><b>Model Name: </b>" + cpu.modelName +
50 "<br><b>Number of Processors: </b>" + cpu.numOfProcessors;
51 var div = document.getElementById("cpu-info");
52 div.innerHTML = cpuInfo;
53 });
54 chrome.experimental.systemInfo.cpu.onUpdated.addListener(function(info) {
55 var table = "<br><table border=\"1\">\n" +
56 "<tr><td width=\"80px\"><b>Index</b></td>";
57 for (var i = 0; i < info.usagePerProcessor.length; i++) {
58 table += "<td width=\"120px\"><b>" + i + "</b></td>";
59 }
60 table += "<td width=\"120px\"><b>Total</b></td></tr>\n";
61 table += "<tr><td><b>History Usage</b></td>";
62 for (var i = 0; i < info.usagePerProcessor.length; i++) {
63 table += "<td>" + Math.round(info.usagePerProcessor[i]) + "</td>";
64 }
65 table += "<td>" + Math.round(info.averageUsage) + "</td></tr>";
66 table += "</table>\n";
67 var div = document.getElementById("cpu-cores");
68 div.innerHTML = table;
69 });
70
71 // Get memory information.
72 chrome.experimental.systemInfo.memory.get(function(memory) {
73 var memoryInfo =
74 "<b>Total Capacity:</b> " + Math.round(memory.capacity / 1024) + "KB" +
75 "<br><b>Available Capacity: </b>" +
76 Math.round(memory.availableCapacity / 1024) + "KB"
77 var div = document.getElementById("memory-info");
78 div.innerHTML = memoryInfo;
79 });
80
81 // Get storage information.
36 chrome.experimental.systemInfo.storage.get(function(units) { 82 chrome.experimental.systemInfo.storage.get(function(units) {
37 var table = "<table width=65% border=\"1\">\n" + 83 var table = "<table width=65% border=\"1\">\n" +
38 "<tr><td><b>ID</b></td>" + 84 "<tr><td><b>ID</b></td>" +
39 "<td>Type</td>" + 85 "<td><b>Type</b></td>" +
40 "<td>Capacity (bytes)</td>" + 86 "<td><b>Total Capacity (KB)</b></td>" +
41 "<td>Available (bytes)</td>" + 87 "<td><b>Available Capacity (KB)</b></td>" +
42 "</tr>\n"; 88 "</tr>\n";
43 for (var i = 0; i < units.length; i++) { 89 for (var i = 0; i < units.length; i++) {
44 indicator[units[i].id] = 0; 90 indicator[units[i].id] = 0;
45 table += showStorageInfo(units[i]); 91 table += showStorageInfo(units[i]);
46 } 92 }
47 table += "</table>\n"; 93 table += "</table>\n";
48 var div = document.getElementById("storage-list"); 94 var div = document.getElementById("storage-list");
49 div.innerHTML = table; 95 div.innerHTML = table;
50 }); 96 });
51 } 97 }
52 98
53 function showStorageInfo(unit) {
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); 99 document.addEventListener('DOMContentLoaded', init);
OLDNEW
« 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