Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/resources/settings/internet_page/network_summary.js

Issue 2651483002: MD Settings: Eliminate use of ES6 for Chrome OS (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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} */
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 return; 261 return;
262 } 262 }
263 // Async call, ensure id still exists. 263 // Async call, ensure id still exists.
264 if (!this.activeNetworkIds_.has(id)) 264 if (!this.activeNetworkIds_.has(id))
265 return; 265 return;
266 if (!state) { 266 if (!state) {
267 this.activeNetworkIds_.delete(id); 267 this.activeNetworkIds_.delete(id);
268 return; 268 return;
269 } 269 }
270 // Find the active state for the type and update it. 270 // Find the active state for the type and update it.
271 for (let i = 0; i < this.activeNetworkStates_.length; ++i) { 271 for (var i = 0; i < this.activeNetworkStates_.length; ++i) {
272 if (this.activeNetworkStates_[i].type == state.type) { 272 if (this.activeNetworkStates_[i].type == state.type) {
273 this.activeNetworkStates_[i] = state; 273 this.activeNetworkStates_[i] = state;
274 return; 274 return;
275 } 275 }
276 } 276 }
277 // Not found 277 // Not found
278 console.error('Active state not found: ' + state.Name); 278 console.error('Active state not found: ' + state.Name);
279 }, 279 },
280 280
281 /** 281 /**
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 * properties for all visible networks. 336 * properties for all visible networks.
337 * @param {!Array<!DeviceStateProperties>=} opt_deviceStates 337 * @param {!Array<!DeviceStateProperties>=} opt_deviceStates
338 * Optional list of state properties for all available devices. If not 338 * Optional list of state properties for all available devices. If not
339 * defined the existing list of device states will be used. 339 * defined the existing list of device states will be used.
340 * @private 340 * @private
341 */ 341 */
342 updateNetworkStates_: function(networkStates, opt_deviceStates) { 342 updateNetworkStates_: function(networkStates, opt_deviceStates) {
343 var newDeviceStates; 343 var newDeviceStates;
344 if (opt_deviceStates) { 344 if (opt_deviceStates) {
345 newDeviceStates = /** @type {!DeviceStateObject} */ ({}); 345 newDeviceStates = /** @type {!DeviceStateObject} */ ({});
346 for (let state of opt_deviceStates) 346 for (var s = 0; s < opt_deviceStates.length; ++s) {
347 var state = opt_deviceStates[s];
347 newDeviceStates[state.Type] = state; 348 newDeviceStates[state.Type] = state;
dpapad 2017/01/23 19:12:54 Nit: No need for temporary |state| variable, since
stevenjb 2017/01/24 02:02:04 Twice. state.Type and state.
349 }
348 } else { 350 } else {
349 newDeviceStates = this.deviceStates_; 351 newDeviceStates = this.deviceStates_;
350 } 352 }
351 353
352 // Clear any current networks. 354 // Clear any current networks.
353 var activeNetworkStatesByType = 355 var activeNetworkStatesByType =
354 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map); 356 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map);
355 357
356 // Complete list of states by type. 358 // Complete list of states by type.
357 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = { 359 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = {
358 Ethernet: [], 360 Ethernet: [],
359 WiFi: [], 361 WiFi: [],
360 Cellular: [], 362 Cellular: [],
361 WiMAX: [], 363 WiMAX: [],
362 VPN: [], 364 VPN: [],
363 }; 365 };
364 366
365 var firstConnectedNetwork = null; 367 var firstConnectedNetwork = null;
366 networkStates.forEach(function(state) { 368 networkStates.forEach(function(networkState) {
367 let type = state.Type; 369 var type = networkState.Type;
368 if (!activeNetworkStatesByType.has(type)) { 370 if (!activeNetworkStatesByType.has(type)) {
369 activeNetworkStatesByType.set(type, state); 371 activeNetworkStatesByType.set(type, networkState);
370 if (!firstConnectedNetwork && state.Type != CrOnc.Type.VPN && 372 if (!firstConnectedNetwork && networkState.Type != CrOnc.Type.VPN &&
371 state.ConnectionState == CrOnc.ConnectionState.CONNECTED) { 373 networkState.ConnectionState == CrOnc.ConnectionState.CONNECTED) {
372 firstConnectedNetwork = state; 374 firstConnectedNetwork = networkState;
373 } 375 }
374 } 376 }
375 newNetworkStateLists[type].push(state); 377 newNetworkStateLists[type].push(networkState);
376 }, this); 378 }, this);
dpapad 2017/01/23 19:12:54 Nit (optional): There is no usage of |this| inside
stevenjb 2017/01/24 02:02:04 Acknowledged.
377 379
378 this.defaultNetwork = firstConnectedNetwork; 380 this.defaultNetwork = firstConnectedNetwork;
379 381
380 // Create a VPN entry in deviceStates if there are any VPN networks. 382 // Create a VPN entry in deviceStates if there are any VPN networks.
381 if (newNetworkStateLists.VPN && newNetworkStateLists.VPN.length > 0) { 383 if (newNetworkStateLists.VPN && newNetworkStateLists.VPN.length > 0) {
382 newDeviceStates.VPN = /** @type {DeviceStateProperties} */ ({ 384 newDeviceStates.VPN = /** @type {DeviceStateProperties} */ ({
383 Type: CrOnc.Type.VPN, 385 Type: CrOnc.Type.VPN,
384 State: chrome.networkingPrivate.DeviceStateType.ENABLED 386 State: chrome.networkingPrivate.DeviceStateType.ENABLED
385 }); 387 });
386 } 388 }
387 389
388 // Push the active networks onto newActiveNetworkStates in order based on 390 // Push the active networks onto newActiveNetworkStates in order based on
389 // device priority, creating an empty state for devices with no networks. 391 // device priority, creating an empty state for devices with no networks.
390 let newActiveNetworkStates = []; 392 var newActiveNetworkStates = [];
391 this.activeNetworkIds_ = new Set; 393 this.activeNetworkIds_ = new Set;
392 let orderedDeviceTypes = [ 394 var orderedDeviceTypes = [
393 CrOnc.Type.ETHERNET, CrOnc.Type.WI_FI, CrOnc.Type.CELLULAR, 395 CrOnc.Type.ETHERNET, CrOnc.Type.WI_FI, CrOnc.Type.CELLULAR,
394 CrOnc.Type.WI_MAX, CrOnc.Type.VPN 396 CrOnc.Type.WI_MAX, CrOnc.Type.VPN
395 ]; 397 ];
396 for (let type of orderedDeviceTypes) { 398 for (var t = 0; t < orderedDeviceTypes.length; ++t) {
397 let device = newDeviceStates[type]; 399 var type = orderedDeviceTypes[t];
400 var device = newDeviceStates[type];
398 if (!device) 401 if (!device)
399 continue; 402 continue;
400 let state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type}; 403 var state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type};
401 if (state.Source === undefined && 404 if (state.Source === undefined &&
402 device.State == chrome.networkingPrivate.DeviceStateType.PROHIBITED) { 405 device.State == chrome.networkingPrivate.DeviceStateType.PROHIBITED) {
403 // Prohibited technologies are enforced by the device policy. 406 // Prohibited technologies are enforced by the device policy.
404 state.Source = CrOnc.Source.DEVICE_POLICY; 407 state.Source = CrOnc.Source.DEVICE_POLICY;
405 } 408 }
406 newActiveNetworkStates.push(state); 409 newActiveNetworkStates.push(state);
407 this.activeNetworkIds_.add(state.GUID); 410 this.activeNetworkIds_.add(state.GUID);
408 } 411 }
409 412
410 this.deviceStates_ = newDeviceStates; 413 this.deviceStates_ = newDeviceStates;
411 this.networkStateLists_ = newNetworkStateLists; 414 this.networkStateLists_ = newNetworkStateLists;
412 // Set activeNetworkStates last to rebuild the dom-repeat. 415 // Set activeNetworkStates last to rebuild the dom-repeat.
413 this.activeNetworkStates_ = newActiveNetworkStates; 416 this.activeNetworkStates_ = newActiveNetworkStates;
414 }, 417 },
415 }); 418 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698