OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 g_main_view = null; | 5 var g_main_view = null; |
6 | 6 |
7 /** | 7 /** |
8 * This class is the root view object of the page. | 8 * This class is the root view object of the page. |
9 */ | 9 */ |
10 var MainView = (function() { | 10 var MainView = (function() { |
(...skipping 12 matching lines...) Expand all Loading... |
23 /** | 23 /** |
24 * Receiving notification to display memory snapshot. | 24 * Receiving notification to display memory snapshot. |
25 * @param {Object} Information about memory in JSON format. | 25 * @param {Object} Information about memory in JSON format. |
26 */ | 26 */ |
27 onSetSnapshot: function(browser) { | 27 onSetSnapshot: function(browser) { |
28 $('json').textContent = JSON.stringify(browser); | 28 $('json').textContent = JSON.stringify(browser); |
29 $('json').style.display = 'block'; | 29 $('json').style.display = 'block'; |
30 | 30 |
31 $('os-value').textContent = browser['os'] + ' (' + | 31 $('os-value').textContent = browser['os'] + ' (' + |
32 browser['os_version'] + ')'; | 32 browser['os_version'] + ')'; |
33 $('uptime-value').textContent = Math.floor(browser['uptime'] / 1000) + | 33 $('uptime-value').textContent = |
34 ' sec'; | 34 secondsToHMS(Math.floor(browser['uptime'] / 1000)); |
35 | 35 |
36 this.updateSnapshot(browser['processes']); | 36 this.updateSnapshot(browser['processes']); |
37 this.updateExtensions(browser['extensions']); | 37 this.updateExtensions(browser['extensions']); |
38 }, | 38 }, |
39 | 39 |
40 /** | 40 /** |
41 * Update process information table. | 41 * Update process information table. |
42 * @param {Object} processes information about memory. | 42 * @param {Object} processes information about memory. |
43 */ | 43 */ |
44 updateSnapshot: function(processes) { | 44 updateSnapshot: function(processes) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 129 } |
130 } | 130 } |
131 }; | 131 }; |
132 | 132 |
133 function JoinLinks(tab) { | 133 function JoinLinks(tab) { |
134 var line = ''; | 134 var line = ''; |
135 for (var l in tab['history']) { | 135 for (var l in tab['history']) { |
136 var history = tab['history'][l]; | 136 var history = tab['history'][l]; |
137 var title = (history['title'] == '') ? history['url'] : history['title']; | 137 var title = (history['title'] == '') ? history['url'] : history['title']; |
138 var url = '<a href="' + history['url'] + '">' + HTMLEscape(title) + | 138 var url = '<a href="' + history['url'] + '">' + HTMLEscape(title) + |
139 '</a> (' + history['time'] + ' sec. ago)'; | 139 '</a> (' + secondsToHMS(history['time']) + ' ago)'; |
140 if (l == tab['index']) { | 140 if (l == tab['index']) { |
141 url = '<strong>' + url + '</strong>'; | 141 url = '<strong>' + url + '</strong>'; |
142 } | 142 } |
143 line += '<dd>' + url; | 143 line += '<dd>' + url; |
144 } | 144 } |
145 return line; | 145 return line; |
146 }; | 146 }; |
147 | 147 |
| 148 /** |
| 149 * Produces a readable string int the format '<HH> hours <MM> min. <SS> sec.' |
| 150 * representing the amount of time provided as the number of seconds. |
| 151 * @param {number} totalSeconds The total amount of seconds. |
| 152 * @return {string} The formatted HH hours/hours MM min. SS sec. string |
| 153 */ |
| 154 function secondsToHMS(totalSeconds) { |
| 155 totalSeconds = Number(totalSeconds); |
| 156 var hour = Math.floor(totalSeconds / 3600); |
| 157 var min = Math.floor(totalSeconds % 3600 / 60); |
| 158 var sec = Math.floor(totalSeconds % 60); |
| 159 return (hour > 0 ? (hour + (hour > 1 ? ' hours ' : ' hour ')) : '') + |
| 160 (min > 0 ? (min + ' min. ') : '') + |
| 161 (sec + ' sec. '); |
| 162 } |
| 163 |
148 return MainView; | 164 return MainView; |
149 })(); | 165 })(); |
150 | 166 |
151 /** | 167 /** |
152 * Initialize everything once we have access to chrome://memory-internals. | 168 * Initialize everything once we have access to chrome://memory-internals. |
153 */ | 169 */ |
154 document.addEventListener('DOMContentLoaded', function() { | 170 document.addEventListener('DOMContentLoaded', function() { |
155 g_main_view = new MainView(); | 171 g_main_view = new MainView(); |
156 }); | 172 }); |
OLD | NEW |