diff options
author | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 23:06:16 +0000 |
---|---|---|
committer | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 23:06:16 +0000 |
commit | c2fee120cfe28a982b11f53514a32191cee8da63 (patch) | |
tree | 180f92aba22f12b58f9aedc7bdc5ab91e05e7ee0 /remoting | |
parent | f252b9a0324a58e80b27df4a9a4854af749fb543 (diff) | |
download | chromium_src-c2fee120cfe28a982b11f53514a32191cee8da63.zip chromium_src-c2fee120cfe28a982b11f53514a32191cee8da63.tar.gz chromium_src-c2fee120cfe28a982b11f53514a32191cee8da63.tar.bz2 |
The webapp uses localStorage to decide whether logging to the server
is enabled, and for a pseudonymous ID to attach to logged events.
BUG=106208
Review URL: http://codereview.chromium.org/8775066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112811 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/webapp/me2mom/debug_log.js | 8 | ||||
-rw-r--r-- | remoting/webapp/me2mom/log_to_server.js | 74 | ||||
-rw-r--r-- | remoting/webapp/me2mom/server_log_entry.js | 12 |
3 files changed, 90 insertions, 4 deletions
diff --git a/remoting/webapp/me2mom/debug_log.js b/remoting/webapp/me2mom/debug_log.js index 7aee65f..3e0fd47 100644 --- a/remoting/webapp/me2mom/debug_log.js +++ b/remoting/webapp/me2mom/debug_log.js @@ -664,7 +664,7 @@ remoting.DebugLog.prototype.prettyIqSet = function(action, iq_list) { /** @type {Node} */ var entry = log.childNodes[0]; if (!this.verifyAttributes(entry, 'role,event-name,session-state,cpu,' + - 'os-name,browser-version,webapp-version')) { + 'os-name,browser-version,webapp-version,id')) { return false; } var role = entry.getAttribute('role'); @@ -676,7 +676,7 @@ remoting.DebugLog.prototype.prettyIqSet = function(action, iq_list) { return false; } var session_state = entry.getAttribute('session-state'); - this.prettyIqHeading(action, '?', 'set session-state ' + session_state, + this.prettyIqHeading(action, '?', 'log session-state ' + session_state, null); var os_name = entry.getAttribute('os-name'); @@ -685,6 +685,10 @@ remoting.DebugLog.prototype.prettyIqSet = function(action, iq_list) { var webapp_version = entry.getAttribute('webapp-version'); this.logIndent(1, os_name + ' ' + cpu + ' Chromium_v' + browser_version + ' Chromoting_v' + webapp_version); + var remoting_id = entry.getAttribute('id'); + if (remoting_id) { + this.logIndent(1, 'id: ' + remoting_id); + } return true; } } diff --git a/remoting/webapp/me2mom/log_to_server.js b/remoting/webapp/me2mom/log_to_server.js index d42bb70..017bc1a 100644 --- a/remoting/webapp/me2mom/log_to_server.js +++ b/remoting/webapp/me2mom/log_to_server.js @@ -17,9 +17,30 @@ var remoting = remoting || {}; */ remoting.LogToServer = function() { /** @type Array.<string> */ this.pendingEntries = []; - /** @type boolean */ this.enabled = false; }; +// Local storage keys. +/** @private */ +remoting.LogToServer.prototype.KEY_ENABLED_ = 'remoting.LogToServer.enabled'; +/** @private */ +remoting.LogToServer.prototype.KEY_ID_ = 'remoting.LogToServer.id'; + +// Constants used for generating an ID. +/** @private */ +remoting.LogToServer.prototype.ID_ALPHABET_ = + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; +/** @private */ +remoting.LogToServer.prototype.ID_LEN_ = 20; + +/** + * Enables or disables logging. + * + * @param {boolean} enabled whether logging is enabled + */ +remoting.LogToServer.prototype.setEnabled = function(enabled) { + window.localStorage.setItem(this.KEY_ENABLED_, enabled ? 'true' : 'false'); +} + /** * Logs a client session state change. * @@ -33,6 +54,7 @@ remoting.LogToServer.prototype.logClientSessionStateChange = entry.addHostFields(); entry.addChromeVersionField(); entry.addWebappVersionField(); + entry.addIdField(this.getId()); this.log(entry); }; @@ -43,7 +65,7 @@ remoting.LogToServer.prototype.logClientSessionStateChange = * @param {remoting.ServerLogEntry} entry */ remoting.LogToServer.prototype.log = function(entry) { - if (!this.enabled) { + if (!this.isEnabled()) { return; } // Store a stanza for the entry @@ -62,3 +84,51 @@ remoting.LogToServer.prototype.log = function(entry) { remoting.debug.logIq(true, stanza); remoting.wcs.sendIq(stanza); }; + +/** + * Whether logging is enabled. + * + * @private + * @return {boolean} whether logging is enabled + */ +remoting.LogToServer.prototype.isEnabled = function() { + var value = window.localStorage.getItem(this.KEY_ENABLED_); + return (value == 'true'); +}; + +/** + * Gets an ID from local storage. + * + * This function returns the empty string if logging is disabled. + * If logging is enabled, and there is no ID in local storage, then this + * function will create and store an ID. + * + * @private + * @return {string} an ID, or the empty string + */ +remoting.LogToServer.prototype.getId = function() { + if (!this.isEnabled()) { + return ''; + } + var id = window.localStorage.getItem(this.KEY_ID_); + if ((!id) || (typeof id != 'string')) { + id = this.generateId(); + window.localStorage.setItem(this.KEY_ID_, id); + } + return id.toString(); +}; + +/** + * Generates an ID. + * + * @private + * @return {string} an ID + */ +remoting.LogToServer.prototype.generateId = function() { + var idArray = []; + for (var i = 0; i < this.ID_LEN_; i++) { + var index = Math.random() * this.ID_ALPHABET_.length; + idArray.push(this.ID_ALPHABET_.slice(index, index + 1)); + } + return idArray.join(''); +}; diff --git a/remoting/webapp/me2mom/server_log_entry.js b/remoting/webapp/me2mom/server_log_entry.js index 0b1f23f..892a91a 100644 --- a/remoting/webapp/me2mom/server_log_entry.js +++ b/remoting/webapp/me2mom/server_log_entry.js @@ -27,6 +27,9 @@ remoting.ServerLogEntry.prototype.VALUE_EVENT_NAME_SESSION_STATE_ = 'session-state'; /** @private */ +remoting.ServerLogEntry.prototype.KEY_ID_ = 'id'; + +/** @private */ remoting.ServerLogEntry.prototype.KEY_ROLE_ = 'role'; /** @private */ remoting.ServerLogEntry.prototype.VALUE_ROLE_CLIENT_ = 'client'; @@ -159,6 +162,15 @@ remoting.ServerLogEntry.prototype.makeClientSessionStateChange = }; /** + * Adds an ID field to this log entry. + * + * @param {string} id + */ +remoting.ServerLogEntry.prototype.addIdField = function(id) { + this.set(this.KEY_ID_, id); +} + +/** * Adds fields describing the host to this log entry. */ remoting.ServerLogEntry.prototype.addHostFields = function() { |