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

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

Issue 11415249: Remove systemInfo sample since it was landed to chrome-app-samples on github (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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 isStarted = false;
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 (isStarted) return;
21 systemInfo.storage.onAvailableCapacityChanged.addListener(onStorageChanged);
22 isStarted = true;
23 }
24
25 function stopMonitor() {
26 if (!isStarted) return;
27 systemInfo.storage.onAvailableCapacityChanged.removeListener(
28 onStorageChanged);
29 isStarted = false;
30 }
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
42 function init() {
43 document.getElementById("start-btn").onclick = startMonitor;
44 document.getElementById("stop-btn").onclick = stopMonitor;
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.
82 chrome.experimental.systemInfo.storage.get(function(units) {
83 var table = "<table width=65% border=\"1\">\n" +
84 "<tr><td><b>ID</b></td>" +
85 "<td><b>Type</b></td>" +
86 "<td><b>Total Capacity (KB)</b></td>" +
87 "<td><b>Available Capacity (KB)</b></td>" +
88 "</tr>\n";
89 for (var i = 0; i < units.length; i++) {
90 indicator[units[i].id] = 0;
91 table += showStorageInfo(units[i]);
92 }
93 table += "</table>\n";
94 var div = document.getElementById("storage-list");
95 div.innerHTML = table;
96 });
97 }
98
99 document.addEventListener('DOMContentLoaded', init);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698