1// Copyright (c) 2011 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/** 6 * This view displays information on the state of all socket pools. 7 * 8 * - Shows a summary of the state of each socket pool at the top. 9 * - For each pool with allocated sockets or connect jobs, shows all its 10 * groups with any allocated sockets. 11 * 12 * @constructor 13 */ 14function SocketsView(mainBoxId, socketPoolDivId, socketPoolGroupsDivId, 15 closeIdleSocketsButtonId, socketPoolFlushButtonId) { 16 DivView.call(this, mainBoxId); 17 18 g_browser.addSocketPoolInfoObserver(this); 19 this.socketPoolDiv_ = document.getElementById(socketPoolDivId); 20 this.socketPoolGroupsDiv_ = document.getElementById(socketPoolGroupsDivId); 21 22 var closeIdleButton = document.getElementById(closeIdleSocketsButtonId); 23 closeIdleButton.onclick = this.closeIdleSockets.bind(this); 24 25 var flushSocketsButton = document.getElementById(socketPoolFlushButtonId); 26 flushSocketsButton.onclick = this.flushSocketPools.bind(this); 27} 28 29inherits(SocketsView, DivView); 30 31SocketsView.prototype.onSocketPoolInfoChanged = function(socketPoolInfo) { 32 this.socketPoolDiv_.innerHTML = ''; 33 this.socketPoolGroupsDiv_.innerHTML = ''; 34 35 if (!socketPoolInfo) 36 return; 37 38 var socketPools = SocketPoolWrapper.createArrayFrom(socketPoolInfo); 39 var tablePrinter = SocketPoolWrapper.createTablePrinter(socketPools); 40 tablePrinter.toHTML(this.socketPoolDiv_, 'styledTable'); 41 42 // Add table for each socket pool with information on each of its groups. 43 for (var i = 0; i < socketPools.length; ++i) { 44 if (socketPools[i].origPool.groups != undefined) { 45 var p = addNode(this.socketPoolGroupsDiv_, 'p'); 46 var br = addNode(p, 'br'); 47 var groupTablePrinter = socketPools[i].createGroupTablePrinter(); 48 groupTablePrinter.toHTML(p, 'styledTable'); 49 } 50 } 51}; 52 53SocketsView.prototype.closeIdleSockets = function() { 54 g_browser.sendCloseIdleSockets(); 55 g_browser.checkForUpdatedInfo(false); 56} 57 58SocketsView.prototype.flushSocketPools = function() { 59 g_browser.sendFlushSocketPools(); 60 g_browser.checkForUpdatedInfo(false); 61} 62