summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-11 22:05:24 +0000
committersimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-11 22:05:24 +0000
commit30942c8f02f4c5737ae99eba5c0619a43174aafd (patch)
treee3afc8e70dd1c9e283184f5ed99a592a99a09b50 /remoting
parent066f4a4b01e9d88caadb9a35420172241fa7e93b (diff)
downloadchromium_src-30942c8f02f4c5737ae99eba5c0619a43174aafd.zip
chromium_src-30942c8f02f4c5737ae99eba5c0619a43174aafd.tar.gz
chromium_src-30942c8f02f4c5737ae99eba5c0619a43174aafd.tar.bz2
The chromoting client sends simple logging to the server.
Review URL: http://codereview.chromium.org/8527011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/remoting.gyp2
-rw-r--r--remoting/webapp/me2mom/choice.html2
-rw-r--r--remoting/webapp/me2mom/client_session.js3
-rw-r--r--remoting/webapp/me2mom/log_to_server.js60
-rw-r--r--remoting/webapp/me2mom/server_log_entry.js283
5 files changed, 349 insertions, 1 deletions
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 7149139c..9f3afa1 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -111,6 +111,7 @@
'webapp/me2mom/host_screen.js',
'webapp/me2mom/host_session.js',
'webapp/me2mom/l10n.js',
+ 'webapp/me2mom/log_to_server.js',
'webapp/me2mom/main.css',
'webapp/me2mom/manifest.json',
'webapp/me2mom/oauth2.js',
@@ -118,6 +119,7 @@
'webapp/me2mom/plugin_settings.js',
'webapp/me2mom/remoting.js',
'webapp/me2mom/scale-to-fit.png',
+ 'webapp/me2mom/server_log_entry.js',
'webapp/me2mom/spinner.gif',
'webapp/me2mom/toolbar.css',
'webapp/me2mom/ui_mode.js',
diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html
index 972d4e9..a46dbae 100644
--- a/remoting/webapp/me2mom/choice.html
+++ b/remoting/webapp/me2mom/choice.html
@@ -21,9 +21,11 @@ found in the LICENSE file.
<script src="host_screen.js"></script>
<script src="host_session.js"></script>
<script src="l10n.js"></script>
+ <script src="log_to_server.js"></script>
<script src="oauth2.js"></script>
<script src="plugin_settings.js"></script>
<script src="remoting.js"></script>
+ <script src="server_log_entry.js"></script>
<script src="ui_mode.js"></script>
<script src="util.js"></script>
<script src="xhr.js"></script>
diff --git a/remoting/webapp/me2mom/client_session.js b/remoting/webapp/me2mom/client_session.js
index a45ad57..9fcd4d9 100644
--- a/remoting/webapp/me2mom/client_session.js
+++ b/remoting/webapp/me2mom/client_session.js
@@ -39,7 +39,7 @@ remoting.ClientSession = function(hostJid, hostPublicKey, accessCode, email,
this.clientJid = '';
this.sessionId = '';
/** @type {remoting.ViewerPlugin} */ this.plugin = null;
-
+ this.logToServer = new remoting.LogToServer();
this.onStateChange = onStateChange;
};
@@ -326,6 +326,7 @@ remoting.ClientSession.prototype.setState_ = function(state) {
if (this.onStateChange) {
this.onStateChange(oldState);
}
+ this.logToServer.logClientSessionStateChange(this.state, this.error);
};
/**
diff --git a/remoting/webapp/me2mom/log_to_server.js b/remoting/webapp/me2mom/log_to_server.js
new file mode 100644
index 0000000..e65260b
--- /dev/null
+++ b/remoting/webapp/me2mom/log_to_server.js
@@ -0,0 +1,60 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * Module for sending log entries to the server.
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/**
+ * @constructor
+ */
+remoting.LogToServer = function() {
+ /** @type Array.<string> */ this.pendingEntries = [];
+};
+
+/**
+ * Logs a client session state change.
+ *
+ * @param {remoting.ClientSession.State} state
+ * @param {remoting.ClientSession.ConnectionError} connectionError
+ */
+remoting.LogToServer.prototype.logClientSessionStateChange =
+ function(state, connectionError) {
+ var entry = remoting.ServerLogEntry.prototype.makeClientSessionStateChange(
+ state, connectionError);
+ entry.addHostFields();
+ entry.addChromeVersionField();
+ entry.addWebappVersionField();
+ this.log(entry);
+};
+
+/**
+ * Sends a log entry to the server.
+ *
+ * @private
+ * @param {remoting.ServerLogEntry} entry
+ */
+remoting.LogToServer.prototype.log = function(entry) {
+ // Store a stanza for the entry
+ this.pendingEntries.push(entry.toStanza());
+ // Stop if there's no connection to the server.
+ if (!remoting.wcs) {
+ return;
+ }
+ // Send all pending entries to the server.
+ var stanza = '<cli:iq to="remoting@bot.talk.google.com" type="set" ' +
+ 'xmlns:cli="jabber:client"><gr:log xmlns:gr="google:remoting">';
+ while (this.pendingEntries.length > 0) {
+ stanza += /** @type string */ this.pendingEntries.shift();
+ }
+ stanza += '</gr:log></cli:iq>';
+ remoting.debug.logIq(true, stanza);
+ remoting.wcs.sendIq(stanza);
+};
diff --git a/remoting/webapp/me2mom/server_log_entry.js b/remoting/webapp/me2mom/server_log_entry.js
new file mode 100644
index 0000000..18c5784
--- /dev/null
+++ b/remoting/webapp/me2mom/server_log_entry.js
@@ -0,0 +1,283 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * A class of server log entries.
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/**
+ * @private
+ * @constructor
+ */
+remoting.ServerLogEntry = function() {
+ /** @type Object.<string, string> */ this.dict = {};
+};
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_EVENT_NAME_ = 'event-name';
+/** @private */
+remoting.ServerLogEntry.prototype.VALUE_EVENT_NAME_SESSION_STATE_ =
+ 'session-state';
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_ROLE_ = 'role';
+/** @private */
+remoting.ServerLogEntry.prototype.VALUE_ROLE_CLIENT_ = 'client';
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_SESSION_STATE_ = 'session-state';
+
+/**
+ * @private
+ * @param {remoting.ClientSession.State} state
+ * @return {string}
+ */
+remoting.ServerLogEntry.prototype.getValueForSessionState = function(state) {
+ switch(state) {
+ case remoting.ClientSession.State.UNKNOWN:
+ return 'unknown';
+ case remoting.ClientSession.State.CREATED:
+ return 'created';
+ case remoting.ClientSession.State.BAD_PLUGIN_VERSION:
+ return 'bad-plugin-version';
+ case remoting.ClientSession.State.UNKNOWN_PLUGIN_ERROR:
+ return 'unknown-plugin-error';
+ case remoting.ClientSession.State.CONNECTING:
+ return 'connecting';
+ case remoting.ClientSession.State.INITIALIZING:
+ return 'initializing';
+ case remoting.ClientSession.State.CONNECTED:
+ return 'connected';
+ case remoting.ClientSession.State.CLOSED:
+ return 'closed';
+ case remoting.ClientSession.State.CONNECTION_FAILED:
+ return 'connection-failed';
+ default:
+ return 'undefined-' + state;
+ }
+};
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_CONNECTION_ERROR_ = 'connection-error';
+
+/**
+ * @private
+ * @param {remoting.ClientSession.ConnectionError} connectionError
+ * @return {string}
+ */
+remoting.ServerLogEntry.prototype.getValueForConnectionError =
+ function(connectionError) {
+ switch(connectionError) {
+ case remoting.ClientSession.ConnectionError.NONE:
+ return 'none';
+ case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE:
+ return 'host-is-offline';
+ case remoting.ClientSession.ConnectionError.SESSION_REJECTED:
+ return 'session-rejected';
+ case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL:
+ return 'incompatible-protocol';
+ case remoting.ClientSession.ConnectionError.NETWORK_FAILURE:
+ return 'network-failure';
+ case remoting.ClientSession.ConnectionError.OTHER:
+ return 'other';
+ default:
+ return 'unknown-' + connectionError;
+ }
+}
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_OS_NAME_ = 'os-name';
+/** @private */
+remoting.ServerLogEntry.prototype.VALUE_OS_NAME_WINDOWS_ = 'Windows';
+/** @private */
+remoting.ServerLogEntry.prototype.VALUE_OS_NAME_LINUX_ = 'Linux';
+/** @private */
+remoting.ServerLogEntry.prototype.VALUE_OS_NAME_MAC_ = 'Mac';
+/** @private */
+remoting.ServerLogEntry.prototype.VALUE_OS_NAME_CHROMEOS_ = 'ChromeOS';
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_OS_VERSION_ = 'os-version';
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_CPU_ = 'cpu';
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_BROWSER_VERSION_ = 'browser-version';
+
+/** @private */
+remoting.ServerLogEntry.prototype.KEY_WEBAPP_VERSION_ = 'webapp-version';
+
+/**
+ * Sets one field in this log entry.
+ *
+ * @private
+ * @param {string} key
+ * @param {string} value
+ */
+remoting.ServerLogEntry.prototype.set = function(key, value) {
+ this.dict[key] = value;
+};
+
+/**
+ * Converts this object into an XML stanza.
+ *
+ * @return {string}
+ */
+remoting.ServerLogEntry.prototype.toStanza = function() {
+ var stanza = '<gr:entry ';
+ for (var key in this.dict) {
+ stanza += escape(key) + '="' + escape(this.dict[key]) + '" ';
+ }
+ stanza += '/>';
+ return stanza;
+};
+
+/**
+ * Makes a log entry for a change of client session state.
+ *
+ * @param {remoting.ClientSession.State} state
+ * @param {remoting.ClientSession.ConnectionError} connectionError
+ * @return {remoting.ServerLogEntry}
+ */
+remoting.ServerLogEntry.prototype.makeClientSessionStateChange =
+ function(state, connectionError) {
+ var entry = new remoting.ServerLogEntry();
+ entry.set(this.KEY_ROLE_, this.VALUE_ROLE_CLIENT_);
+ entry.set(this.KEY_EVENT_NAME_, this.VALUE_EVENT_NAME_SESSION_STATE_);
+ entry.set(this.KEY_SESSION_STATE_, this.getValueForSessionState(state));
+ if (connectionError != remoting.ClientSession.ConnectionError.NONE) {
+ entry.set(this.KEY_CONNECTION_ERROR_,
+ this.getValueForConnectionError(connectionError));
+ }
+ return entry;
+};
+
+/**
+ * Adds fields describing the host to this log entry.
+ */
+remoting.ServerLogEntry.prototype.addHostFields = function() {
+ var host = this.getHostData();
+ if (host) {
+ if (host.os_name.length > 0) {
+ this.set(this.KEY_OS_NAME_, host.os_name);
+ }
+ if (host.os_version.length > 0) {
+ this.set(this.KEY_OS_VERSION_, host.os_version);
+ }
+ if (host.cpu.length > 0) {
+ this.set(this.KEY_CPU_, host.cpu);
+ }
+ }
+};
+
+/**
+ * Extracts host data from the userAgent string.
+ *
+ * @private
+ * @return {{os_name:string, os_version:string, cpu:string} | null}
+ */
+remoting.ServerLogEntry.prototype.getHostData = function() {
+ return this.extractHostDataFrom(navigator.userAgent);
+};
+
+/**
+ * Extracts host data from the given userAgent string.
+ *
+ * @private
+ * @param {string} s
+ * @return {{os_name:string, os_version:string, cpu:string} | null}
+ */
+remoting.ServerLogEntry.prototype.extractHostDataFrom = function(s) {
+ // Sample userAgent strings:
+ // 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 ' +
+ // '(KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2'
+ // 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.8 ' +
+ // '(KHTML, like Gecko) Chrome/17.0.933.0 Safari/535.8'
+ // 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 ' +
+ // '(KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1'
+ // 'Mozilla/5.0 (X11; CrOS i686 14.811.154) AppleWebKit/535.1 ' +
+ // '(KHTML, like Gecko) Chrome/14.0.835.204 Safari/535.1'
+ var match = new RegExp('Windows NT ([0-9\\.]*)').exec(s);
+ if (match && (match.length >= 2)) {
+ return {
+ 'os_name': this.VALUE_OS_NAME_WINDOWS_,
+ 'os_version': match[1],
+ 'cpu': ''
+ };
+ }
+ match = new RegExp('Linux ([a-zA-Z0-9_]*)').exec(s);
+ if (match && (match.length >= 2)) {
+ return {
+ 'os_name': this.VALUE_OS_NAME_LINUX_,
+ 'os_version' : '',
+ 'cpu': match[1]
+ };
+ }
+ match = new RegExp('([a-zA-Z]*) Mac OS X ([0-9_]*)').exec(s);
+ if (match && (match.length >= 3)) {
+ return {
+ 'os_name': this.VALUE_OS_NAME_MAC_,
+ 'os_version': match[2].replace(/_/g, '.'),
+ 'cpu': match[1]
+ };
+ }
+ match = new RegExp('CrOS ([a-zA-Z0-9]*) ([0-9.]*)').exec(s);
+ if (match && (match.length >= 3)) {
+ return {
+ 'os_name': this.VALUE_OS_NAME_CHROMEOS_,
+ 'os_version': match[2],
+ 'cpu': match[1]
+ };
+ }
+ return null;
+};
+
+/**
+ * Adds a field specifying the browser version to this log entry.
+ */
+remoting.ServerLogEntry.prototype.addChromeVersionField = function() {
+ var version = this.getChromeVersion();
+ if (version != null) {
+ this.set(this.KEY_BROWSER_VERSION_, version);
+ }
+};
+
+/**
+ * Extracts the Chrome version from the userAgent string.
+ *
+ * @private
+ * @return {string | null}
+ */
+remoting.ServerLogEntry.prototype.getChromeVersion = function() {
+ return this.extractChromeVersionFrom(navigator.userAgent);
+};
+
+/**
+ * Extracts the Chrome version from the given userAgent string.
+ *
+ * @private
+ * @param {string} s
+ * @return {string | null}
+ */
+remoting.ServerLogEntry.prototype.extractChromeVersionFrom = function(s) {
+ var match = new RegExp('Chrome/([0-9.]*)').exec(s);
+ if (match && (match.length >= 2)) {
+ return match[1];
+ }
+ return null;
+};
+
+/**
+ * Adds a field specifying the webapp version to this log entry.
+ */
+remoting.ServerLogEntry.prototype.addWebappVersionField = function() {
+ this.set(this.KEY_WEBAPP_VERSION_, chrome.app.getDetails().version);
+};