Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @unrestricted | 5 MobileThrottling.NetworkThrottlingSelector = class { |
| 6 */ | |
| 7 MobileThrottling.NetworkConditionsSelector = class { | |
| 8 /** | 6 /** |
| 9 * @param {function(!Array<!MobileThrottling.NetworkConditionsGroup>):!Array<? SDK.NetworkManager.Conditions>} populateCallback | 7 * @param {function(!Array<!MobileThrottling.NetworkThrottlingConditionsGroup> ):!Array<?SDK.NetworkManager.Conditions>} populateCallback |
| 10 * @param {function(number)} selectCallback | 8 * @param {function(number)} selectCallback |
| 11 */ | 9 */ |
| 12 constructor(populateCallback, selectCallback) { | 10 constructor(populateCallback, selectCallback) { |
| 13 this._populateCallback = populateCallback; | 11 this._populateCallback = populateCallback; |
| 14 this._selectCallback = selectCallback; | 12 this._selectCallback = selectCallback; |
| 15 this._customSetting = Common.moduleSetting('customNetworkConditions'); | 13 MobileThrottling.customNetworkConditionsSetting().addChangeListener(this._po pulateOptions, this); |
| 16 this._customSetting.addChangeListener(this._populateOptions, this); | 14 SDK.multitargetNetworkManager.addEventListener( |
| 17 this._manager = SDK.multitargetNetworkManager; | 15 SDK.MultitargetNetworkManager.Events.ConditionsChanged, this._networkCon ditionsChanged, this); |
| 18 this._manager.addEventListener( | 16 /** @type {!Array<?SDK.NetworkManager.Conditions>} */ |
| 19 SDK.MultitargetNetworkManager.Events.ConditionsChanged, this._conditions Changed, this); | 17 this._options; |
| 20 this._populateOptions(); | 18 this._populateOptions(); |
| 21 } | 19 } |
| 22 | 20 |
| 23 /** | 21 /** |
| 24 * @param {number} throughput | |
| 25 * @param {boolean=} plainText | |
| 26 * @return {string} | |
| 27 */ | |
| 28 static throughputText(throughput, plainText) { | |
| 29 if (throughput < 0) | |
| 30 return ''; | |
| 31 var throughputInKbps = throughput / (1024 / 8); | |
| 32 var delimiter = plainText ? '' : ' '; | |
| 33 if (throughputInKbps < 1024) | |
| 34 return Common.UIString('%d%skb/s', throughputInKbps, delimiter); | |
| 35 if (throughputInKbps < 1024 * 10) | |
| 36 return Common.UIString('%.1f%sMb/s', throughputInKbps / 1024, delimiter); | |
| 37 return Common.UIString('%d%sMb/s', (throughputInKbps / 1024) | 0, delimiter) ; | |
| 38 } | |
| 39 | |
| 40 /** | |
| 41 * @param {!HTMLSelectElement} selectElement | 22 * @param {!HTMLSelectElement} selectElement |
| 23 * @return {!MobileThrottling.NetworkThrottlingSelector} | |
| 42 */ | 24 */ |
| 43 static decorateSelect(selectElement) { | 25 static decorateSelect(selectElement) { |
| 44 var options = []; | 26 var options = []; |
| 45 var selector = new MobileThrottling.NetworkConditionsSelector(populate, sele ct); | 27 var selector = new MobileThrottling.NetworkThrottlingSelector(populate, sele ct); |
| 46 selectElement.addEventListener('change', optionSelected, false); | 28 selectElement.addEventListener('change', optionSelected, false); |
| 29 return selector; | |
| 47 | 30 |
| 48 /** | 31 /** |
| 49 * @param {!Array.<!MobileThrottling.NetworkConditionsGroup>} groups | 32 * @param {!Array.<!MobileThrottling.NetworkThrottlingConditionsGroup>} grou ps |
| 50 * @return {!Array<?SDK.NetworkManager.Conditions>} | 33 * @return {!Array<?SDK.NetworkManager.Conditions>} |
| 51 */ | 34 */ |
| 52 function populate(groups) { | 35 function populate(groups) { |
| 53 selectElement.removeChildren(); | 36 selectElement.removeChildren(); |
| 54 options = []; | 37 options = []; |
| 55 for (var i = 0; i < groups.length; ++i) { | 38 for (var i = 0; i < groups.length; ++i) { |
| 56 var group = groups[i]; | 39 var group = groups[i]; |
| 57 var groupElement = selectElement.createChild('optgroup'); | 40 var groupElement = selectElement.createChild('optgroup'); |
| 58 groupElement.label = group.title; | 41 groupElement.label = group.title; |
| 59 for (var conditions of group.items) { | 42 for (var conditions of group.items) { |
| 60 var title = Common.UIString(conditions.title); | 43 var title = conditions.title; |
| 61 var option = new Option(title, title); | 44 var option = new Option(title, title); |
| 62 groupElement.appendChild(option); | 45 groupElement.appendChild(option); |
| 63 options.push(conditions); | 46 options.push(conditions); |
| 64 } | 47 } |
| 65 if (i === groups.length - 1) { | 48 if (i === groups.length - 1) { |
| 66 groupElement.appendChild(new Option(Common.UIString('Add\u2026'), Comm on.UIString('Add\u2026'))); | 49 groupElement.appendChild(new Option(Common.UIString('Add\u2026'), Comm on.UIString('Add\u2026'))); |
| 67 options.push(null); | 50 options.push(null); |
| 68 } | 51 } |
| 69 } | 52 } |
| 70 return options; | 53 return options; |
| 71 } | 54 } |
| 72 | 55 |
| 73 function optionSelected() { | 56 function optionSelected() { |
| 74 if (selectElement.selectedIndex === selectElement.options.length - 1) | 57 if (selectElement.selectedIndex === selectElement.options.length - 1) |
| 75 selector.revealAndUpdate(); | 58 selector._revealAndUpdate(); |
| 76 else | 59 else |
| 77 selector.optionSelected(options[selectElement.selectedIndex]); | 60 selector._optionSelected(options[selectElement.selectedIndex]); |
| 78 } | 61 } |
| 79 | 62 |
| 80 /** | 63 /** |
| 81 * @param {number} index | 64 * @param {number} index |
| 82 */ | 65 */ |
| 83 function select(index) { | 66 function select(index) { |
| 84 if (selectElement.selectedIndex !== index) | 67 if (selectElement.selectedIndex !== index) |
| 85 selectElement.selectedIndex = index; | 68 selectElement.selectedIndex = index; |
| 86 } | 69 } |
| 87 } | 70 } |
| 88 | 71 |
| 89 /** | 72 /** |
| 73 * @return {!UI.ToolbarCheckbox} | |
| 74 */ | |
| 75 static createOfflineToolbarCheckbox() { | |
| 76 var checkbox = new UI.ToolbarCheckbox( | |
| 77 Common.UIString('Offline'), Common.UIString('Force disconnected from net work'), forceOffline); | |
| 78 SDK.multitargetNetworkManager.addEventListener( | |
| 79 SDK.MultitargetNetworkManager.Events.ConditionsChanged, networkCondition sChanged); | |
| 80 checkbox.setChecked(SDK.multitargetNetworkManager.networkConditions() === SD K.NetworkManager.OfflineConditions); | |
| 81 | |
| 82 function forceOffline() { | |
| 83 if (checkbox.checked()) | |
| 84 SDK.multitargetNetworkManager.setNetworkConditions(SDK.NetworkManager.Of flineConditions); | |
| 85 else | |
| 86 SDK.multitargetNetworkManager.setNetworkConditions(MobileThrottling._las tNetworkThrottlingConditions); | |
| 87 } | |
| 88 | |
| 89 function networkConditionsChanged() { | |
| 90 checkbox.setChecked(SDK.multitargetNetworkManager.networkConditions() === SDK.NetworkManager.OfflineConditions); | |
| 91 } | |
| 92 | |
| 93 return checkbox; | |
| 94 } | |
| 95 | |
| 96 _populateOptions() { | |
| 97 var disabledGroup = {title: Common.UIString('Disabled'), items: [SDK.Network Manager.NoThrottlingConditions]}; | |
| 98 var presetsGroup = {title: Common.UIString('Common'), items: MobileThrottlin g.networkPresets}; | |
| 99 var advancedGroup = {title: Common.UIString('Advanced'), items: MobileThrott ling.advancedNetworkPresets}; | |
| 100 var customGroup = { | |
| 101 title: Common.UIString('Custom'), | |
| 102 items: MobileThrottling.customNetworkConditionsSetting().get() | |
| 103 }; | |
| 104 this._options = this._populateCallback([disabledGroup, presetsGroup, advance dGroup, customGroup]); | |
| 105 if (!this._networkConditionsChanged()) { | |
| 106 for (var i = this._options.length - 1; i >= 0; i--) { | |
| 107 if (this._options[i]) { | |
| 108 this._optionSelected(/** @type {!SDK.NetworkManager.Conditions} */ (th is._options[i])); | |
| 109 break; | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 _revealAndUpdate() { | |
| 116 Common.Revealer.reveal(MobileThrottling.customNetworkConditionsSetting()); | |
| 117 this._networkConditionsChanged(); | |
| 118 } | |
| 119 | |
| 120 /** | |
| 121 * @param {!SDK.NetworkManager.Conditions} conditions | |
| 122 */ | |
| 123 _optionSelected(conditions) { | |
| 124 SDK.multitargetNetworkManager.setNetworkConditions(conditions); | |
| 125 } | |
| 126 | |
| 127 /** | |
| 128 * @return {boolean} returns false if selected condition no longer exists | |
| 129 */ | |
| 130 _networkConditionsChanged() { | |
| 131 var value = SDK.multitargetNetworkManager.networkConditions(); | |
| 132 for (var index = 0; index < this._options.length; ++index) { | |
| 133 var option = this._options[index]; | |
| 134 if (option && option.download === value.download && option.upload === valu e.upload && | |
| 135 option.latency === value.latency) { | |
| 136 this._selectCallback(index); | |
| 137 return true; | |
| 138 } | |
| 139 } | |
| 140 return false; | |
| 141 } | |
| 142 }; | |
| 143 | |
| 144 MobileThrottling.MobileThrottlingSelector = class { | |
| 145 /** | |
| 146 * @param {function(!Array<!MobileThrottling.MobileThrottlingConditionsGroup>) :!MobileThrottling.ConditionsList} populateCallback | |
| 147 * @param {function(number)} selectCallback | |
| 148 */ | |
| 149 constructor(populateCallback, selectCallback) { | |
| 150 this._populateCallback = populateCallback; | |
| 151 this._selectCallback = selectCallback; | |
| 152 MobileThrottling.cpuThrottlingManager.addEventListener( | |
| 153 MobileThrottling.CPUThrottlingManager.Events.RateChanged, this._conditio nsChanged, this); | |
| 154 SDK.multitargetNetworkManager.addEventListener( | |
| 155 SDK.MultitargetNetworkManager.Events.ConditionsChanged, this._conditions Changed, this); | |
| 156 /** @type {!MobileThrottling.ConditionsList} */ | |
| 157 this._options = this._populateOptions(); | |
| 158 this._conditionsChanged(); | |
| 159 } | |
| 160 | |
| 161 /** | |
| 90 * @return {!UI.ToolbarMenuButton} | 162 * @return {!UI.ToolbarMenuButton} |
| 91 */ | 163 */ |
| 92 static createToolbarMenuButton() { | 164 static createToolbarMenuButton() { |
| 93 var button = new UI.ToolbarMenuButton(appendItems); | 165 var button = new UI.ToolbarMenuButton(appendItems); |
| 166 button.setTitle(Common.UIString('Throttling')); | |
| 94 button.setGlyph(''); | 167 button.setGlyph(''); |
| 95 button.turnIntoSelect(); | 168 button.turnIntoSelect(); |
| 96 | 169 |
| 97 /** @type {!Array<?SDK.NetworkManager.Conditions>} */ | 170 /** @type {!MobileThrottling.ConditionsList} */ |
| 98 var options = []; | 171 var options = []; |
| 99 var selectedIndex = -1; | 172 var selectedIndex = -1; |
| 100 var selector = new MobileThrottling.NetworkConditionsSelector(populate, sele ct); | 173 var selector = new MobileThrottling.MobileThrottlingSelector(populate, selec t); |
| 101 return button; | 174 return button; |
| 102 | 175 |
| 103 /** | 176 /** |
| 104 * @param {!UI.ContextMenu} contextMenu | 177 * @param {!UI.ContextMenu} contextMenu |
| 105 */ | 178 */ |
| 106 function appendItems(contextMenu) { | 179 function appendItems(contextMenu) { |
| 107 for (var index = 0; index < options.length; ++index) { | 180 for (var index = 0; index < options.length; ++index) { |
| 108 var conditions = options[index]; | 181 var conditions = options[index]; |
| 109 if (!conditions) { | 182 if (!conditions) { |
| 110 contextMenu.appendSeparator(); | 183 contextMenu.appendSeparator(); |
| 111 } else { | 184 continue; |
| 112 contextMenu.appendCheckboxItem( | |
| 113 Common.UIString(conditions.title), selector.optionSelected.bind(se lector, conditions), | |
| 114 selectedIndex === index); | |
| 115 } | 185 } |
| 186 if (conditions.title === MobileThrottling.CustomConditions.title && | |
| 187 conditions.description === MobileThrottling.CustomConditions.descrip tion) | |
| 188 continue; | |
| 189 contextMenu.appendCheckboxItem( | |
| 190 Common.UIString(conditions.title), | |
| 191 selector._optionSelected.bind(selector, /** @type {!MobileThrottling .Conditions} */ (conditions)), | |
| 192 selectedIndex === index); | |
| 116 } | 193 } |
| 117 contextMenu.appendItem(Common.UIString('Edit\u2026'), selector.revealAndUp date.bind(selector)); | |
| 118 } | 194 } |
| 119 | 195 |
| 120 /** | 196 /** |
| 121 * @param {!Array.<!MobileThrottling.NetworkConditionsGroup>} groups | 197 * @param {!Array.<!MobileThrottling.MobileThrottlingConditionsGroup>} group s |
| 122 * @return {!Array<?SDK.NetworkManager.Conditions>} | 198 * @return {!MobileThrottling.ConditionsList} |
| 123 */ | 199 */ |
| 124 function populate(groups) { | 200 function populate(groups) { |
| 125 options = []; | 201 options = []; |
| 126 for (var group of groups) { | 202 for (var group of groups) { |
| 127 for (var conditions of group.items) | 203 for (var conditions of group.items) |
| 128 options.push(conditions); | 204 options.push(conditions); |
| 129 options.push(null); | 205 options.push(null); |
| 130 } | 206 } |
| 131 return options; | 207 return options; |
| 132 } | 208 } |
| 133 | 209 |
| 134 /** | 210 /** |
| 135 * @param {number} index | 211 * @param {number} index |
| 136 */ | 212 */ |
| 137 function select(index) { | 213 function select(index) { |
| 138 selectedIndex = index; | 214 selectedIndex = index; |
| 139 button.setText(options[index].title); | 215 button.setText(options[index].title); |
| 216 button.setTitle(options[index].description || 'Throttling'); | |
| 140 } | 217 } |
| 141 } | 218 } |
| 142 | 219 |
| 143 /** | 220 /** |
| 144 * @return {!UI.ToolbarCheckbox} | 221 * @return {!MobileThrottling.ConditionsList} |
| 145 */ | 222 */ |
| 146 static createOfflineToolbarCheckbox() { | |
| 147 var checkbox = new UI.ToolbarCheckbox( | |
| 148 Common.UIString('Offline'), Common.UIString('Force disconnected from net work'), forceOffline); | |
| 149 SDK.multitargetNetworkManager.addEventListener( | |
| 150 SDK.MultitargetNetworkManager.Events.ConditionsChanged, networkCondition sChanged); | |
| 151 checkbox.setChecked(SDK.multitargetNetworkManager.networkConditions() === SD K.NetworkManager.OfflineConditions); | |
| 152 | |
| 153 function forceOffline() { | |
| 154 if (checkbox.checked()) { | |
| 155 MobileThrottling.NetworkConditionsSelector._lastNetworkConditions = | |
| 156 SDK.multitargetNetworkManager.networkConditions(); | |
| 157 SDK.multitargetNetworkManager.setNetworkConditions(SDK.NetworkManager.Of flineConditions); | |
| 158 } else { | |
| 159 SDK.multitargetNetworkManager.setNetworkConditions( | |
| 160 MobileThrottling.NetworkConditionsSelector._lastNetworkConditions); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 function networkConditionsChanged() { | |
| 165 var conditions = SDK.multitargetNetworkManager.networkConditions(); | |
| 166 checkbox.setChecked(conditions === SDK.NetworkManager.OfflineConditions); | |
| 167 } | |
| 168 return checkbox; | |
| 169 } | |
| 170 | |
| 171 _populateOptions() { | 223 _populateOptions() { |
| 172 var customGroup = {title: Common.UIString('Custom'), items: this._customSett ing.get()}; | 224 var disabledGroup = {title: Common.UIString('Disabled'), items: [MobileThrot tling.NoThrottlingConditions]}; |
| 173 var presetsGroup = {title: Common.UIString('Presets'), items: MobileThrottli ng.NetworkConditionsSelector.presets}; | 225 var presetsGroup = {title: Common.UIString('Presets'), items: MobileThrottli ng.mobilePresets}; |
| 174 var disabledGroup = {title: Common.UIString('Disabled'), items: [SDK.Network Manager.NoThrottlingConditions]}; | 226 var advancedGroup = {title: Common.UIString('Advanced'), items: MobileThrott ling.advancedMobilePresets}; |
| 175 this._options = this._populateCallback([disabledGroup, presetsGroup, customG roup]); | 227 return this._populateCallback([disabledGroup, presetsGroup, advancedGroup]); |
| 176 if (!this._conditionsChanged()) { | |
| 177 for (var i = this._options.length - 1; i >= 0; i--) { | |
| 178 if (this._options[i]) { | |
| 179 this.optionSelected(/** @type {!SDK.NetworkManager.Conditions} */ (thi s._options[i])); | |
| 180 break; | |
| 181 } | |
| 182 } | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 revealAndUpdate() { | |
| 187 Common.Revealer.reveal(this._customSetting); | |
| 188 this._conditionsChanged(); | |
| 189 } | 228 } |
| 190 | 229 |
| 191 /** | 230 /** |
| 192 * @param {!SDK.NetworkManager.Conditions} conditions | 231 * @param {!MobileThrottling.Conditions} conditions |
| 193 */ | 232 */ |
| 194 optionSelected(conditions) { | 233 _optionSelected(conditions) { |
| 195 this._manager.setNetworkConditions(conditions); | 234 SDK.multitargetNetworkManager.setNetworkConditions(conditions.network); |
| 235 MobileThrottling.cpuThrottlingManager.setRate(conditions.cpuThrottlingRate); | |
| 196 } | 236 } |
| 197 | 237 |
| 198 /** | |
| 199 * @return {boolean} | |
| 200 */ | |
| 201 _conditionsChanged() { | 238 _conditionsChanged() { |
| 202 var value = this._manager.networkConditions(); | 239 var networkConditions = SDK.multitargetNetworkManager.networkConditions(); |
| 240 var cpuThrottlingRate = MobileThrottling.cpuThrottlingManager.rate(); | |
| 203 for (var index = 0; index < this._options.length; ++index) { | 241 for (var index = 0; index < this._options.length; ++index) { |
| 204 var option = this._options[index]; | 242 var option = this._options[index]; |
| 205 if (option && option.download === value.download && option.upload === valu e.upload && | 243 if (option && option.network === networkConditions && option.cpuThrottling Rate === cpuThrottlingRate) { |
| 206 option.latency === value.latency && option.title === value.title) { | |
| 207 this._selectCallback(index); | 244 this._selectCallback(index); |
| 208 return true; | 245 return; |
| 209 } | 246 } |
| 210 } | 247 } |
| 211 return false; | 248 this._selectCallback(this._options.indexOf(MobileThrottling.CustomConditions )); |
| 212 } | 249 } |
| 213 }; | 250 }; |
| 214 | 251 |
| 252 MobileThrottling.trackNetworkConditions = function() { | |
|
dgozman
2017/06/30 00:54:16
Make this a member function of CPUThrottlingManage
chenwilliam
2017/06/30 22:01:11
Done.
| |
| 253 MobileThrottling._currentNetworkThrottlingConditions = SDK.NetworkManager.NoTh rottlingConditions; | |
| 254 SDK.multitargetNetworkManager.addEventListener( | |
| 255 SDK.MultitargetNetworkManager.Events.ConditionsChanged, networkConditionsC hanged); | |
| 256 | |
| 257 function networkConditionsChanged() { | |
| 258 MobileThrottling._lastNetworkThrottlingConditions = MobileThrottling._curren tNetworkThrottlingConditions; | |
| 259 MobileThrottling._currentNetworkThrottlingConditions = SDK.multitargetNetwor kManager.networkConditions(); | |
| 260 } | |
| 261 }; | |
| 262 | |
| 263 /** | |
| 264 * @return {!Common.Setting<!Array<!SDK.NetworkManager.Conditions>>} | |
| 265 */ | |
| 266 MobileThrottling.customNetworkConditionsSetting = function() { | |
|
dgozman
2017/06/30 00:54:16
Should this be public?
chenwilliam
2017/06/30 22:01:11
Private now.
| |
| 267 if (!MobileThrottling._customNetworkConditionsSetting) | |
| 268 MobileThrottling._customNetworkConditionsSetting = Common.moduleSetting('cus tomNetworkConditions'); | |
| 269 return MobileThrottling._customNetworkConditionsSetting; | |
| 270 }; | |
| 271 | |
| 272 /** | |
| 273 * @typedef {{ | |
| 274 * title: string, | |
| 275 * description: string, | |
| 276 * network: SDK.NetworkManager.Conditions, | |
| 277 * cpuThrottlingRate: number | |
| 278 * }} | |
| 279 **/ | |
| 280 MobileThrottling.Conditions; | |
| 281 | |
| 282 /** @enum {number} */ | |
| 283 MobileThrottling.CPUThrottlingRates = { | |
| 284 NoThrottling: 1, | |
| 285 MidTierMobile: 4, | |
| 286 LowEndMobile: 6, | |
| 287 }; | |
| 288 | |
| 289 /** @type {!MobileThrottling.Conditions} */ | |
| 290 MobileThrottling.NoThrottlingConditions = { | |
| 291 title: SDK.NetworkManager.NoThrottlingConditions.title, | |
| 292 description: Common.UIString('No throttling'), | |
| 293 network: SDK.NetworkManager.NoThrottlingConditions, | |
| 294 cpuThrottlingRate: MobileThrottling.CPUThrottlingRates.NoThrottling, | |
| 295 }; | |
| 296 | |
| 297 /** @type {!MobileThrottling.Conditions} */ | |
| 298 MobileThrottling.OfflineConditions = { | |
| 299 title: SDK.NetworkManager.OfflineConditions.title, | |
| 300 description: Common.UIString('No internet connectivity'), | |
| 301 network: SDK.NetworkManager.OfflineConditions, | |
| 302 cpuThrottlingRate: MobileThrottling.CPUThrottlingRates.NoThrottling, | |
| 303 }; | |
| 304 | |
| 305 /** @type {!MobileThrottling.Conditions} */ | |
| 306 MobileThrottling.LowEndMobileConditions = { | |
| 307 title: Common.UIString('Low-end mobile'), | |
| 308 description: Common.UIString('Slow 3G & 6x CPU slowdown'), | |
| 309 network: SDK.NetworkManager.Slow3GConditions, | |
| 310 cpuThrottlingRate: MobileThrottling.CPUThrottlingRates.LowEndMobile, | |
| 311 }; | |
| 312 | |
| 313 /** @type {!MobileThrottling.Conditions} */ | |
| 314 MobileThrottling.MidTierMobileConditions = { | |
| 315 title: Common.UIString('Mid-tier mobile'), | |
| 316 description: Common.UIString('Fast 3G & 4x CPU slowdown'), | |
| 317 network: SDK.NetworkManager.Fast3GConditions, | |
| 318 cpuThrottlingRate: MobileThrottling.CPUThrottlingRates.MidTierMobile, | |
| 319 }; | |
| 320 | |
| 321 /** | |
| 322 * @typedef {{ | |
| 323 * title: string, | |
| 324 * description: string | |
| 325 * }} | |
| 326 **/ | |
| 327 MobileThrottling.PlaceholderConditions; | |
| 328 | |
| 329 /** @type {!MobileThrottling.PlaceholderConditions} */ | |
| 330 MobileThrottling.CustomConditions = { | |
| 331 title: Common.UIString('Custom'), | |
| 332 description: Common.UIString('Check Network and Performance panels'), | |
| 333 }; | |
| 334 | |
| 215 /** @typedef {!{title: string, items: !Array<!SDK.NetworkManager.Conditions>}} * / | 335 /** @typedef {!{title: string, items: !Array<!SDK.NetworkManager.Conditions>}} * / |
| 216 MobileThrottling.NetworkConditionsGroup; | 336 MobileThrottling.NetworkThrottlingConditionsGroup; |
| 217 | 337 |
| 338 /** @typedef {!{title: string, items: !Array<!MobileThrottling.Conditions|!Mobil eThrottling.PlaceholderConditions>}} */ | |
| 339 MobileThrottling.MobileThrottlingConditionsGroup; | |
| 218 | 340 |
| 219 /** @type {!Array.<!SDK.NetworkManager.Conditions>} */ | 341 /** @typedef {!Array<?MobileThrottling.Conditions|!MobileThrottling.PlaceholderC onditions>} */ |
| 220 MobileThrottling.NetworkConditionsSelector.presets = [ | 342 MobileThrottling.ConditionsList; |
| 343 | |
| 344 /** @type {!Array.<!MobileThrottling.Conditions>} */ | |
| 345 MobileThrottling.mobilePresets = [ | |
| 346 MobileThrottling.MidTierMobileConditions, MobileThrottling.LowEndMobileConditi ons, MobileThrottling.CustomConditions | |
| 347 ]; | |
| 348 | |
| 349 /** @type {!Array.<!MobileThrottling.Conditions>} */ | |
| 350 MobileThrottling.advancedMobilePresets = [ | |
| 351 MobileThrottling.OfflineConditions, | |
| 352 ]; | |
| 353 | |
| 354 /** @type {!Array<!SDK.NetworkManager.Conditions>} */ | |
| 355 MobileThrottling.networkPresets = [ | |
| 356 SDK.NetworkManager.Fast3GConditions, | |
| 357 SDK.NetworkManager.Slow3GConditions, | |
| 358 ]; | |
| 359 | |
| 360 /** @type {!Array<!SDK.NetworkManager.Conditions>} */ | |
| 361 MobileThrottling.advancedNetworkPresets = [ | |
| 221 SDK.NetworkManager.OfflineConditions, | 362 SDK.NetworkManager.OfflineConditions, |
| 222 {title: 'Slow 3G', download: 500 * 1024 / 8 * .8, upload: 500 * 1024 / 8 * .8, latency: 400 * 5}, | |
| 223 {title: 'Fast 3G', download: 1.6 * 1024 * 1024 / 8 * .9, upload: 750 * 1024 / 8 * .9, latency: 150 * 3.75} | |
| 224 ]; | 363 ]; |
| 225 | 364 |
| 226 /** | 365 /** |
| 227 * @implements {UI.ActionDelegate} | 366 * @implements {UI.ActionDelegate} |
| 228 * @unrestricted | 367 * @unrestricted |
| 229 */ | 368 */ |
| 230 MobileThrottling.NetworkConditionsActionDelegate = class { | 369 MobileThrottling.NetworkConditionsActionDelegate = class { |
| 231 /** | 370 /** |
| 232 * @override | 371 * @override |
| 233 * @param {!UI.Context} context | 372 * @param {!UI.Context} context |
| 234 * @param {string} actionId | 373 * @param {string} actionId |
| 235 * @return {boolean} | 374 * @return {boolean} |
| 236 */ | 375 */ |
| 237 handleAction(context, actionId) { | 376 handleAction(context, actionId) { |
| 238 if (actionId === 'network-conditions.network-online') { | 377 if (actionId === 'network-conditions.network-online') { |
| 239 SDK.multitargetNetworkManager.setNetworkConditions(SDK.NetworkManager.NoTh rottlingConditions); | 378 SDK.multitargetNetworkManager.setNetworkConditions(SDK.NetworkManager.NoTh rottlingConditions); |
| 240 return true; | 379 return true; |
| 241 } | 380 } |
| 242 if (actionId === 'network-conditions.network-offline') { | 381 if (actionId === 'network-conditions.network-offline') { |
| 243 SDK.multitargetNetworkManager.setNetworkConditions(SDK.NetworkManager.Offl ineConditions); | 382 SDK.multitargetNetworkManager.setNetworkConditions(SDK.NetworkManager.Offl ineConditions); |
| 244 return true; | 383 return true; |
| 245 } | 384 } |
| 246 return false; | 385 return false; |
| 247 } | 386 } |
| 248 }; | 387 }; |
| OLD | NEW |