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

Unified Diff: remoting/webapp/host_dispatcher.js

Issue 132793007: Download the host components when user tries to enable Me2Me host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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/host_dispatcher.js
diff --git a/remoting/webapp/host_dispatcher.js b/remoting/webapp/host_dispatcher.js
index ee33e41fc2e52ced77f070efaa5b64633e8a0304..5de4d55fb98c96da2b02bc509ac25f7c8732b97c 100644
--- a/remoting/webapp/host_dispatcher.js
+++ b/remoting/webapp/host_dispatcher.js
@@ -28,9 +28,6 @@ var remoting = remoting || {};
* unsupported.
*/
remoting.HostDispatcher = function(createPluginCallback) {
- /** @type {remoting.HostDispatcher} */
- var that = this;
-
/** @type {remoting.HostNativeMessaging} @private */
this.nativeMessagingHost_ = new remoting.HostNativeMessaging();
@@ -43,23 +40,44 @@ remoting.HostDispatcher = function(createPluginCallback) {
/** @type {Array.<function()>} */
this.pendingRequests_ = [];
+ this.createPluginCallback_ = createPluginCallback;
+
+ this.tryToInitialize_();
+}
+
+/** @enum {number} */
+remoting.HostDispatcher.State = {
+ UNKNOWN: 0,
+ NATIVE_MESSAGING: 1,
+ NPAPI: 2,
+ NOT_INSTALLED: 3
+};
+
+remoting.HostDispatcher.prototype.tryToInitialize_ = function() {
+ /** @type {remoting.HostDispatcher} */
+ var that = this;
+
+ if (this.state_ != remoting.HostDispatcher.State.UNKNOWN)
+ return;
+
function sendPendingRequests() {
- for (var i = 0; i < that.pendingRequests_.length; i++) {
- that.pendingRequests_[i]();
+ var pendingRequests = that.pendingRequests_;
+ that.pendingRequests_ = [];
+ for (var i = 0; i < pendingRequests.length; i++) {
+ pendingRequests[i]();
}
- that.pendingRequests_ = null;
}
function onNativeMessagingInit() {
- console.log('Native Messaging supported.');
that.state_ = remoting.HostDispatcher.State.NATIVE_MESSAGING;
sendPendingRequests();
}
function onNativeMessagingFailed(error) {
- console.log('Native Messaging unsupported, falling back to NPAPI.');
- that.npapiHost_ = createPluginCallback();
- that.state_ = remoting.HostDispatcher.State.NPAPI;
+ that.npapiHost_ = that.createPluginCallback_();
+
+ that.state_ = that.npapiHost_ ? remoting.HostDispatcher.State.NPAPI
+ : remoting.HostDispatcher.State.NOT_INSTALLED;
sendPendingRequests();
}
@@ -67,13 +85,6 @@ remoting.HostDispatcher = function(createPluginCallback) {
onNativeMessagingFailed);
};
-/** @enum {number} */
-remoting.HostDispatcher.State = {
- UNKNOWN: 0,
- NATIVE_MESSAGING: 1,
- NPAPI: 2
-};
-
/**
* @param {remoting.HostController.Feature} feature The feature to test for.
* @param {function(boolean):void} onDone
@@ -98,6 +109,9 @@ remoting.HostDispatcher.prototype.hasFeature = function(
}
onDone(supportedFeatures.indexOf(feature) >= 0);
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onDone(false);
+ break;
}
};
@@ -122,6 +136,9 @@ remoting.HostDispatcher.prototype.getHostName = function(onDone, onError) {
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onError(remoting.Error.MISSING_PLUGIN);
+ break;
}
};
@@ -149,6 +166,9 @@ remoting.HostDispatcher.prototype.getPinHash =
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onError(remoting.Error.MISSING_PLUGIN);
+ break;
}
};
@@ -173,6 +193,9 @@ remoting.HostDispatcher.prototype.generateKeyPair = function(onDone, onError) {
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onError(remoting.Error.MISSING_PLUGIN);
+ break;
}
};
@@ -199,6 +222,9 @@ remoting.HostDispatcher.prototype.updateDaemonConfig =
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onError(remoting.Error.MISSING_PLUGIN);
+ break;
}
};
@@ -238,6 +264,9 @@ remoting.HostDispatcher.prototype.getDaemonConfig = function(onDone, onError) {
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onDone({});
Jamie 2014/01/31 18:39:15 Why is this not onError like the other cases? Mayb
Sergey Ulanov 2014/01/31 23:34:17 For most other things we can'd do anything without
+ break;
}
};
@@ -262,6 +291,9 @@ remoting.HostDispatcher.prototype.getDaemonVersion = function(onDone, onError) {
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onError(remoting.Error.MISSING_PLUGIN);
+ break;
}
};
@@ -287,6 +319,9 @@ remoting.HostDispatcher.prototype.getUsageStatsConsent =
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onError(remoting.Error.MISSING_PLUGIN);
+ break;
}
};
@@ -314,6 +349,9 @@ remoting.HostDispatcher.prototype.startDaemon =
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onError(remoting.Error.MISSING_PLUGIN);
+ break;
}
};
@@ -337,6 +375,9 @@ remoting.HostDispatcher.prototype.stopDaemon = function(onDone, onError) {
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onError(remoting.Error.MISSING_PLUGIN);
+ break;
}
};
@@ -346,10 +387,27 @@ remoting.HostDispatcher.prototype.stopDaemon = function(onDone, onError) {
* @return {void}
*/
remoting.HostDispatcher.prototype.getDaemonState = function(onDone, onError) {
+ // If the host was in not-initialized state try initializing it again in case
+ // it was installed.
+ if (this.state_ == remoting.HostDispatcher.State.NOT_INSTALLED) {
+ this.state_ = remoting.HostDispatcher.State.UNKNOWN;
+ this.tryToInitialize_();
+ }
+
+ this.getDaemonStateInternal_(onDone, onError);
+}
+
+/**
+ * @param {function(remoting.HostController.State):void} onDone
+ * @param {function(remoting.Error):void} onError
+ * @return {void}
+ */
+remoting.HostDispatcher.prototype.getDaemonStateInternal_ =
+ function(onDone, onError) {
switch (this.state_) {
case remoting.HostDispatcher.State.UNKNOWN:
this.pendingRequests_.push(
- this.getDaemonState.bind(this, onDone, onError));
+ this.getDaemonStateInternal_.bind(this, onDone, onError));
break;
case remoting.HostDispatcher.State.NATIVE_MESSAGING:
this.nativeMessagingHost_.getDaemonState(onDone, onError);
@@ -364,6 +422,9 @@ remoting.HostDispatcher.prototype.getDaemonState = function(onDone, onError) {
onDone(state);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onDone(remoting.HostController.State.NOT_INSTALLED);
+ break;
}
};
@@ -404,6 +465,9 @@ remoting.HostDispatcher.prototype.getPairedClients = function(onDone, onError) {
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onDone(remoting.HostController.State.NOT_INSTALLED);
Jamie 2014/01/31 18:39:15 This is the wrong type for onDone. I think you mea
Sergey Ulanov 2014/01/31 23:34:17 Done
+ break;
}
};
@@ -449,6 +513,9 @@ remoting.HostDispatcher.prototype.clearPairedClients =
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onDone(remoting.HostController.State.NOT_INSTALLED);
Jamie 2014/01/31 18:39:15 onDone take no parameters; perhaps you need to cal
Sergey Ulanov 2014/01/31 23:34:17 Yes.
+ break;
}
};
@@ -477,6 +544,9 @@ remoting.HostDispatcher.prototype.deletePairedClient =
onError(remoting.Error.MISSING_PLUGIN);
}
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onDone(remoting.HostController.State.NOT_INSTALLED);
Jamie 2014/01/31 18:39:15 onError?
Sergey Ulanov 2014/01/31 23:34:17 Done.
+ break;
}
};
@@ -500,6 +570,9 @@ remoting.HostDispatcher.prototype.getHostClientId =
// doesn't have access to the API keys baked into the installed host.
onError(remoting.Error.UNEXPECTED);
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onDone(remoting.HostController.State.NOT_INSTALLED);
Jamie 2014/01/31 18:39:15 onError?
Sergey Ulanov 2014/01/31 23:34:17 Done.
+ break;
}
};
@@ -526,5 +599,8 @@ remoting.HostDispatcher.prototype.getCredentialsFromAuthCode =
// doesn't have access to the API keys baked into the installed host.
onError(remoting.Error.UNEXPECTED);
break;
+ case remoting.HostDispatcher.State.NOT_INSTALLED:
+ onDone(remoting.HostController.State.NOT_INSTALLED);
Jamie 2014/01/31 18:39:15 onError?
Sergey Ulanov 2014/01/31 23:34:17 Done.
+ break;
}
};

Powered by Google App Engine
This is Rietveld 408576698