Skip to content

Commit

Permalink
[Chromoting] Implement HEARTBEAT log message on webapp.
Browse files Browse the repository at this point in the history
This CL sends a HEARTBEAT message from the webapp to the telemetry backend
whenever the app is launched.

This will be used to help us understand how many clients are deployed in
a percentage push.

BUG=502095

Review URL: https://codereview.chromium.org/1219043003

Cr-Commit-Position: refs/heads/master@{#336956}
  • Loading branch information
kelvinp authored and Commit bot committed Jul 1, 2015
1 parent 8a0dcf1 commit 74f3b3c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions remoting/remoting_webapp_files.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
'webapp/base/js/oauth2.js',
'webapp/base/js/oauth2_api.js',
'webapp/base/js/oauth2_api_impl.js',
'webapp/base/js/platform.js',
'webapp/base/js/plugin_settings.js',
'webapp/base/js/telemetry_event_writer.js',
'webapp/base/js/typecheck.js',
Expand Down
8 changes: 4 additions & 4 deletions remoting/webapp/base/js/telemetry_event_writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ remoting.TelemetryEventWriter.Service.prototype.init = function() {
new base.ChromeEventHook(chrome.runtime.onSuspend,
this.onSuspend_.bind(this)));

this.ipc_.register(IpcNames.WRITE, this.write_.bind(this));
this.ipc_.register(IpcNames.WRITE, this.write.bind(this));
this.eventWriter_.flush();
}
// Only listen for new incoming requests after we have loaded the pending
Expand All @@ -72,9 +72,9 @@ remoting.TelemetryEventWriter.Service.prototype.unbindSession =
* @param {string} windowId The source window id of the IPC.
* @param {!Object} event The event to be written to the server.
*/
remoting.TelemetryEventWriter.Service.prototype.write_ =
remoting.TelemetryEventWriter.Service.prototype.write =
function(windowId, event) {
this.sessionMonitor_.onEvent(windowId, event);
this.sessionMonitor_.trackSessionStateChanges(windowId, event);
this.eventWriter_.write(event);
};

Expand Down Expand Up @@ -137,7 +137,7 @@ var SessionMonitor = function(eventWriter) {
* @param {string} windowId
* @param {Object} entry
*/
SessionMonitor.prototype.onEvent = function(windowId, entry) {
SessionMonitor.prototype.trackSessionStateChanges = function(windowId, entry) {
var event = /** @type {remoting.ChromotingEvent} */ (base.deepCopy(entry));

if (event.type !== remoting.ChromotingEvent.Type.SESSION_STATE) {
Expand Down
19 changes: 15 additions & 4 deletions remoting/webapp/crd/js/activation_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ var NEW_WINDOW_MENU_ID_ = 'new-window';
*
* @param {base.Ipc} ipc
* @param {remoting.V2AppLauncher} appLauncher
* @param {remoting.TelemetryEventWriter.Service} telemetryService
* @extends {base.EventSourceImpl}
* @implements {base.Disposable}
* @constructor
*/
remoting.ActivationHandler = function (ipc, appLauncher) {
remoting.ActivationHandler = function (ipc, appLauncher, telemetryService) {
base.inherits(this, base.EventSourceImpl);
this.defineEvents(base.values(remoting.ActivationHandler.Events));

Expand All @@ -34,6 +35,9 @@ remoting.ActivationHandler = function (ipc, appLauncher) {
/** @private {Map<string, base.Disposable>} */
this.windowClosedHooks_ = new Map();

/** @private */
this.telemetryService_ = telemetryService;

chrome.contextMenus.create({
id: NEW_WINDOW_MENU_ID_,
contexts: ['launcher'],
Expand Down Expand Up @@ -87,7 +91,7 @@ remoting.ActivationHandler.prototype.onContextMenu_ = function(info) {
* @private
*/
remoting.ActivationHandler.prototype.onRestart_ = function(id) {
this.appLauncher_.restart(id).then(this.registerCloseListener_.bind(this));
this.appLauncher_.restart(id).then(this.onWindowCreated_.bind(this));
};

/**
Expand All @@ -103,16 +107,23 @@ remoting.ActivationHandler.prototype.onLaunched_ = function() {
* @private
*/
remoting.ActivationHandler.prototype.createWindow_ = function() {
this.appLauncher_.launch().then(this.registerCloseListener_.bind(this));
this.appLauncher_.launch().then(this.onWindowCreated_.bind(this));
};

/**
* @param {string} windowId
*
* @private
*/
remoting.ActivationHandler.prototype.registerCloseListener_ = function(
remoting.ActivationHandler.prototype.onWindowCreated_ = function(
windowId) {
// Send the client heartbeat.
var event =
new remoting.ChromotingEvent(remoting.ChromotingEvent.Type.HEARTBEAT);
event.role = remoting.ChromotingEvent.Role.CLIENT;
this.telemetryService_.write(''/* No window Id for background page */, event);

// Register close handler.
var appWindow = chrome.app.window.get(windowId);
console.assert(!this.windowClosedHooks_.has(windowId),
'Duplicate close listener attached to window : ' + windowId);
Expand Down
4 changes: 2 additions & 2 deletions remoting/webapp/crd/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ BackgroundPage.prototype.preInit_ = function() {

if (base.isAppsV2()) {
this.appLauncher_ = new remoting.V2AppLauncher();
this.activationHandler_ = new remoting.ActivationHandler(
base.Ipc.getInstance(), this.appLauncher_);
this.telemetryService_ = remoting.TelemetryEventWriter.Service.create();
this.telemetryService_.init();
this.activationHandler_ = new remoting.ActivationHandler(
base.Ipc.getInstance(), this.appLauncher_, this.telemetryService_);
this.disposables_.add(new base.EventHook(
this.activationHandler_, remoting.ActivationHandler.Events.windowClosed,
this.telemetryService_.unbindSession.bind(this.telemetryService_)));
Expand Down
1 change: 1 addition & 0 deletions remoting/webapp/files.gni
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ remoting_webapp_background_html_all_js_files += [
"base/js/oauth2.js",
"base/js/oauth2_api.js",
"base/js/oauth2_api_impl.js",
"base/js/platform.js",
"base/js/plugin_settings.js",
"base/js/telemetry_event_writer.js",
"base/js/typecheck.js",
Expand Down

0 comments on commit 74f3b3c

Please sign in to comment.