The chromoting client logs a session ID to the server,

instead of a per-install ID.

BUG=106208
TEST=none

Review URL: http://codereview.chromium.org/8893015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114127 0039d316-1c4b-4281-b951-d872f2087c98
parent 4ca0c4e4
...@@ -20,20 +20,29 @@ remoting.LogToServer = function() { ...@@ -20,20 +20,29 @@ remoting.LogToServer = function() {
this.pendingEntries = []; this.pendingEntries = [];
/** @type {remoting.StatsAccumulator} */ /** @type {remoting.StatsAccumulator} */
this.statsAccumulator = new remoting.StatsAccumulator(); this.statsAccumulator = new remoting.StatsAccumulator();
/** @type string */
this.sessionId = '';
/** @type number */
this.sessionIdGenerationTime = 0;
}; };
// Local storage keys. // Local storage key.
/** @private */ /** @private */
remoting.LogToServer.prototype.KEY_ENABLED_ = 'remoting.LogToServer.enabled'; remoting.LogToServer.KEY_ENABLED_ = 'remoting.LogToServer.enabled';
/** @private */
remoting.LogToServer.prototype.KEY_ID_ = 'remoting.LogToServer.id';
// Constants used for generating an ID. // Constants used for generating a session ID.
/** @private */ /** @private */
remoting.LogToServer.prototype.ID_ALPHABET_ = remoting.LogToServer.SESSION_ID_ALPHABET_ =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
/** @private */ /** @private */
remoting.LogToServer.prototype.ID_LEN_ = 20; remoting.LogToServer.SESSION_ID_LEN_ = 20;
// The maximum age of a session ID, in milliseconds.
remoting.LogToServer.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000;
// The time over which to accumulate connection statistics before logging them
// to the server, in milliseconds.
remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000;
/** /**
* Enables or disables logging. * Enables or disables logging.
...@@ -41,7 +50,8 @@ remoting.LogToServer.prototype.ID_LEN_ = 20; ...@@ -41,7 +50,8 @@ remoting.LogToServer.prototype.ID_LEN_ = 20;
* @param {boolean} enabled whether logging is enabled * @param {boolean} enabled whether logging is enabled
*/ */
remoting.LogToServer.prototype.setEnabled = function(enabled) { remoting.LogToServer.prototype.setEnabled = function(enabled) {
window.localStorage.setItem(this.KEY_ENABLED_, enabled ? 'true' : 'false'); window.localStorage.setItem(remoting.LogToServer.KEY_ENABLED_,
enabled ? 'true' : 'false');
} }
/** /**
...@@ -52,16 +62,31 @@ remoting.LogToServer.prototype.setEnabled = function(enabled) { ...@@ -52,16 +62,31 @@ remoting.LogToServer.prototype.setEnabled = function(enabled) {
*/ */
remoting.LogToServer.prototype.logClientSessionStateChange = remoting.LogToServer.prototype.logClientSessionStateChange =
function(state, connectionError) { function(state, connectionError) {
this.maybeExpireSessionId();
// Maybe set the session ID.
if ((state == remoting.ClientSession.State.CONNECTING) ||
(state == remoting.ClientSession.State.INITIALIZING) ||
(state == remoting.ClientSession.State.CONNECTED)) {
if (this.sessionId == '') {
this.setSessionId();
}
}
// Log the session state change.
var entry = remoting.ServerLogEntry.makeClientSessionStateChange( var entry = remoting.ServerLogEntry.makeClientSessionStateChange(
state, connectionError); state, connectionError);
entry.addHostFields(); entry.addHostFields();
entry.addChromeVersionField(); entry.addChromeVersionField();
entry.addWebappVersionField(); entry.addWebappVersionField();
entry.addIdField(this.getId()); entry.addSessionIdField(this.sessionId);
this.log(entry); this.log(entry);
// Don't accumulate connection statistics across state changes. // Don't accumulate connection statistics across state changes.
this.logAccumulatedStatistics(); this.logAccumulatedStatistics();
this.statsAccumulator.empty(); this.statsAccumulator.empty();
// Maybe clear the session ID.
if ((state == remoting.ClientSession.State.CLOSED) ||
(state == remoting.ClientSession.State.CONNECTION_FAILED)) {
this.clearSessionId();
}
}; };
/** /**
...@@ -69,11 +94,13 @@ remoting.LogToServer.prototype.logClientSessionStateChange = ...@@ -69,11 +94,13 @@ remoting.LogToServer.prototype.logClientSessionStateChange =
* @param {Object.<string, number>} stats the connection statistics * @param {Object.<string, number>} stats the connection statistics
*/ */
remoting.LogToServer.prototype.logStatistics = function(stats) { remoting.LogToServer.prototype.logStatistics = function(stats) {
this.maybeExpireSessionId();
// Store the statistics. // Store the statistics.
this.statsAccumulator.add(stats); this.statsAccumulator.add(stats);
// Send statistics to the server if they've been accumulating for at least // Send statistics to the server if they've been accumulating for at least
// 60 seconds. // 60 seconds.
if (this.statsAccumulator.getTimeSinceFirstValue() >= 60 * 1000) { if (this.statsAccumulator.getTimeSinceFirstValue() >=
remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME) {
this.logAccumulatedStatistics(); this.logAccumulatedStatistics();
} }
}; };
...@@ -92,7 +119,7 @@ remoting.LogToServer.prototype.logAccumulatedStatistics = function() { ...@@ -92,7 +119,7 @@ remoting.LogToServer.prototype.logAccumulatedStatistics = function() {
entry.addHostFields(); entry.addHostFields();
entry.addChromeVersionField(); entry.addChromeVersionField();
entry.addWebappVersionField(); entry.addWebappVersionField();
entry.addIdField(this.getId()); entry.addSessionIdField(this.sessionId);
this.log(entry); this.log(entry);
} }
this.statsAccumulator.empty(); this.statsAccumulator.empty();
...@@ -137,43 +164,66 @@ remoting.LogToServer.prototype.log = function(entry) { ...@@ -137,43 +164,66 @@ remoting.LogToServer.prototype.log = function(entry) {
* @return {boolean} whether logging is enabled * @return {boolean} whether logging is enabled
*/ */
remoting.LogToServer.prototype.isEnabled = function() { remoting.LogToServer.prototype.isEnabled = function() {
var value = window.localStorage.getItem(this.KEY_ENABLED_); var value = window.localStorage.getItem(remoting.LogToServer.KEY_ENABLED_);
return (value == 'true'); return (value == 'true');
}; };
/** /**
* Gets an ID from local storage. * Sets the session ID to a random string.
* *
* This function returns the empty string if logging is disabled. * @private
* If logging is enabled, and there is no ID in local storage, then this */
* function will create and store an ID. remoting.LogToServer.prototype.setSessionId = function() {
this.sessionId = remoting.LogToServer.generateSessionId();
this.sessionIdGenerationTime = new Date().getTime();
};
/**
* Clears the session ID.
* *
* @private * @private
* @return {string} an ID, or the empty string
*/ */
remoting.LogToServer.prototype.getId = function() { remoting.LogToServer.prototype.clearSessionId = function() {
if (!this.isEnabled()) { this.sessionId = '';
return ''; this.sessionIdGenerationTime = 0;
} };
var id = window.localStorage.getItem(this.KEY_ID_);
if ((!id) || (typeof id != 'string')) { /**
id = this.generateId(); * Sets a new session ID, if the current session ID has reached its maximum age.
window.localStorage.setItem(this.KEY_ID_, id); *
* This method also logs the old and new session IDs to the server, in separate
* log entries.
*
* @private
*/
remoting.LogToServer.prototype.maybeExpireSessionId = function() {
if ((this.sessionId != '') &&
(new Date().getTime() - this.sessionIdGenerationTime >=
remoting.LogToServer.MAX_SESSION_ID_AGE)) {
// Log the old session ID.
var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId);
this.log(entry);
// Generate a new session ID.
this.setSessionId();
// Log the new session ID.
entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId);
this.log(entry);
} }
return id.toString();
}; };
/** /**
* Generates an ID. * Generates a string that can be used as a session ID.
* *
* @private * @private
* @return {string} an ID * @return {string} a session ID
*/ */
remoting.LogToServer.prototype.generateId = function() { remoting.LogToServer.generateSessionId = function() {
var idArray = []; var idArray = [];
for (var i = 0; i < this.ID_LEN_; i++) { for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) {
var index = Math.random() * this.ID_ALPHABET_.length; var index =
idArray.push(this.ID_ALPHABET_.slice(index, index + 1)); Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length;
idArray.push(
remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1));
} }
return idArray.join(''); return idArray.join('');
}; };
...@@ -27,7 +27,7 @@ remoting.ServerLogEntry.VALUE_EVENT_NAME_SESSION_STATE_ = ...@@ -27,7 +27,7 @@ remoting.ServerLogEntry.VALUE_EVENT_NAME_SESSION_STATE_ =
'session-state'; 'session-state';
/** @private */ /** @private */
remoting.ServerLogEntry.KEY_ID_ = 'id'; remoting.ServerLogEntry.KEY_SESSION_ID_ = 'session-id';
/** @private */ /** @private */
remoting.ServerLogEntry.KEY_ROLE_ = 'role'; remoting.ServerLogEntry.KEY_ROLE_ = 'role';
...@@ -132,6 +132,12 @@ remoting.ServerLogEntry.KEY_BROWSER_VERSION_ = 'browser-version'; ...@@ -132,6 +132,12 @@ remoting.ServerLogEntry.KEY_BROWSER_VERSION_ = 'browser-version';
/** @private */ /** @private */
remoting.ServerLogEntry.KEY_WEBAPP_VERSION_ = 'webapp-version'; remoting.ServerLogEntry.KEY_WEBAPP_VERSION_ = 'webapp-version';
/** @private */
remoting.ServerLogEntry.VALUE_EVENT_NAME_SESSION_ID_OLD_ = 'session-id-old';
/** @private */
remoting.ServerLogEntry.VALUE_EVENT_NAME_SESSION_ID_NEW_ = 'session-id-new';
/** /**
* Sets one field in this log entry. * Sets one field in this log entry.
* *
...@@ -249,12 +255,44 @@ remoting.ServerLogEntry.prototype.addStatsField = function( ...@@ -249,12 +255,44 @@ remoting.ServerLogEntry.prototype.addStatsField = function(
}; };
/** /**
* Adds an ID field to this log entry. * Makes a log entry for a "this session ID is old" event.
*
* @param {string} sessionId
* @return {remoting.ServerLogEntry}
*/
remoting.ServerLogEntry.makeSessionIdOld = function(sessionId) {
var entry = new remoting.ServerLogEntry();
entry.set(remoting.ServerLogEntry.KEY_ROLE_,
remoting.ServerLogEntry.VALUE_ROLE_CLIENT_);
entry.set(remoting.ServerLogEntry.KEY_EVENT_NAME_,
remoting.ServerLogEntry.VALUE_EVENT_NAME_SESSION_ID_OLD_);
entry.addSessionIdField(sessionId);
return entry;
};
/**
* Makes a log entry for a "this session ID is new" event.
*
* @param {string} sessionId
* @return {remoting.ServerLogEntry}
*/
remoting.ServerLogEntry.makeSessionIdNew = function(sessionId) {
var entry = new remoting.ServerLogEntry();
entry.set(remoting.ServerLogEntry.KEY_ROLE_,
remoting.ServerLogEntry.VALUE_ROLE_CLIENT_);
entry.set(remoting.ServerLogEntry.KEY_EVENT_NAME_,
remoting.ServerLogEntry.VALUE_EVENT_NAME_SESSION_ID_NEW_);
entry.addSessionIdField(sessionId);
return entry;
};
/**
* Adds a session ID field to this log entry.
* *
* @param {string} id * @param {string} sessionId
*/ */
remoting.ServerLogEntry.prototype.addIdField = function(id) { remoting.ServerLogEntry.prototype.addSessionIdField = function(sessionId) {
this.set(remoting.ServerLogEntry.KEY_ID_, id); this.set(remoting.ServerLogEntry.KEY_SESSION_ID_, sessionId);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment