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

Side by Side Diff: chrome/browser/resources/options2/chromeos/internet_detail.js

Issue 10204017: Throttle updates to the internet details page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with trunk. Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 cr.define('options.internet', function() { 5 cr.define('options.internet', function() {
6 var OptionsPage = options.OptionsPage; 6 var OptionsPage = options.OptionsPage;
7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; 7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
8 8
9 /**
10 * Minimum delay in milliseconds before updating controls. Used to
11 * consolidate update requests resulting from preference update
12 * notifications.
13 * @type {Number}
14 * @const
15 */
16 var minimumUpdateContentsDelay_ = 50;
17
18 /**
19 * Time of the last request to update controls in milliseconds.
20 * @type {Number}
21 */
22 var lastContentsUpdateRequest_ = 0;
23
24 /**
25 * Time of the last update to the controls in milliseconds.
26 * @type {Number}
27 */
28 var lastContentsUpdate_ = 0;
29
9 /* 30 /*
10 * Helper function to set hidden attribute for elements matching a selector. 31 * Helper function to set hidden attribute for elements matching a selector.
11 * @param {string} selector CSS selector for extracting a list of elements. 32 * @param {string} selector CSS selector for extracting a list of elements.
12 * @param {bool} hidden New hidden value. 33 * @param {bool} hidden New hidden value.
13 */ 34 */
14 function updateHidden(selector, hidden) { 35 function updateHidden(selector, hidden) {
15 var elements = cr.doc.querySelectorAll(selector); 36 var elements = cr.doc.querySelectorAll(selector);
16 for (var i = 0, el; el = elements[i]; i++) { 37 for (var i = 0, el; el = elements[i]; i++) {
17 el.hidden = hidden; 38 el.hidden = hidden;
18 } 39 }
19 } 40 }
20 41
21 /** 42 /**
22 * Monitor pref change of given element. 43 * Monitor pref change of given element.
23 * @param {Element} el Target element. 44 * @param {Element} el Target element.
24 */ 45 */
25 function observePrefsUI(el) { 46 function observePrefsUI(el) {
26 Preferences.getInstance().addEventListener(el.pref, handlePrefUpdate); 47 Preferences.getInstance().addEventListener(el.pref, handlePrefUpdate);
27 } 48 }
28 49
29 /** 50 /**
30 * UI pref change handler. 51 * UI pref change handler.
31 * @param {Event} e The update event. 52 * @param {Event} e The update event.
32 */ 53 */
33 function handlePrefUpdate(e) { 54 function handlePrefUpdate(e) {
34 DetailsInternetPage.getInstance().updateControls(); 55 var now = new Date();
56 requestUpdateControls(now.getTime());
57 }
58
59 /**
60 * Throttles the frequency of updating controls to accelerate loading of the
61 * page.
62 * @param {Number} when Timestamp for the update request.
63 */
64 function requestUpdateControls(when) {
65 if (when < lastContentsUpdate_)
66 return;
67 var now = new Date();
68 var time = now.getTime();
69 if (!lastContentsUpdateRequest_)
70 lastContentsUpdateRequest_ = time;
71 var elapsed = time - lastContentsUpdateRequest_;
72 if (elapsed > minimumUpdateContentsDelay_) {
73 DetailsInternetPage.getInstance().updateControls();
74 } else {
75 setTimeout(function() {
76 requestUpdateControls(when);
77 }, minimumUpdateContentsDelay_);
78 }
79 lastContentsUpdateRequest_ = time;
35 } 80 }
36 81
37 ///////////////////////////////////////////////////////////////////////////// 82 /////////////////////////////////////////////////////////////////////////////
38 // DetailsInternetPage class: 83 // DetailsInternetPage class:
39 84
40 /** 85 /**
41 * Encapsulated handling of ChromeOS internet details overlay page. 86 * Encapsulated handling of ChromeOS internet details overlay page.
42 * @constructor 87 * @constructor
43 */ 88 */
44 function DetailsInternetPage() { 89 function DetailsInternetPage() {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 for (var x = 0; x < selectedItems.length; x++) { 312 for (var x = 0; x < selectedItems.length; x++) {
268 $('ignored-host-list').removeException(selectedItems[x]); 313 $('ignored-host-list').removeException(selectedItems[x]);
269 } 314 }
270 }, 315 },
271 316
272 /** 317 /**
273 * Update details page controls. 318 * Update details page controls.
274 * @private 319 * @private
275 */ 320 */
276 updateControls: function() { 321 updateControls: function() {
322 // Record time of the update to throttle future updates.
323 var now = new Date();
324 lastContentsUpdate_ = now.getTime();
325
277 // Only show ipconfig section if network is connected OR if nothing on 326 // Only show ipconfig section if network is connected OR if nothing on
278 // this device is connected. This is so that you can fix the ip configs 327 // this device is connected. This is so that you can fix the ip configs
279 // if you can't connect to any network. 328 // if you can't connect to any network.
280 // TODO(chocobo): Once ipconfig is moved to flimflam service objects, 329 // TODO(chocobo): Once ipconfig is moved to flimflam service objects,
281 // we need to redo this logic to allow configuration of all networks. 330 // we need to redo this logic to allow configuration of all networks.
282 $('ipconfig-section').hidden = !this.connected && this.deviceConnected; 331 $('ipconfig-section').hidden = !this.connected && this.deviceConnected;
283 332
284 // Network type related. 333 // Network type related.
285 updateHidden('#details-internet-page .cellular-details', !this.cellular); 334 updateHidden('#details-internet-page .cellular-details', !this.cellular);
286 updateHidden('#details-internet-page .wifi-details', !this.wireless); 335 updateHidden('#details-internet-page .wifi-details', !this.wireless);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 897
849 // Don't show page name in address bar and in history to prevent people 898 // Don't show page name in address bar and in history to prevent people
850 // navigate here by hand and solve issue with page session restore. 899 // navigate here by hand and solve issue with page session restore.
851 OptionsPage.showPageByName('detailsInternetPage', false); 900 OptionsPage.showPageByName('detailsInternetPage', false);
852 }; 901 };
853 902
854 return { 903 return {
855 DetailsInternetPage: DetailsInternetPage 904 DetailsInternetPage: DetailsInternetPage
856 }; 905 };
857 }); 906 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698