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 /** | 5 /** |
6 * @fileoverview Polymer element for displaying a summary of network states | 6 * @fileoverview Polymer element for displaying a summary of network states |
7 * by type: Ethernet, WiFi, Cellular, WiMAX, and VPN. | 7 * by type: Ethernet, WiFi, Cellular, WiMAX, and VPN. |
8 */ | 8 */ |
9 | 9 |
10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ | 10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ |
11 var DeviceStateProperties; | 11 var DeviceStateProperties; |
12 | 12 |
13 /** | 13 /** |
14 * @typedef {{ | 14 * @typedef {{ |
15 * Ethernet: (DeviceStateProperties|undefined), | 15 * Ethernet: (DeviceStateProperties|undefined), |
16 * WiFi: (DeviceStateProperties|undefined), | 16 * WiFi: (DeviceStateProperties|undefined), |
17 * Cellular: (DeviceStateProperties|undefined), | 17 * Cellular: (DeviceStateProperties|undefined), |
18 * WiMAX: (DeviceStateProperties|undefined), | 18 * WiMAX: (DeviceStateProperties|undefined), |
19 * VPN: (DeviceStateProperties|undefined) | 19 * VPN: (DeviceStateProperties|undefined) |
20 * }} | 20 * }} |
21 */ | 21 */ |
22 var DeviceStateObject; | 22 var DeviceStateObject; |
23 | 23 |
24 /** | 24 /** |
25 * @typedef {{ | 25 * @typedef {{ |
26 * Ethernet: (!CrOnc.NetworkStateProperties|undefined), | |
27 * WiFi: (!CrOnc.NetworkStateProperties|undefined), | |
28 * Cellular: (!CrOnc.NetworkStateProperties|undefined), | |
29 * WiMAX: (!CrOnc.NetworkStateProperties|undefined), | |
30 * VPN: (!CrOnc.NetworkStateProperties|undefined) | |
31 * }} | |
32 */ | |
33 var NetworkStateObject; | |
34 | |
35 /** | |
36 * @typedef {{ | |
37 * Ethernet: (Array<CrOnc.NetworkStateProperties>|undefined), | 26 * Ethernet: (Array<CrOnc.NetworkStateProperties>|undefined), |
38 * WiFi: (Array<CrOnc.NetworkStateProperties>|undefined), | 27 * WiFi: (Array<CrOnc.NetworkStateProperties>|undefined), |
39 * Cellular: (Array<CrOnc.NetworkStateProperties>|undefined), | 28 * Cellular: (Array<CrOnc.NetworkStateProperties>|undefined), |
40 * WiMAX: (Array<CrOnc.NetworkStateProperties>|undefined), | 29 * WiMAX: (Array<CrOnc.NetworkStateProperties>|undefined), |
41 * VPN: (Array<CrOnc.NetworkStateProperties>|undefined) | 30 * VPN: (Array<CrOnc.NetworkStateProperties>|undefined) |
42 * }} | 31 * }} |
43 */ | 32 */ |
44 var NetworkStateListObject; | 33 var NetworkStateListObject; |
45 | 34 |
46 (function() { | |
47 | |
48 /** @const {!Array<chrome.networkingPrivate.NetworkType>} */ | |
49 var NETWORK_TYPES = [ | |
50 CrOnc.Type.ETHERNET, | |
51 CrOnc.Type.WI_FI, | |
52 CrOnc.Type.CELLULAR, | |
53 CrOnc.Type.WI_MAX, | |
54 CrOnc.Type.VPN | |
55 ]; | |
56 | |
57 Polymer({ | 35 Polymer({ |
58 is: 'network-summary', | 36 is: 'network-summary', |
59 | 37 |
60 properties: { | 38 properties: { |
61 /** | 39 /** |
62 * Highest priority connected network or null. | 40 * Highest priority connected network or null. |
63 * @type {?CrOnc.NetworkStateProperties} | 41 * @type {?CrOnc.NetworkStateProperties} |
64 */ | 42 */ |
65 defaultNetwork: { | 43 defaultNetwork: { |
66 type: Object, | 44 type: Object, |
67 value: null, | 45 value: null, |
68 notify: true | 46 notify: true, |
69 }, | 47 }, |
70 | 48 |
71 /** | 49 /** |
72 * The device state for each network device type. | 50 * The device state for each network device type. |
73 * @type {DeviceStateObject} | 51 * @type {DeviceStateObject} |
74 */ | 52 */ |
75 deviceStates: { | 53 deviceStates: { |
76 type: Object, | 54 type: Object, |
77 value: function() { return {}; }, | 55 value: function() { return {}; }, |
78 }, | 56 }, |
79 | 57 |
80 /** | 58 /** |
81 * Network state data for each network type. | 59 * Array of active network states, one per device type. |
82 * @type {NetworkStateObject} | 60 * @type {!Array<!CrOnc.NetworkStateProperties>} |
83 */ | 61 */ |
84 networkStates: { | 62 activeNetworkStates: { |
85 type: Object, | 63 type: Object, |
michaelpg
2016/07/20 19:36:37
Array
stevenjb
2016/07/20 20:29:16
Done.
| |
86 value: function() { return {}; }, | 64 value: function() { return []; }, |
87 }, | 65 }, |
88 | 66 |
89 /** | 67 /** |
90 * List of network state data for each network type. | 68 * List of network state data for each network type. |
91 * @type {NetworkStateListObject} | 69 * @type {NetworkStateListObject} |
92 */ | 70 */ |
93 networkStateLists: { | 71 networkStateLists: { |
94 type: Object, | 72 type: Object, |
95 value: function() { return {}; }, | 73 value: function() { return {}; }, |
96 }, | 74 }, |
97 | 75 |
98 /** | 76 /** |
99 * Interface for networkingPrivate calls, passed from internet_page. | 77 * Interface for networkingPrivate calls, passed from internet_page. |
100 * @type {NetworkingPrivate} | 78 * @type {NetworkingPrivate} |
101 */ | 79 */ |
102 networkingPrivate: { | 80 networkingPrivate: { |
103 type: Object, | 81 type: Object, |
104 } | 82 }, |
105 }, | 83 }, |
106 | 84 |
107 /** | 85 /** |
108 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. | 86 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. |
109 * @type {function(!Array<string>)} | 87 * @type {function(!Array<string>)} |
110 * @private | 88 * @private |
111 */ | 89 */ |
112 networkListChangedListener_: function() {}, | 90 networkListChangedListener_: function() {}, |
113 | 91 |
114 /** | 92 /** |
115 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged | 93 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged |
116 * event. | 94 * event. |
117 * @type {function(!Array<string>)} | 95 * @type {function(!Array<string>)} |
118 * @private | 96 * @private |
119 */ | 97 */ |
120 deviceStateListChangedListener_: function() {}, | 98 deviceStateListChangedListener_: function() {}, |
121 | 99 |
122 /** | 100 /** |
123 * Listener function for chrome.networkingPrivate.onNetworksChanged event. | 101 * Listener function for chrome.networkingPrivate.onNetworksChanged event. |
124 * @type {function(!Array<string>)} | 102 * @type {function(!Array<string>)} |
125 * @private | 103 * @private |
126 */ | 104 */ |
127 networksChangedListener_: function() {}, | 105 networksChangedListener_: function() {}, |
128 | 106 |
129 /** | 107 /** |
130 * Dictionary of GUIDs identifying primary (active) networks for each type. | 108 * Set of GUIDs identifying active networks for each type. |
michaelpg
2016/07/20 19:36:37
how does a Set of GUIDS identify networks on a per
stevenjb
2016/07/20 20:29:16
Updated comment.
| |
131 * @type {?Object} | 109 * @type {?Set<string>} |
132 * @private | 110 * @private |
133 */ | 111 */ |
134 networkIds_: null, | 112 activeNetworkIds_: null, |
135 | 113 |
136 /** @override */ | 114 /** @override */ |
137 attached: function() { | 115 attached: function() { |
138 this.networkIds_ = {}; | |
139 | |
140 this.getNetworkLists_(); | 116 this.getNetworkLists_(); |
141 | 117 |
142 this.networkListChangedListener_ = | 118 this.networkListChangedListener_ = |
143 this.onNetworkListChangedEvent_.bind(this); | 119 this.onNetworkListChangedEvent_.bind(this); |
144 this.networkingPrivate.onNetworkListChanged.addListener( | 120 this.networkingPrivate.onNetworkListChanged.addListener( |
145 this.networkListChangedListener_); | 121 this.networkListChangedListener_); |
146 | 122 |
147 this.deviceStateListChangedListener_ = | 123 this.deviceStateListChangedListener_ = |
148 this.onDeviceStateListChangedEvent_.bind(this); | 124 this.onDeviceStateListChangedEvent_.bind(this); |
149 this.networkingPrivate.onDeviceStateListChanged.addListener( | 125 this.networkingPrivate.onDeviceStateListChanged.addListener( |
(...skipping 10 matching lines...) Expand all Loading... | |
160 this.networkListChangedListener_); | 136 this.networkListChangedListener_); |
161 | 137 |
162 this.networkingPrivate.onDeviceStateListChanged.removeListener( | 138 this.networkingPrivate.onDeviceStateListChanged.removeListener( |
163 this.deviceStateListChangedListener_); | 139 this.deviceStateListChangedListener_); |
164 | 140 |
165 this.networkingPrivate.onNetworksChanged.removeListener( | 141 this.networkingPrivate.onNetworksChanged.removeListener( |
166 this.networksChangedListener_); | 142 this.networksChangedListener_); |
167 }, | 143 }, |
168 | 144 |
169 /** | 145 /** |
170 * Event triggered when the WiFi network-summary-item is expanded. | 146 * Event triggered when the network-summary-item is expanded. |
171 * @param {!{detail: {expanded: boolean, type: string}}} event | 147 * @param {!{detail: {expanded: boolean, type: string}}} event |
172 * @private | 148 * @private |
173 */ | 149 */ |
174 onWiFiExpanded_: function(event) { | 150 onExpanded_: function(event) { |
175 if (!event.detail.expanded) | 151 if (!event.detail.expanded) |
176 return; | 152 return; |
177 // Get the latest network states (only). | 153 // Get the latest network states. |
178 this.getNetworkStates_(); | 154 this.getNetworkStates_(); |
179 this.networkingPrivate.requestNetworkScan(); | 155 if (event.detail.type == CrOnc.Type.WI_FI) |
156 this.networkingPrivate.requestNetworkScan(); | |
180 }, | 157 }, |
181 | 158 |
182 /** | 159 /** |
183 * Event triggered when a network-summary-item is selected. | 160 * Event triggered when a network-summary-item is selected. |
184 * @param {!{detail: !CrOnc.NetworkStateProperties}} event | 161 * @param {!{detail: !CrOnc.NetworkStateProperties}} event |
185 * @private | 162 * @private |
186 */ | 163 */ |
187 onSelected_: function(event) { | 164 onSelected_: function(event) { |
188 var state = event.detail; | 165 var state = event.detail; |
189 if (this.canConnect_(state)) { | 166 if (this.canConnect_(state)) { |
(...skipping 28 matching lines...) Expand all Loading... | |
218 * @private | 195 * @private |
219 */ | 196 */ |
220 onDeviceStateListChangedEvent_: function() { this.getNetworkLists_(); }, | 197 onDeviceStateListChangedEvent_: function() { this.getNetworkLists_(); }, |
221 | 198 |
222 /** | 199 /** |
223 * networkingPrivate.onNetworksChanged event callback. | 200 * networkingPrivate.onNetworksChanged event callback. |
224 * @param {!Array<string>} networkIds The list of changed network GUIDs. | 201 * @param {!Array<string>} networkIds The list of changed network GUIDs. |
225 * @private | 202 * @private |
226 */ | 203 */ |
227 onNetworksChangedEvent_: function(networkIds) { | 204 onNetworksChangedEvent_: function(networkIds) { |
205 if (!this.activeNetworkIds_) | |
206 return; // Initial list of networks not received yet. | |
228 networkIds.forEach(function(id) { | 207 networkIds.forEach(function(id) { |
229 if (id in this.networkIds_) { | 208 if (this.activeNetworkIds_.has(id)) { |
230 this.networkingPrivate.getState( | 209 this.networkingPrivate.getState( |
231 id, this.getStateCallback_.bind(this, id)); | 210 id, this.getActiveStateCallback_.bind(this, id)); |
232 } | 211 } |
233 }, this); | 212 }, this); |
234 }, | 213 }, |
235 | 214 |
236 /** | 215 /** |
237 * Determines whether or not a network state can be connected to. | 216 * Determines whether or not a network state can be connected to. |
238 * @param {!CrOnc.NetworkStateProperties} state The network state. | 217 * @param {!CrOnc.NetworkStateProperties} state The network state. |
239 * @private | 218 * @private |
240 */ | 219 */ |
241 canConnect_: function(state) { | 220 canConnect_: function(state) { |
242 if (state.Type == CrOnc.Type.ETHERNET || | 221 if (state.Type == CrOnc.Type.ETHERNET || |
243 state.Type == CrOnc.Type.VPN && !this.defaultNetwork) { | 222 state.Type == CrOnc.Type.VPN && !this.defaultNetwork) { |
244 return false; | 223 return false; |
245 } | 224 } |
246 return state.ConnectionState == CrOnc.ConnectionState.NOT_CONNECTED; | 225 return state.ConnectionState == CrOnc.ConnectionState.NOT_CONNECTED; |
247 }, | 226 }, |
248 | 227 |
249 /** | 228 /** |
250 * networkingPrivate.getState event callback. | 229 * networkingPrivate.getState event callback for an active state. |
251 * @param {string} id The id of the requested state. | 230 * @param {string} id The id of the requested state. |
252 * @param {!chrome.networkingPrivate.NetworkStateProperties} state | 231 * @param {!chrome.networkingPrivate.NetworkStateProperties} state |
253 * @private | 232 * @private |
254 */ | 233 */ |
255 getStateCallback_: function(id, state) { | 234 getActiveStateCallback_: function(id, state) { |
256 if (chrome.runtime.lastError) { | 235 if (chrome.runtime.lastError) { |
257 var message = chrome.runtime.lastError.message; | 236 var message = chrome.runtime.lastError.message; |
258 if (message != 'Error.NetworkUnavailable') { | 237 if (message != 'Error.NetworkUnavailable') { |
259 console.error( | 238 console.error( |
260 'Unexpected networkingPrivate.getState error: ' + message + | 239 'Unexpected networkingPrivate.getState error: ' + message + |
261 ' For: ' + id); | 240 ' For: ' + id); |
262 } | 241 } |
263 return; | 242 return; |
264 } | 243 } |
265 // Async call, ensure id still exists. | 244 // Async call, ensure id still exists. |
266 if (!this.networkIds_[id]) | 245 if (!this.activeNetworkIds_.has(id)) |
267 return; | 246 return; |
268 if (!state) { | 247 if (!state) { |
269 this.networkIds_[id] = undefined; | 248 this.activeNetworkIds_.delete(id); |
270 return; | 249 return; |
271 } | 250 } |
272 this.updateNetworkState_(state.Type, state); | 251 // Find the active state for the type and update it. |
252 for (let i = 0; i < this.activeNetworkStates.length; ++i) { | |
253 if (this.activeNetworkStates[i].type == state.type) { | |
254 this.activeNetworkStates[i] = state; | |
255 return; | |
256 } | |
257 } | |
258 // Not found | |
259 console.error('Active state not found: ' + state.Name); | |
273 }, | 260 }, |
274 | 261 |
275 /** | 262 /** |
276 * Handles UI requests to connect to a network. | 263 * Handles UI requests to connect to a network. |
277 * TODO(stevenjb): Handle Cellular activation, etc. | 264 * TODO(stevenjb): Handle Cellular activation, etc. |
278 * @param {!CrOnc.NetworkStateProperties} state The network state. | 265 * @param {!CrOnc.NetworkStateProperties} state The network state. |
279 * @private | 266 * @private |
280 */ | 267 */ |
281 connectToNetwork_: function(state) { | 268 connectToNetwork_: function(state) { |
282 this.networkingPrivate.startConnect(state.GUID, function() { | 269 this.networkingPrivate.startConnect(state.GUID, function() { |
283 if (chrome.runtime.lastError) { | 270 if (chrome.runtime.lastError) { |
284 var message = chrome.runtime.lastError.message; | 271 var message = chrome.runtime.lastError.message; |
285 if (message != 'connecting') { | 272 if (message != 'connecting') { |
286 console.error( | 273 console.error( |
287 'Unexpected networkingPrivate.startConnect error: ' + message + | 274 'Unexpected networkingPrivate.startConnect error: ' + message + |
288 'For: ' + state.GUID); | 275 'For: ' + state.GUID); |
289 } | 276 } |
290 } | 277 } |
291 }); | 278 }); |
292 }, | 279 }, |
293 | 280 |
294 /** | 281 /** |
295 * Requests the list of device states and network states from Chrome. | 282 * Requests the list of device states and network states from Chrome. |
296 * Updates deviceStates, networkStates, and networkStateLists once the | 283 * Updates deviceStates, activeNetworkStates, and networkStateLists once the |
297 * results are returned from Chrome. | 284 * results are returned from Chrome. |
298 * @private | 285 * @private |
299 */ | 286 */ |
300 getNetworkLists_: function() { | 287 getNetworkLists_: function() { |
301 // First get the device states. | 288 // First get the device states. |
302 this.networkingPrivate.getDeviceStates( | 289 this.networkingPrivate.getDeviceStates(function(deviceStates) { |
303 function(deviceStates) { | 290 // Second get the network states. |
304 // Second get the network states. | 291 this.getNetworkStates_(deviceStates); |
305 this.getNetworkStates_(deviceStates); | 292 }.bind(this)); |
306 }.bind(this)); | |
307 }, | 293 }, |
308 | 294 |
309 /** | 295 /** |
310 * Requests the list of network states from Chrome. Updates networkStates and | 296 * Requests the list of network states from Chrome. Updates |
311 * networkStateLists once the results are returned from Chrome. | 297 * activeNetworkStates and networkStateLists once the results are returned |
298 * from Chrome. | |
312 * @param {!Array<!DeviceStateProperties>=} opt_deviceStates | 299 * @param {!Array<!DeviceStateProperties>=} opt_deviceStates |
313 * Optional list of state properties for all available devices. | 300 * Optional list of state properties for all available devices. |
314 * @private | 301 * @private |
315 */ | 302 */ |
316 getNetworkStates_: function(opt_deviceStates) { | 303 getNetworkStates_: function(opt_deviceStates) { |
317 var filter = { | 304 var filter = { |
318 networkType: chrome.networkingPrivate.NetworkType.ALL, | 305 networkType: chrome.networkingPrivate.NetworkType.ALL, |
319 visible: true, | 306 visible: true, |
320 configured: false | 307 configured: false |
321 }; | 308 }; |
322 this.networkingPrivate.getNetworks(filter, function(networkStates) { | 309 this.networkingPrivate.getNetworks(filter, function(networkStates) { |
323 this.updateNetworkStates_(networkStates, opt_deviceStates); | 310 this.updateNetworkStates_(networkStates, opt_deviceStates); |
324 }.bind(this)); | 311 }.bind(this)); |
325 }, | 312 }, |
326 | 313 |
327 /** | 314 /** |
328 * Called after network states are received from getNetworks. | 315 * Called after network states are received from getNetworks. |
329 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStates The state | 316 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStates The state |
330 * properties for all visible networks. | 317 * properties for all visible networks. |
331 * @param {!Array<!DeviceStateProperties>=} opt_deviceStates | 318 * @param {!Array<!DeviceStateProperties>=} opt_deviceStates |
332 * Optional list of state properties for all available devices. If not | 319 * Optional list of state properties for all available devices. If not |
333 * defined the existing list of device states will be used. | 320 * defined the existing list of device states will be used. |
334 * @private | 321 * @private |
335 */ | 322 */ |
336 updateNetworkStates_: function(networkStates, opt_deviceStates) { | 323 updateNetworkStates_: function(networkStates, opt_deviceStates) { |
337 var newDeviceStates; | 324 var newDeviceStates; |
338 if (opt_deviceStates) { | 325 if (opt_deviceStates) { |
339 newDeviceStates = /** @type {!DeviceStateObject} */({}); | 326 newDeviceStates = /** @type {!DeviceStateObject} */ ({}); |
340 opt_deviceStates.forEach(function(state) { | 327 for (let state of opt_deviceStates) |
341 newDeviceStates[state.Type] = state; | 328 newDeviceStates[state.Type] = state; |
342 }); | |
343 } else { | 329 } else { |
344 newDeviceStates = this.deviceStates; | 330 newDeviceStates = this.deviceStates; |
345 } | 331 } |
346 | 332 |
347 // Clear any current networks. | 333 // Clear any current networks. |
348 this.networkIds_ = {}; | 334 var activeNetworkStatesByType = |
349 | 335 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map); |
350 // Track the first (active) state for each type. | |
351 var foundTypes = {}; | |
352 | 336 |
353 // Complete list of states by type. | 337 // Complete list of states by type. |
354 /** @type {!NetworkStateListObject} */ var networkStateLists = { | 338 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = { |
355 Ethernet: [], | 339 Ethernet: [], |
356 WiFi: [], | 340 WiFi: [], |
357 Cellular: [], | 341 Cellular: [], |
358 WiMAX: [], | 342 WiMAX: [], |
359 VPN: [] | 343 VPN: [], |
360 }; | 344 }; |
361 | 345 |
362 var firstConnectedNetwork = null; | 346 var firstConnectedNetwork = null; |
363 networkStates.forEach(function(state) { | 347 networkStates.forEach(function(state) { |
364 var type = state.Type; | 348 let type = state.Type; |
365 if (!foundTypes[type]) { | 349 if (!activeNetworkStatesByType.has(type)) { |
366 foundTypes[type] = true; | 350 activeNetworkStatesByType.set(type, state); |
367 this.updateNetworkState_(type, state); | |
368 if (!firstConnectedNetwork && state.Type != CrOnc.Type.VPN && | 351 if (!firstConnectedNetwork && state.Type != CrOnc.Type.VPN && |
369 state.ConnectionState == CrOnc.ConnectionState.CONNECTED) { | 352 state.ConnectionState == CrOnc.ConnectionState.CONNECTED) { |
370 firstConnectedNetwork = state; | 353 firstConnectedNetwork = state; |
371 } | 354 } |
372 } | 355 } |
373 networkStateLists[type].push(state); | 356 newNetworkStateLists[type].push(state); |
374 }, this); | 357 }, this); |
375 | 358 |
376 this.defaultNetwork = firstConnectedNetwork; | 359 this.defaultNetwork = firstConnectedNetwork; |
377 | 360 |
378 // Set any types with a deviceState and no network to a default state, | |
379 // and any types not found to undefined. | |
380 NETWORK_TYPES.forEach(function(type) { | |
381 if (!foundTypes[type]) { | |
382 var defaultState = undefined; | |
383 if (newDeviceStates[type]) | |
384 defaultState = {GUID: '', Type: type}; | |
385 this.updateNetworkState_(type, defaultState); | |
386 } | |
387 }, this); | |
388 | |
389 this.networkStateLists = networkStateLists; | |
390 | |
391 // Create a VPN entry in deviceStates if there are any VPN networks. | 361 // Create a VPN entry in deviceStates if there are any VPN networks. |
392 if (networkStateLists.VPN && networkStateLists.VPN.length > 0) { | 362 if (newNetworkStateLists.VPN && newNetworkStateLists.VPN.length > 0) { |
393 newDeviceStates.VPN = /** @type {DeviceStateProperties} */ ({ | 363 newDeviceStates.VPN = /** @type {DeviceStateProperties} */ ({ |
394 Type: CrOnc.Type.VPN, | 364 Type: CrOnc.Type.VPN, |
395 State: chrome.networkingPrivate.DeviceStateType.ENABLED | 365 State: chrome.networkingPrivate.DeviceStateType.ENABLED |
396 }); | 366 }); |
397 } | 367 } |
398 | 368 |
369 // Push the active networks onto newActiveNetworkStates in device order, | |
370 // creating an empty state for devices with no networks. | |
371 var newActiveNetworkStates = []; | |
372 this.activeNetworkIds_ = new Set; | |
373 for (let type in newDeviceStates) { | |
374 var state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type}; | |
michaelpg
2016/07/20 19:36:37
opt nit: this is fine, but i would line break afte
stevenjb
2016/07/20 20:29:16
Blame clang.
| |
375 newActiveNetworkStates.push(state); | |
376 this.activeNetworkIds_.add(state.GUID); | |
377 } | |
378 | |
399 this.deviceStates = newDeviceStates; | 379 this.deviceStates = newDeviceStates; |
400 }, | 380 this.networkStateLists = newNetworkStateLists; |
401 | 381 // Set activeNetworkStates last to rebuild the dom-repeat. |
402 /** | 382 this.activeNetworkStates = newActiveNetworkStates; |
403 * Sets 'networkStates[type]' which will update the | |
404 * cr-network-list-network-item associated with 'type'. | |
405 * @param {string} type The network type. | |
406 * @param {!CrOnc.NetworkStateProperties|undefined} state The state properties | |
407 * for the network to associate with |type|. May be undefined if there are | |
408 * no networks matching |type|. | |
409 * @private | |
410 */ | |
411 updateNetworkState_: function(type, state) { | |
412 this.set('networkStates.' + type, state); | |
413 if (state) | |
414 this.networkIds_[state.GUID] = true; | |
415 }, | 383 }, |
416 }); | 384 }); |
417 })(); | |
OLD | NEW |