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

Side by Side Diff: remoting/webapp/crd/js/log_to_server.js

Issue 1066003007: Include application ID in log entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | remoting/webapp/crd/js/server_log_entry.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Module for sending log entries to the server. 7 * Module for sending log entries to the server.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
11 11
12 /** @suppress {duplicate} */ 12 /** @suppress {duplicate} */
13 var remoting = remoting || {}; 13 var remoting = remoting || {};
14 14
15 /** 15 /**
16 * @param {remoting.SignalStrategy} signalStrategy Signal strategy. 16 * @param {remoting.SignalStrategy} signalStrategy Signal strategy.
17 * @constructor 17 * @constructor
18 */ 18 */
19 remoting.LogToServer = function(signalStrategy) { 19 remoting.LogToServer = function(signalStrategy) {
20 /** @private */ 20 /** @private */
21 this.statsAccumulator_ = new remoting.StatsAccumulator(); 21 this.statsAccumulator_ = new remoting.StatsAccumulator();
22 /** @private */ 22 /** @private */
23 this.sessionId_ = ''; 23 this.sessionId_ = '';
24 /** @private */ 24 /** @private */
25 this.applicationId_ = '';
anandc 2015/04/23 00:38:32 There are a few different ways we could track the
Jamie 2015/04/23 00:54:38 With my suggested change it's just a property acce
26 /** @private */
25 this.sessionIdGenerationTime_ = 0; 27 this.sessionIdGenerationTime_ = 0;
26 /** @private */ 28 /** @private */
27 this.sessionStartTime_ = new Date().getTime(); 29 this.sessionStartTime_ = new Date().getTime();
28 /** @private */ 30 /** @private */
29 this.signalStrategy_ = signalStrategy; 31 this.signalStrategy_ = signalStrategy;
30 /** @private {string} */ 32 /** @private {string} */
31 this.connectionType_ = ''; 33 this.connectionType_ = '';
32 34
33 this.setSessionId_(); 35 this.setSessionId_();
36 this.setApplicationId_();
34 signalStrategy.sendConnectionSetupResults(this); 37 signalStrategy.sendConnectionSetupResults(this);
35 }; 38 };
36 39
37 // Constants used for generating a session ID. 40 // Constants used for generating a session ID.
38 /** @private */ 41 /** @private */
39 remoting.LogToServer.SESSION_ID_ALPHABET_ = 42 remoting.LogToServer.SESSION_ID_ALPHABET_ =
40 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; 43 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
41 /** @private */ 44 /** @private */
42 remoting.LogToServer.SESSION_ID_LEN_ = 20; 45 remoting.LogToServer.SESSION_ID_LEN_ = 20;
43 46
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 88
86 /** 89 /**
87 * @param {remoting.SignalStrategy.Type} strategyType 90 * @param {remoting.SignalStrategy.Type} strategyType
88 * @param {remoting.FallbackSignalStrategy.Progress} progress 91 * @param {remoting.FallbackSignalStrategy.Progress} progress
89 */ 92 */
90 remoting.LogToServer.prototype.logSignalStrategyProgress = 93 remoting.LogToServer.prototype.logSignalStrategyProgress =
91 function(strategyType, progress) { 94 function(strategyType, progress) {
92 this.maybeExpireSessionId_(); 95 this.maybeExpireSessionId_();
93 var entry = remoting.ServerLogEntry.makeSignalStrategyProgress( 96 var entry = remoting.ServerLogEntry.makeSignalStrategyProgress(
94 this.sessionId_, strategyType, progress); 97 this.sessionId_, strategyType, progress);
95 this.log_(entry); 98 this.log_(entry);
anandc 2015/04/23 00:38:32 Is there a reason we're not setting the webapp and
Jamie 2015/04/23 00:54:38 No; I just didn't think to include that informatio
96 }; 99 };
97 100
98 /** 101 /**
99 * Whether a session state is one of the states that occurs at the start of 102 * Whether a session state is one of the states that occurs at the start of
100 * a session. 103 * a session.
101 * 104 *
102 * @private 105 * @private
103 * @param {remoting.ClientSession.State} state 106 * @param {remoting.ClientSession.State} state
104 * @return {boolean} 107 * @return {boolean}
105 */ 108 */
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 * Sends a log entry to the server. 170 * Sends a log entry to the server.
168 * 171 *
169 * @private 172 * @private
170 * @param {remoting.ServerLogEntry} entry 173 * @param {remoting.ServerLogEntry} entry
171 */ 174 */
172 remoting.LogToServer.prototype.log_ = function(entry) { 175 remoting.LogToServer.prototype.log_ = function(entry) {
173 // Log the time taken to get to this point from the time this session started. 176 // Log the time taken to get to this point from the time this session started.
174 var sessionDurationInSeconds = 177 var sessionDurationInSeconds =
175 (new Date().getTime() - this.sessionStartTime_) / 1000.0; 178 (new Date().getTime() - this.sessionStartTime_) / 1000.0;
176 entry.addSessionDuration(sessionDurationInSeconds); 179 entry.addSessionDuration(sessionDurationInSeconds);
180 entry.addApplicationId(this.applicationId_);
177 181
178 // Send the stanza to the debug log. 182 // Send the stanza to the debug log.
179 console.log('Enqueueing log entry:'); 183 console.log('Enqueueing log entry:');
180 entry.toDebugLog(1); 184 entry.toDebugLog(1);
181 185
182 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' + 186 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' +
183 'type="set" xmlns:cli="jabber:client">' + 187 'type="set" xmlns:cli="jabber:client">' +
184 '<gr:log xmlns:gr="google:remoting">' + 188 '<gr:log xmlns:gr="google:remoting">' +
185 entry.toStanza() + 189 entry.toStanza() +
186 '</gr:log>' + 190 '</gr:log>' +
187 '</cli:iq>'; 191 '</cli:iq>';
188 this.signalStrategy_.sendMessage(stanza); 192 this.signalStrategy_.sendMessage(stanza);
189 }; 193 };
190 194
191 /** 195 /**
192 * Sets the session ID to a random string. 196 * Sets the session ID to a random string.
193 * 197 *
194 * @private 198 * @private
195 */ 199 */
196 remoting.LogToServer.prototype.setSessionId_ = function() { 200 remoting.LogToServer.prototype.setSessionId_ = function() {
197 this.sessionId_ = remoting.LogToServer.generateSessionId_(); 201 this.sessionId_ = remoting.LogToServer.generateSessionId_();
198 this.sessionIdGenerationTime_ = new Date().getTime(); 202 this.sessionIdGenerationTime_ = new Date().getTime();
199 }; 203 };
200 204
201 /** 205 /**
206 * Sets the application ID for this session.
207 *
208 * @private
209 */
210 remoting.LogToServer.prototype.setApplicationId_ = function() {
211 this.applicationId_ = chrome.i18n.getMessage('@@extension_id');
Jamie 2015/04/23 00:54:38 chrome.runtime.id would be a better way of getting
anandc 2015/04/23 01:26:59 Done.
rmsousa 2015/04/23 01:55:51 Drive-by: For app remoting, there are cases (e.g.
212 };
213
214 /**
202 * Clears the session ID. 215 * Clears the session ID.
203 * 216 *
204 * @private 217 * @private
205 */ 218 */
206 remoting.LogToServer.prototype.clearSessionId_ = function() { 219 remoting.LogToServer.prototype.clearSessionId_ = function() {
207 this.sessionId_ = ''; 220 this.sessionId_ = '';
208 this.sessionIdGenerationTime_ = 0; 221 this.sessionIdGenerationTime_ = 0;
209 }; 222 };
210 223
211 /** 224 /**
212 * Sets a new session ID, if the current session ID has reached its maximum age. 225 * Sets a new session ID, if the current session ID has reached its maximum age.
213 * 226 *
214 * This method also logs the old and new session IDs to the server, in separate 227 * This method also logs the old and new session IDs to the server, in separate
215 * log entries. 228 * log entries.
216 * 229 *
217 * @private 230 * @private
218 */ 231 */
219 remoting.LogToServer.prototype.maybeExpireSessionId_ = function() { 232 remoting.LogToServer.prototype.maybeExpireSessionId_ = function() {
220 if ((this.sessionId_ != '') && 233 if ((this.sessionId_ != '') &&
221 (new Date().getTime() - this.sessionIdGenerationTime_ >= 234 (new Date().getTime() - this.sessionIdGenerationTime_ >=
222 remoting.LogToServer.MAX_SESSION_ID_AGE)) { 235 remoting.LogToServer.MAX_SESSION_ID_AGE)) {
223 // Log the old session ID. 236 // Log the old session ID.
224 var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_); 237 var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_);
anandc 2015/04/23 00:38:32 Same question as above: why don't we set the webap
225 this.log_(entry); 238 this.log_(entry);
226 // Generate a new session ID. 239 // Generate a new session ID.
227 this.setSessionId_(); 240 this.setSessionId_();
228 // Log the new session ID. 241 // Log the new session ID.
229 entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_); 242 entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_);
230 this.log_(entry); 243 this.log_(entry);
231 } 244 }
232 }; 245 };
233 246
234 /** 247 /**
235 * Generates a string that can be used as a session ID. 248 * Generates a string that can be used as a session ID.
236 * 249 *
237 * @private 250 * @private
238 * @return {string} a session ID 251 * @return {string} a session ID
239 */ 252 */
240 remoting.LogToServer.generateSessionId_ = function() { 253 remoting.LogToServer.generateSessionId_ = function() {
241 var idArray = []; 254 var idArray = [];
242 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) { 255 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) {
243 var index = 256 var index =
244 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length; 257 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length;
245 idArray.push( 258 idArray.push(
246 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1)); 259 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1));
247 } 260 }
248 return idArray.join(''); 261 return idArray.join('');
249 }; 262 };
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/crd/js/server_log_entry.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698