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.
6 * This view displays information on the state of all socket pools.
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.
12 var SocketsView
= (function() {
15 // We inherit from DivView.
16 var superClass
= DivView
;
21 function SocketsView() {
22 assertFirstConstructorCall(SocketsView
);
24 // Call superclass's constructor.
25 superClass
.call(this, SocketsView
.MAIN_BOX_ID
);
27 g_browser
.addSocketPoolInfoObserver(this, true);
28 this.socketPoolDiv_
= $(SocketsView
.SOCKET_POOL_DIV_ID
);
29 this.socketPoolGroupsDiv_
= $(SocketsView
.SOCKET_POOL_GROUPS_DIV_ID
);
31 var closeIdleButton
= $(SocketsView
.CLOSE_IDLE_SOCKETS_BUTTON_ID
);
32 closeIdleButton
.onclick
= this.closeIdleSockets
.bind(this);
34 var flushSocketsButton
= $(SocketsView
.SOCKET_POOL_FLUSH_BUTTON_ID
);
35 flushSocketsButton
.onclick
= this.flushSocketPools
.bind(this);
38 SocketsView
.TAB_ID
= 'tab-handle-sockets';
39 SocketsView
.TAB_NAME
= 'Sockets';
40 SocketsView
.TAB_HASH
= '#sockets';
42 // IDs for special HTML elements in sockets_view.html
43 SocketsView
.MAIN_BOX_ID
= 'sockets-view-tab-content';
44 SocketsView
.SOCKET_POOL_DIV_ID
= 'sockets-view-pool-div';
45 SocketsView
.SOCKET_POOL_GROUPS_DIV_ID
= 'sockets-view-pool-groups-div';
46 SocketsView
.CLOSE_IDLE_SOCKETS_BUTTON_ID
= 'sockets-view-close-idle-button';
47 SocketsView
.SOCKET_POOL_FLUSH_BUTTON_ID
= 'sockets-view-flush-button';
49 cr
.addSingletonGetter(SocketsView
);
51 SocketsView
.prototype = {
52 // Inherit the superclass's methods.
53 __proto__
: superClass
.prototype,
55 onLoadLogFinish: function(data
) {
56 return this.onSocketPoolInfoChanged(data
.socketPoolInfo
);
59 onSocketPoolInfoChanged: function(socketPoolInfo
) {
60 this.socketPoolDiv_
.innerHTML
= '';
61 this.socketPoolGroupsDiv_
.innerHTML
= '';
66 var socketPools
= SocketPoolWrapper
.createArrayFrom(socketPoolInfo
);
67 var tablePrinter
= SocketPoolWrapper
.createTablePrinter(socketPools
);
68 tablePrinter
.toHTML(this.socketPoolDiv_
, 'styled-table');
70 // Add table for each socket pool with information on each of its groups.
71 for (var i
= 0; i
< socketPools
.length
; ++i
) {
72 if (socketPools
[i
].origPool
.groups
!= undefined) {
73 var p
= addNode(this.socketPoolGroupsDiv_
, 'p');
74 var br
= addNode(p
, 'br');
75 var groupTablePrinter
= socketPools
[i
].createGroupTablePrinter();
76 groupTablePrinter
.toHTML(p
, 'styled-table');
82 closeIdleSockets: function() {
83 g_browser
.sendCloseIdleSockets();
84 g_browser
.checkForUpdatedInfo(false);
87 flushSocketPools: function() {
88 g_browser
.sendFlushSocketPools();
89 g_browser
.checkForUpdatedInfo(false);