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

Unified Diff: remoting/webapp/crd/js/background.js

Issue 896003002: Use the local user's email when connecting to It2MeHelpeeChannel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@HRD_V2Auth
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/crd/js/background.js
diff --git a/remoting/webapp/crd/js/background.js b/remoting/webapp/crd/js/background.js
index fd2e41de623798d6bcdf503e9266d0f72ceb3bc4..78fda0bd0cfc05def6e5de25805f400e1ba73be5 100644
--- a/remoting/webapp/crd/js/background.js
+++ b/remoting/webapp/crd/js/background.js
@@ -9,45 +9,84 @@ var remoting = remoting || {};
'use strict';
+var ENABLE_HANGOUT_REMOTE_ASSISTANCE = true;
+
/**
- * The background service is responsible for listening to incoming connection
- * requests from Hangouts and the webapp.
- *
- * @param {remoting.AppLauncher} appLauncher
+ * @constructor
*/
-function initializeBackgroundService(appLauncher) {
- function initializeIt2MeService() {
- /** @type {remoting.It2MeService} */
- remoting.it2meService = new remoting.It2MeService(appLauncher);
- remoting.it2meService.init();
- }
+var BackgroundPage = function() {
+ /**
+ * @type {remoting.AppLauncher}
dcaiafa 2015/02/04 00:12:35 nit: do you guys know about the short form of this
kelvinp 2015/02/04 00:38:13 Glad to know. I love it. Done.
+ * @private
+ */
+ this.appLauncher_ = null;
+ /**
+ * @type {remoting.ActivationHandler}
+ * @private
+ */
+ this.activationHandler_ = null;
+ /**
+ * @type {remoting.It2MeService}
+ * @private
+ */
+ this.it2meService_ = null;
+ /**
+ * @type {base.Disposables}
+ * @private
+ */
+ this.disposables_ = null;
- chrome.runtime.onSuspend.addListener(function() {
- base.debug.assert(remoting.it2meService != null);
- remoting.it2meService.dispose();
- remoting.it2meService = null;
- });
+ this.preInit_();
+ this.onResumed_();
- remoting.settings = new remoting.Settings();
+ chrome.runtime.onSuspendCanceled.addListener(this.onResumed_.bind(this));
+ chrome.runtime.onSuspend.addListener(this.onSuspended_.bind(this));
+};
- chrome.runtime.onSuspendCanceled.addListener(initializeIt2MeService);
- initializeIt2MeService();
-}
+/**
+ * Initialize members and globals that are valid throughout the entire lifetime
+ * of the background page.
+ *
+ * @private
+ */
+BackgroundPage.prototype.preInit_ = function() {
+ remoting.settings = new remoting.Settings();
+ if (base.isAppsV2()) {
+ remoting.identity = new remoting.Identity();
+ } else {
+ remoting.oauth2 = new remoting.OAuth2();
+ var oauth2 = /** @type {*} */ (remoting.oauth2);
+ remoting.identity = /** @type {remoting.Identity} */ (oauth2);
+ }
-function main() {
if (base.isAppsV2()) {
- new remoting.ActivationHandler(base.Ipc.getInstance(),
- new remoting.V2AppLauncher());
+ this.appLauncher_ = new remoting.V2AppLauncher();
+ this.activationHandler_ = new remoting.ActivationHandler(
+ base.Ipc.getInstance(), this.appLauncher_);
+ } else {
+ this.appLauncher_ = new remoting.V1AppLauncher();
+ this.activationHandler_ = new base.Disposables();
dcaiafa 2015/02/04 00:12:35 Why can't this be just null? It's never disposed o
kelvinp 2015/02/04 00:38:13 It is artifacts from a previous experiment. Remov
}
-}
+};
+
+/** @private */
+BackgroundPage.prototype.onResumed_ = function() {
+ if (ENABLE_HANGOUT_REMOTE_ASSISTANCE) {
+ this.it2meService_ = new remoting.It2MeService(this.appLauncher_);
+ this.it2meService_.init();
+ this.disposables_ = new base.Disposables(this.it2meService_);
+ }
+};
-remoting.enableHangoutsRemoteAssistance = function() {
- /** @type {remoting.AppLauncher} */
- var appLauncher = base.isAppsV2() ? new remoting.V1AppLauncher():
- new remoting.V2AppLauncher();
- initializeBackgroundService(appLauncher);
+/** @private */
+BackgroundPage.prototype.onSuspended_ = function() {
+ this.it2meService_ = null;
+ base.dispose(this.disposables_);
+ this.disposables_ = null;
};
-window.addEventListener('load', main, false);
+window.addEventListener('load', function() {
+ remoting.backgroundPage = new BackgroundPage();
+}, false);
}());

Powered by Google App Engine
This is Rietveld 408576698