Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / remoting / webapp / crd / js / background.js
blob96f2833d9545d0327eb88738f14d7436660fe77d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /** @suppress {duplicate} */
6 var remoting = remoting || {};
8 (function(){
10 'use strict';
12 var ENABLE_HANGOUT_REMOTE_ASSISTANCE = true;
14 /**
15  * @constructor
16  */
17 var BackgroundPage = function() {
18   /** @private {remoting.AppLauncher} */
19   this.appLauncher_ = null;
20   /** @private {remoting.ActivationHandler} */
21   this.activationHandler_ = null;
22   /** @private {remoting.It2MeService} */
23   this.it2meService_ = null;
24   /** @private {base.Disposables} */
25   this.disposables_ = null;
27   this.preInit_();
28   this.onResumed_();
30   chrome.runtime.onSuspendCanceled.addListener(this.onResumed_.bind(this));
31   chrome.runtime.onSuspend.addListener(this.onSuspended_.bind(this));
34 /**
35  * Initialize members and globals that are valid throughout the entire lifetime
36  * of the background page.
37  *
38  * @private
39  */
40 BackgroundPage.prototype.preInit_ = function() {
41   remoting.settings = new remoting.Settings();
42   if (base.isAppsV2()) {
43     remoting.identity = new remoting.Identity();
44   } else {
45     remoting.oauth2 = new remoting.OAuth2();
46     var oauth2 = /** @type {*} */ (remoting.oauth2);
47     remoting.identity = /** @type {remoting.Identity} */ (oauth2);
48   }
50   if (base.isAppsV2()) {
51     this.appLauncher_ = new remoting.V2AppLauncher();
52     this.activationHandler_ = new remoting.ActivationHandler(
53         base.Ipc.getInstance(), this.appLauncher_);
54   } else {
55     this.appLauncher_ = new remoting.V1AppLauncher();
56   }
59 /** @private */
60 BackgroundPage.prototype.onResumed_ = function() {
61   if (ENABLE_HANGOUT_REMOTE_ASSISTANCE) {
62     this.it2meService_ = new remoting.It2MeService(this.appLauncher_);
63     this.it2meService_.init();
64     this.disposables_ = new base.Disposables(this.it2meService_);
65   }
68 /** @private */
69 BackgroundPage.prototype.onSuspended_ = function() {
70   this.it2meService_ = null;
71   base.dispose(this.disposables_);
72   this.disposables_ = null;
75 window.addEventListener('load', function() {
76   remoting.backgroundPage = new BackgroundPage();
77 }, false);
79 }());