OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * This class provides a "bridge" for communicating between the javascript and | 6 * This class provides a "bridge" for communicating between the javascript and |
7 * the browser. | 7 * the browser. |
8 */ | 8 */ |
| 9 var BrowserBridge = (function() { |
| 10 'use strict'; |
9 | 11 |
10 var BrowserBridge = (function() { | |
11 /** | 12 /** |
12 * Delay in milliseconds between updates of certain browser information. | 13 * Delay in milliseconds between updates of certain browser information. |
13 */ | 14 */ |
14 const POLL_INTERVAL_MS = 5000; | 15 var POLL_INTERVAL_MS = 5000; |
15 | 16 |
16 /** | 17 /** |
17 * @constructor | 18 * @constructor |
18 */ | 19 */ |
19 function BrowserBridge() { | 20 function BrowserBridge() { |
| 21 assertFirstConstructorCall(BrowserBridge); |
| 22 |
20 // List of observers for various bits of browser state. | 23 // List of observers for various bits of browser state. |
21 this.connectionTestsObservers_ = []; | 24 this.connectionTestsObservers_ = []; |
22 this.hstsObservers_ = []; | 25 this.hstsObservers_ = []; |
23 this.httpThrottlingObservers_ = []; | 26 this.httpThrottlingObservers_ = []; |
24 this.constantsObservers_ = []; | 27 this.constantsObservers_ = []; |
25 | 28 |
26 this.pollableDataHelpers_ = {}; | 29 this.pollableDataHelpers_ = {}; |
27 this.pollableDataHelpers_.proxySettings = | 30 this.pollableDataHelpers_.proxySettings = |
28 new PollableDataHelper('onProxySettingsChanged', | 31 new PollableDataHelper('onProxySettingsChanged', |
29 this.sendGetProxySettings.bind(this)); | 32 this.sendGetProxySettings.bind(this)); |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 */ | 477 */ |
475 addPrerenderInfoObserver: function(observer) { | 478 addPrerenderInfoObserver: function(observer) { |
476 this.pollableDataHelpers_.prerenderInfo.addObserver(observer); | 479 this.pollableDataHelpers_.prerenderInfo.addObserver(observer); |
477 }, | 480 }, |
478 | 481 |
479 /** | 482 /** |
480 * If |force| is true, calls all startUpdate functions. Otherwise, just | 483 * If |force| is true, calls all startUpdate functions. Otherwise, just |
481 * runs updates with active observers. | 484 * runs updates with active observers. |
482 */ | 485 */ |
483 checkForUpdatedInfo: function(force) { | 486 checkForUpdatedInfo: function(force) { |
484 for (name in this.pollableDataHelpers_) { | 487 for (var name in this.pollableDataHelpers_) { |
485 var helper = this.pollableDataHelpers_[name]; | 488 var helper = this.pollableDataHelpers_[name]; |
486 if (force || helper.hasActiveObserver()) | 489 if (force || helper.hasActiveObserver()) |
487 helper.startUpdate(); | 490 helper.startUpdate(); |
488 } | 491 } |
489 }, | 492 }, |
490 | 493 |
491 /** | 494 /** |
492 * Calls all startUpdate functions and, if |callback| is non-null, | 495 * Calls all startUpdate functions and, if |callback| is non-null, |
493 * calls it with the results of all updates. | 496 * calls it with the results of all updates. |
494 */ | 497 */ |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 * It works by keeping track of how many polling functions have | 601 * It works by keeping track of how many polling functions have |
599 * yet to receive data, and recording the data as it it received. | 602 * yet to receive data, and recording the data as it it received. |
600 * | 603 * |
601 * @constructor | 604 * @constructor |
602 */ | 605 */ |
603 function UpdateAllObserver(callback, pollableDataHelpers) { | 606 function UpdateAllObserver(callback, pollableDataHelpers) { |
604 this.callback_ = callback; | 607 this.callback_ = callback; |
605 this.observingCount_ = 0; | 608 this.observingCount_ = 0; |
606 this.updatedData_ = {}; | 609 this.updatedData_ = {}; |
607 | 610 |
608 for (name in pollableDataHelpers) { | 611 for (var name in pollableDataHelpers) { |
609 ++this.observingCount_; | 612 ++this.observingCount_; |
610 var helper = pollableDataHelpers[name]; | 613 var helper = pollableDataHelpers[name]; |
611 helper.addObserver(this); | 614 helper.addObserver(this); |
612 this[helper.getObserverMethodName()] = | 615 this[helper.getObserverMethodName()] = |
613 this.onDataReceived_.bind(this, helper, name); | 616 this.onDataReceived_.bind(this, helper, name); |
614 } | 617 } |
615 } | 618 } |
616 | 619 |
617 UpdateAllObserver.prototype = { | 620 UpdateAllObserver.prototype = { |
618 isActive: function() { | 621 isActive: function() { |
619 return true; | 622 return true; |
620 }, | 623 }, |
621 | 624 |
622 onDataReceived_: function(helper, name, data) { | 625 onDataReceived_: function(helper, name, data) { |
623 helper.removeObserver(this); | 626 helper.removeObserver(this); |
624 --this.observingCount_; | 627 --this.observingCount_; |
625 this.updatedData_[name] = data; | 628 this.updatedData_[name] = data; |
626 if (this.observingCount_ == 0) | 629 if (this.observingCount_ == 0) |
627 this.callback_(this.updatedData_); | 630 this.callback_(this.updatedData_); |
628 } | 631 } |
629 }; | 632 }; |
630 | 633 |
631 return BrowserBridge; | 634 return BrowserBridge; |
632 })(); | 635 })(); |
OLD | NEW |