| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 /** This view displays summary statistics on bandwidth usage. */ | 5 /** This view displays summary statistics on bandwidth usage. */ |
| 6 var BandwidthView = (function() { | 6 var BandwidthView = (function() { |
| 7 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 // We inherit from DivView. | 9 // We inherit from DivView. |
| 10 var superClass = DivView; | 10 var superClass = DivView; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 __proto__: superClass.prototype, | 54 __proto__: superClass.prototype, |
| 55 | 55 |
| 56 data_reduction_proxy_config_: null, | 56 data_reduction_proxy_config_: null, |
| 57 last_bypass_: null, | 57 last_bypass_: null, |
| 58 bad_proxy_config_: null, | 58 bad_proxy_config_: null, |
| 59 | 59 |
| 60 onLoadLogFinish: function(data) { | 60 onLoadLogFinish: function(data) { |
| 61 return this.onBadProxiesChanged(data.badProxies) && | 61 return this.onBadProxiesChanged(data.badProxies) && |
| 62 this.onDataReductionProxyInfoChanged(data.dataReductionProxyInfo) && | 62 this.onDataReductionProxyInfoChanged(data.dataReductionProxyInfo) && |
| 63 (this.onSessionNetworkStatsChanged(data.sessionNetworkStats) || | 63 (this.onSessionNetworkStatsChanged(data.sessionNetworkStats) || |
| 64 this.onHistoricNetworkStatsChanged(data.historicNetworkStats)); | 64 this.onHistoricNetworkStatsChanged(data.historicNetworkStats)); |
| 65 }, | 65 }, |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Retains information on bandwidth usage this session. | 68 * Retains information on bandwidth usage this session. |
| 69 */ | 69 */ |
| 70 onSessionNetworkStatsChanged: function(sessionNetworkStats) { | 70 onSessionNetworkStatsChanged: function(sessionNetworkStats) { |
| 71 this.sessionNetworkStats_ = sessionNetworkStats; | 71 this.sessionNetworkStats_ = sessionNetworkStats; |
| 72 return this.updateBandwidthUsageTable_(); | 72 return this.updateBandwidthUsageTable_(); |
| 73 }, | 73 }, |
| 74 | 74 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 99 this.data_reduction_proxy_config_ = info.proxy_config.params; | 99 this.data_reduction_proxy_config_ = info.proxy_config.params; |
| 100 } else { | 100 } else { |
| 101 $(BandwidthView.ENABLED_ID).innerText = 'Disabled'; | 101 $(BandwidthView.ENABLED_ID).innerText = 'Disabled'; |
| 102 $(BandwidthView.PROBE_STATUS_ID).innerText = 'N/A'; | 102 $(BandwidthView.PROBE_STATUS_ID).innerText = 'N/A'; |
| 103 this.data_reduction_proxy_config_ = null; | 103 this.data_reduction_proxy_config_ = null; |
| 104 } | 104 } |
| 105 | 105 |
| 106 this.updateDataReductionProxyConfig_(); | 106 this.updateDataReductionProxyConfig_(); |
| 107 | 107 |
| 108 for (var eventIndex = info.events.length - 1; eventIndex >= 0; | 108 for (var eventIndex = info.events.length - 1; eventIndex >= 0; |
| 109 --eventIndex) { | 109 --eventIndex) { |
| 110 var event = info.events[eventIndex]; | 110 var event = info.events[eventIndex]; |
| 111 var headerRow = addNode($(BandwidthView.EVENTS_TBODY_ID), 'tr'); | 111 var headerRow = addNode($(BandwidthView.EVENTS_TBODY_ID), 'tr'); |
| 112 var detailsRow = addNode($(BandwidthView.EVENTS_TBODY_ID), 'tr'); | 112 var detailsRow = addNode($(BandwidthView.EVENTS_TBODY_ID), 'tr'); |
| 113 | 113 |
| 114 var timeCell = addNode(headerRow, 'td'); | 114 var timeCell = addNode(headerRow, 'td'); |
| 115 var actionCell = addNode(headerRow, 'td'); | 115 var actionCell = addNode(headerRow, 'td'); |
| 116 var detailsCell = addNode(detailsRow, 'td'); | 116 var detailsCell = addNode(detailsRow, 'td'); |
| 117 detailsCell.colSpan = 2; | 117 detailsCell.colSpan = 2; |
| 118 detailsCell.className = 'data-reduction-proxy-view-events-details'; | 118 detailsCell.className = 'data-reduction-proxy-view-events-details'; |
| 119 var eventTime = timeutil.convertTimeTicksToDate(event.time); | 119 var eventTime = timeutil.convertTimeTicksToDate(event.time); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 var sessionOriginal = sessionNetworkStats.session_original_content_length; | 159 var sessionOriginal = sessionNetworkStats.session_original_content_length; |
| 160 var sessionReceived = sessionNetworkStats.session_received_content_length; | 160 var sessionReceived = sessionNetworkStats.session_received_content_length; |
| 161 var historicOriginal = | 161 var historicOriginal = |
| 162 historicNetworkStats.historic_original_content_length; | 162 historicNetworkStats.historic_original_content_length; |
| 163 var historicReceived = | 163 var historicReceived = |
| 164 historicNetworkStats.historic_received_content_length; | 164 historicNetworkStats.historic_received_content_length; |
| 165 | 165 |
| 166 var rows = []; | 166 var rows = []; |
| 167 rows.push({ | 167 rows.push({ |
| 168 title: 'Original (KB)', | 168 title: 'Original (KB)', |
| 169 sessionValue: bytesToRoundedKilobytes_(sessionOriginal), | 169 sessionValue: bytesToRoundedKilobytes_(sessionOriginal), |
| 170 historicValue: bytesToRoundedKilobytes_(historicOriginal) | 170 historicValue: bytesToRoundedKilobytes_(historicOriginal) |
| 171 }); | 171 }); |
| 172 rows.push({ | 172 rows.push({ |
| 173 title: 'Received (KB)', | 173 title: 'Received (KB)', |
| 174 sessionValue: bytesToRoundedKilobytes_(sessionReceived), | 174 sessionValue: bytesToRoundedKilobytes_(sessionReceived), |
| 175 historicValue: bytesToRoundedKilobytes_(historicReceived) | 175 historicValue: bytesToRoundedKilobytes_(historicReceived) |
| 176 }); | 176 }); |
| 177 rows.push({ | 177 rows.push({ |
| 178 title: 'Savings (KB)', | 178 title: 'Savings (KB)', |
| 179 sessionValue: | 179 sessionValue: |
| 180 bytesToRoundedKilobytes_(sessionOriginal - sessionReceived), | 180 bytesToRoundedKilobytes_(sessionOriginal - sessionReceived), |
| 181 historicValue: | 181 historicValue: |
| 182 bytesToRoundedKilobytes_(historicOriginal - historicReceived) | 182 bytesToRoundedKilobytes_(historicOriginal - historicReceived) |
| 183 }); | 183 }); |
| 184 rows.push({ | 184 rows.push({ |
| 185 title: 'Savings (%)', | 185 title: 'Savings (%)', |
| 186 sessionValue: getPercentSavings_(sessionOriginal, sessionReceived), | 186 sessionValue: getPercentSavings_(sessionOriginal, sessionReceived), |
| 187 historicValue: getPercentSavings_(historicOriginal, | 187 historicValue: getPercentSavings_(historicOriginal, historicReceived) |
| 188 historicReceived) | |
| 189 }); | 188 }); |
| 190 | 189 |
| 191 var input = new JsEvalContext({rows: rows}); | 190 var input = new JsEvalContext({rows: rows}); |
| 192 jstProcess(input, $(BandwidthView.STATS_BOX_ID)); | 191 jstProcess(input, $(BandwidthView.STATS_BOX_ID)); |
| 193 return true; | 192 return true; |
| 194 }, | 193 }, |
| 195 | 194 |
| 196 /** | 195 /** |
| 197 * Renders a Data Reduction Proxy event into the event tbody | 196 * Renders a Data Reduction Proxy event into the event tbody |
| 198 */ | 197 */ |
| 199 buildEventRow_: function(event, actionCell, detailsCell) { | 198 buildEventRow_: function(event, actionCell, detailsCell) { |
| 200 if (event.type == EventType.DATA_REDUCTION_PROXY_ENABLED && | 199 if (event.type == EventType.DATA_REDUCTION_PROXY_ENABLED && |
| 201 event.params.enabled == 0) { | 200 event.params.enabled == 0) { |
| 202 addTextNode(actionCell, 'DISABLED'); | 201 addTextNode(actionCell, 'DISABLED'); |
| 203 } else { | 202 } else { |
| 204 var actionText = | 203 var actionText = |
| 205 EventTypeNames[event.type].replace('DATA_REDUCTION_PROXY_', ''); | 204 EventTypeNames[event.type].replace('DATA_REDUCTION_PROXY_', ''); |
| 206 if (event.phase == EventPhase.PHASE_BEGIN || | 205 if (event.phase == EventPhase.PHASE_BEGIN || |
| 207 event.phase == EventPhase.PHASE_END) { | 206 event.phase == EventPhase.PHASE_END) { |
| 208 actionText = actionText + ' (' + | 207 actionText = actionText + ' (' + |
| 209 getKeyWithValue(EventPhase, event.phase) | 208 getKeyWithValue(EventPhase, event.phase).replace('PHASE_', '') + |
| 210 .replace('PHASE_', '') + ')'; | 209 ')'; |
| 211 } | 210 } |
| 212 | 211 |
| 213 addTextNode(actionCell, actionText); | 212 addTextNode(actionCell, actionText); |
| 214 this.createEventTable_(event.params, detailsCell); | 213 this.createEventTable_(event.params, detailsCell); |
| 215 } | 214 } |
| 216 }, | 215 }, |
| 217 | 216 |
| 218 /** | 217 /** |
| 219 * Updates the data reduction proxy summary block. | 218 * Updates the data reduction proxy summary block. |
| 220 */ | 219 */ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 249 } | 248 } |
| 250 | 249 |
| 251 if (hasBypassedProxy) { | 250 if (hasBypassedProxy) { |
| 252 break; | 251 break; |
| 253 } | 252 } |
| 254 } | 253 } |
| 255 } | 254 } |
| 256 } | 255 } |
| 257 | 256 |
| 258 if (hasBypassedProxy) { | 257 if (hasBypassedProxy) { |
| 259 this.createEventTable_(this.last_bypass_.params, | 258 this.createEventTable_( |
| 260 $(BandwidthView.BYPASS_STATE_ID)); | 259 this.last_bypass_.params, $(BandwidthView.BYPASS_STATE_ID)); |
| 261 } | 260 } |
| 262 | 261 |
| 263 this.createEventTable_(this.data_reduction_proxy_config_, | 262 this.createEventTable_( |
| 264 $(BandwidthView.PROXY_CONFIG_ID)); | 263 this.data_reduction_proxy_config_, |
| 265 setNodeDisplay($(BandwidthView.BYPASS_STATE_CONTAINER_ID), | 264 $(BandwidthView.PROXY_CONFIG_ID)); |
| 266 hasBypassedProxy); | 265 setNodeDisplay( |
| 266 $(BandwidthView.BYPASS_STATE_CONTAINER_ID), hasBypassedProxy); |
| 267 } | 267 } |
| 268 }, | 268 }, |
| 269 | 269 |
| 270 /** | 270 /** |
| 271 * Checks to see if a proxy server is in marked as bad. | 271 * Checks to see if a proxy server is in marked as bad. |
| 272 */ | 272 */ |
| 273 isMarkedAsBad_: function(proxy) { | 273 isMarkedAsBad_: function(proxy) { |
| 274 for (var entry in this.bad_proxy_config_) { | 274 for (var entry in this.bad_proxy_config_) { |
| 275 if (entry == proxy && | 275 if (entry == proxy && |
| 276 this.hasTimePassedLogTime_(this.bad_proxy_config_[entry])) { | 276 this.hasTimePassedLogTime_(this.bad_proxy_config_[entry])) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (value != null && value.toString() != '') { | 310 if (value != null && value.toString() != '') { |
| 311 if (key == 'net_error') { | 311 if (key == 'net_error') { |
| 312 if (value == 0) { | 312 if (value == 0) { |
| 313 value = 'OK'; | 313 value = 'OK'; |
| 314 } else { | 314 } else { |
| 315 value = netErrorToString(value); | 315 value = netErrorToString(value); |
| 316 } | 316 } |
| 317 } else if (key == 'bypass_type') { | 317 } else if (key == 'bypass_type') { |
| 318 value = getKeyWithValue(DataReductionProxyBypassEventType, value); | 318 value = getKeyWithValue(DataReductionProxyBypassEventType, value); |
| 319 } else if (key == 'bypass_action_type') { | 319 } else if (key == 'bypass_action_type') { |
| 320 value = getKeyWithValue(DataReductionProxyBypassActionType, | 320 value = |
| 321 value); | 321 getKeyWithValue(DataReductionProxyBypassActionType, value); |
| 322 } else if (key == 'expiration') { | 322 } else if (key == 'expiration') { |
| 323 value = timeutil.convertTimeTicksToDate(value); | 323 value = timeutil.convertTimeTicksToDate(value); |
| 324 } | 324 } |
| 325 var tableRow = addNode(tableNode, 'tr'); | 325 var tableRow = addNode(tableNode, 'tr'); |
| 326 addNodeWithText(tableRow, 'td', key); | 326 addNodeWithText(tableRow, 'td', key); |
| 327 addNodeWithText(tableRow, 'td', value); | 327 addNodeWithText(tableRow, 'td', value); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 } | 331 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 343 */ | 343 */ |
| 344 function getPercentSavings_(original, received) { | 344 function getPercentSavings_(original, received) { |
| 345 if (original > 0) { | 345 if (original > 0) { |
| 346 return ((original - received) * 100 / original).toFixed(1); | 346 return ((original - received) * 100 / original).toFixed(1); |
| 347 } | 347 } |
| 348 return '0.0'; | 348 return '0.0'; |
| 349 } | 349 } |
| 350 | 350 |
| 351 return BandwidthView; | 351 return BandwidthView; |
| 352 })(); | 352 })(); |
| OLD | NEW |