Commit 3b8a1974 authored by hongbo.min@intel.com's avatar hongbo.min@intel.com

Add an example for showing how to use systemInfo API.

BUG=136519
TEST=None

Review URL: https://chromiumcodereview.appspot.com/10882059

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153637 0039d316-1c4b-4281-b951-d872f2087c98
parent d304f4b4
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> System Information </title>
<script src="main.js"></script>
</head>
<body>
<div id="title"><b>Storage Information</b></div>
<div id="storage-list">
<i>Loading ...</i>
</div>
<div>
<i>Monitor free space change? </i>
<input type="button" value="Start" id="start-btn"></input>
<input type="button" value="Stop" id="stop-btn"></input>
</div>
</body>
</html>
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var systemInfo = chrome.experimental.systemInfo;
var indicator = {}
var isStarted = false;
function onStorageChanged(info) {
var elem = document.getElementById(info.id);
if (indicator[info.id]++ % 2)
elem.bgColor = "green";
else
elem.bgColor = "white";
elem.innerHTML = info.availableCapacity;
}
function startMonitor() {
if (isStarted) return;
systemInfo.storage.onAvailableCapacityChanged.addListener(onStorageChanged);
isStarted = true;
}
function stopMonitor() {
if (!isStarted) return;
systemInfo.storage.onAvailableCapacityChanged.removeListener(
onStorageChanged);
isStarted = false;
}
function init() {
document.getElementById("start-btn").onclick = startMonitor;
document.getElementById("stop-btn").onclick = stopMonitor;
chrome.experimental.systemInfo.storage.get(function(info) {
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>" +
"</tr>\n";
for (var i = 0; i < info.units.length; i++) {
indicator[info.units[i].id] = 0;
table += showStorageInfo(info.units[i]);
}
table += "</table>\n";
var div = document.getElementById("storage-list");
div.innerHTML = table;
});
}
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);
{
"version": "0.1",
"name": "SystemInfo APIs",
"permissions": ["experimental"],
"manifest_version": 2,
"description": "Show disk capacity via SystemInfo API",
"app": {
"launch": {
"local_path": "index.html"
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment