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

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

Issue 2300783002: MD Settings: Internet: Cleanup JS (Closed)
Patch Set: Feedback Created 4 years, 3 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 29 matching lines...) Expand all
40 * Highest priority connected network or null. 40 * Highest priority connected network or null.
41 * @type {?CrOnc.NetworkStateProperties} 41 * @type {?CrOnc.NetworkStateProperties}
42 */ 42 */
43 defaultNetwork: { 43 defaultNetwork: {
44 type: Object, 44 type: Object,
45 value: null, 45 value: null,
46 notify: true, 46 notify: true,
47 }, 47 },
48 48
49 /** 49 /**
50 * Interface for networkingPrivate calls, passed from internet_page.
51 * @type {NetworkingPrivate}
52 */
53 networkingPrivate: Object,
54
55 /**
50 * The device state for each network device type. 56 * The device state for each network device type.
51 * @type {DeviceStateObject} 57 * @private {DeviceStateObject}
52 */ 58 */
53 deviceStates: { 59 deviceStates_: {
54 type: Object, 60 type: Object,
55 value: function() { 61 value: function() {
56 return {}; 62 return {};
57 }, 63 },
58 }, 64 },
59 65
60 /** 66 /**
61 * Array of active network states, one per device type. 67 * Array of active network states, one per device type.
62 * @type {!Array<!CrOnc.NetworkStateProperties>} 68 * @private {!Array<!CrOnc.NetworkStateProperties>}
63 */ 69 */
64 activeNetworkStates: { 70 activeNetworkStates_: {
65 type: Array, 71 type: Array,
66 value: function() { 72 value: function() {
67 return []; 73 return [];
68 }, 74 },
69 }, 75 },
70 76
71 /** 77 /**
72 * List of network state data for each network type. 78 * List of network state data for each network type.
73 * @type {NetworkStateListObject} 79 * @private {NetworkStateListObject}
74 */ 80 */
75 networkStateLists: { 81 networkStateLists_: {
76 type: Object, 82 type: Object,
77 value: function() { 83 value: function() {
78 return {}; 84 return {};
79 }, 85 },
80 }, 86 },
81
82 /**
83 * Interface for networkingPrivate calls, passed from internet_page.
84 * @type {NetworkingPrivate}
85 */
86 networkingPrivate: {
87 type: Object,
88 },
89 }, 87 },
90 88
91 /** 89 /**
92 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. 90 * Listener function for chrome.networkingPrivate.onNetworkListChanged event.
93 * @type {function(!Array<string>)} 91 * @type {function(!Array<string>)}
94 * @private 92 * @private
95 */ 93 */
96 networkListChangedListener_: function() {}, 94 networkListChangedListener_: function() {},
97 95
98 /** 96 /**
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return; 250 return;
253 } 251 }
254 // Async call, ensure id still exists. 252 // Async call, ensure id still exists.
255 if (!this.activeNetworkIds_.has(id)) 253 if (!this.activeNetworkIds_.has(id))
256 return; 254 return;
257 if (!state) { 255 if (!state) {
258 this.activeNetworkIds_.delete(id); 256 this.activeNetworkIds_.delete(id);
259 return; 257 return;
260 } 258 }
261 // Find the active state for the type and update it. 259 // Find the active state for the type and update it.
262 for (let i = 0; i < this.activeNetworkStates.length; ++i) { 260 for (let i = 0; i < this.activeNetworkStates_.length; ++i) {
263 if (this.activeNetworkStates[i].type == state.type) { 261 if (this.activeNetworkStates_[i].type == state.type) {
264 this.activeNetworkStates[i] = state; 262 this.activeNetworkStates_[i] = state;
265 return; 263 return;
266 } 264 }
267 } 265 }
268 // Not found 266 // Not found
269 console.error('Active state not found: ' + state.Name); 267 console.error('Active state not found: ' + state.Name);
270 }, 268 },
271 269
272 /** 270 /**
273 * Handles UI requests to connect to a network. 271 * Handles UI requests to connect to a network.
274 * TODO(stevenjb): Handle Cellular activation, etc. 272 * TODO(stevenjb): Handle Cellular activation, etc.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 * defined the existing list of device states will be used. 328 * defined the existing list of device states will be used.
331 * @private 329 * @private
332 */ 330 */
333 updateNetworkStates_: function(networkStates, opt_deviceStates) { 331 updateNetworkStates_: function(networkStates, opt_deviceStates) {
334 var newDeviceStates; 332 var newDeviceStates;
335 if (opt_deviceStates) { 333 if (opt_deviceStates) {
336 newDeviceStates = /** @type {!DeviceStateObject} */ ({}); 334 newDeviceStates = /** @type {!DeviceStateObject} */ ({});
337 for (let state of opt_deviceStates) 335 for (let state of opt_deviceStates)
338 newDeviceStates[state.Type] = state; 336 newDeviceStates[state.Type] = state;
339 } else { 337 } else {
340 newDeviceStates = this.deviceStates; 338 newDeviceStates = this.deviceStates_;
341 } 339 }
342 340
343 // Clear any current networks. 341 // Clear any current networks.
344 var activeNetworkStatesByType = 342 var activeNetworkStatesByType =
345 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map); 343 /** @type {!Map<string, !CrOnc.NetworkStateProperties>} */ (new Map);
346 344
347 // Complete list of states by type. 345 // Complete list of states by type.
348 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = { 346 /** @type {!NetworkStateListObject} */ var newNetworkStateLists = {
349 Ethernet: [], 347 Ethernet: [],
350 WiFi: [], 348 WiFi: [],
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 ]; 384 ];
387 for (let type of orderedDeviceTypes) { 385 for (let type of orderedDeviceTypes) {
388 let device = newDeviceStates[type]; 386 let device = newDeviceStates[type];
389 if (!device) 387 if (!device)
390 continue; 388 continue;
391 let state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type}; 389 let state = activeNetworkStatesByType.get(type) || {GUID: '', Type: type};
392 newActiveNetworkStates.push(state); 390 newActiveNetworkStates.push(state);
393 this.activeNetworkIds_.add(state.GUID); 391 this.activeNetworkIds_.add(state.GUID);
394 } 392 }
395 393
396 this.deviceStates = newDeviceStates; 394 this.deviceStates_ = newDeviceStates;
397 this.networkStateLists = newNetworkStateLists; 395 this.networkStateLists_ = newNetworkStateLists;
398 // Set activeNetworkStates last to rebuild the dom-repeat. 396 // Set activeNetworkStates last to rebuild the dom-repeat.
399 this.activeNetworkStates = newActiveNetworkStates; 397 this.activeNetworkStates_ = newActiveNetworkStates;
400 }, 398 },
401 }); 399 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698