Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 * Class handling creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
| 8 * | 8 * |
| 9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
| 10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 */ | 132 */ |
| 133 remoting.ClientSession.EventHandler.prototype.onDisconnected = | 133 remoting.ClientSession.EventHandler.prototype.onDisconnected = |
| 134 function(reason) {}; | 134 function(reason) {}; |
| 135 | 135 |
| 136 // Note that the positive values in both of these enums are copied directly | 136 // Note that the positive values in both of these enums are copied directly |
| 137 // from connection_to_host.h and must be kept in sync. Code in | 137 // from connection_to_host.h and must be kept in sync. Code in |
| 138 // chromoting_instance.cc converts the C++ enums into strings that must match | 138 // chromoting_instance.cc converts the C++ enums into strings that must match |
| 139 // the names given here. | 139 // the names given here. |
| 140 // The negative values represent state transitions that occur within the | 140 // The negative values represent state transitions that occur within the |
| 141 // web-app that have no corresponding plugin state transition. | 141 // web-app that have no corresponding plugin state transition. |
| 142 // NOTE: The enums here correspond to the Chromoting.Connections enumerated | |
| 143 // histogram defined in src/tools/metrics/histograms/histograms.xml. UMA | |
| 144 // histograms don't work well with negative values, so only non-negative values | |
| 145 // have been used for Chromoting.Connections. | |
| 146 // The maximum values for the UMA enumerated histogram is included here for use | |
| 147 // when uploading values to UMA. | |
| 148 // The 2 lists should be kept in sync, and any new enums should be append-only. | |
| 142 /** @enum {number} */ | 149 /** @enum {number} */ |
| 143 remoting.ClientSession.State = { | 150 remoting.ClientSession.State = { |
| 151 MIN_STATE_ENUM: -3, | |
| 144 CONNECTION_CANCELED: -3, // Connection closed (gracefully) before connecting. | 152 CONNECTION_CANCELED: -3, // Connection closed (gracefully) before connecting. |
| 145 CONNECTION_DROPPED: -2, // Succeeded, but subsequently closed with an error. | 153 CONNECTION_DROPPED: -2, // Succeeded, but subsequently closed with an error. |
| 146 CREATED: -1, | 154 CREATED: -1, |
| 147 UNKNOWN: 0, | 155 UNKNOWN: 0, |
| 148 INITIALIZING: 1, | 156 INITIALIZING: 1, |
| 149 CONNECTING: 2, | 157 CONNECTING: 2, |
| 150 AUTHENTICATED: 3, | 158 AUTHENTICATED: 3, |
| 151 CONNECTED: 4, | 159 CONNECTED: 4, |
| 152 CLOSED: 5, | 160 CLOSED: 5, |
| 153 FAILED: 6 | 161 FAILED: 6, |
| 162 HISTOGRAM_MAX: 10, // According to src/base/metrics/histogram.h, for a UMA | |
|
Ilya Sherman
2015/08/21 21:39:48
Optional nit: I think it might be clearer to defin
anandc
2015/08/21 21:56:10
Done.
| |
| 163 // enumerated histogram, the upper limit should be 1 above | |
| 164 // the max-enum. | |
| 154 }; | 165 }; |
| 155 | 166 |
| 156 /** | 167 /** |
| 157 * @param {string} state The state name. | 168 * @param {string} state The state name. |
| 158 * @return {remoting.ClientSession.State} The session state enum value. | 169 * @return {remoting.ClientSession.State} The session state enum value. |
| 159 */ | 170 */ |
| 160 remoting.ClientSession.State.fromString = function(state) { | 171 remoting.ClientSession.State.fromString = function(state) { |
| 161 if (!remoting.ClientSession.State.hasOwnProperty(state)) { | 172 if (!remoting.ClientSession.State.hasOwnProperty(state)) { |
| 162 throw "Invalid ClientSession.State: " + state; | 173 throw "Invalid ClientSession.State: " + state; |
| 163 } | 174 } |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 if (this.plugin_.hasCapability( | 570 if (this.plugin_.hasCapability( |
| 560 remoting.ClientSession.Capability.TOUCH_EVENTS)) { | 571 remoting.ClientSession.Capability.TOUCH_EVENTS)) { |
| 561 this.plugin_.enableTouchEvents(true); | 572 this.plugin_.enableTouchEvents(true); |
| 562 } | 573 } |
| 563 } else if (this.isFinished()) { | 574 } else if (this.isFinished()) { |
| 564 base.dispose(this.connectedDisposables_); | 575 base.dispose(this.connectedDisposables_); |
| 565 this.connectedDisposables_ = null; | 576 this.connectedDisposables_ = null; |
| 566 } | 577 } |
| 567 | 578 |
| 568 this.notifyStateChanges_(oldState, this.state_); | 579 this.notifyStateChanges_(oldState, this.state_); |
| 580 // Record state count in an UMA enumerated histogram. | |
| 581 recordState(this.state_); | |
| 569 this.logger_.logClientSessionStateChange( | 582 this.logger_.logClientSessionStateChange( |
| 570 this.state_, this.error_, this.xmppErrorCache_.getFirstError()); | 583 this.state_, this.error_, this.xmppErrorCache_.getFirstError()); |
| 571 }; | 584 }; |
| 572 | 585 |
| 573 /** | 586 /** |
| 587 * Records a Chromoting Connection State, stored in an UMA enumerated histogram. | |
| 588 * @param {remoting.ClientSession.State} state State identifier. | |
| 589 */ | |
| 590 function recordState(state) { | |
| 591 var metricDescription = { | |
| 592 metricName: 'Chromoting.Connections', | |
| 593 type: 'histogram-linear', | |
| 594 min: 1, // According to histogram.h, min should be 1. | |
| 595 max: remoting.ClientSession.State.HISTOGRAM_MAX, | |
| 596 // The # of buckets should include 1 for overflow. | |
|
Ilya Sherman
2015/08/21 21:39:48
This comment is misleading -- the +1 below is actu
anandc
2015/08/21 21:56:10
Done.
| |
| 597 buckets: remoting.ClientSession.State.HISTOGRAM_MAX + 1 | |
| 598 }; | |
| 599 | |
| 600 chrome.metricsPrivate.recordValue(metricDescription, state - | |
|
kelvinp
2015/08/21 21:32:09
Consider state == MIN_STATE_ENUM, the difference w
Ilya Sherman
2015/08/21 21:39:48
That is actually ok -- enumerated histograms typic
anandc
2015/08/21 21:56:10
Acknowledged.
anandc
2015/08/21 21:56:10
Added comment explaining how this works. Tested by
| |
| 601 remoting.ClientSession.State.MIN_STATE_ENUM); | |
| 602 } | |
| 603 | |
| 604 /** | |
| 574 * @param {remoting.ClientSession.State} oldState The new state for the session. | 605 * @param {remoting.ClientSession.State} oldState The new state for the session. |
| 575 * @param {remoting.ClientSession.State} newState The new state for the session. | 606 * @param {remoting.ClientSession.State} newState The new state for the session. |
| 576 * @private | 607 * @private |
| 577 */ | 608 */ |
| 578 remoting.ClientSession.prototype.notifyStateChanges_ = | 609 remoting.ClientSession.prototype.notifyStateChanges_ = |
| 579 function(oldState, newState) { | 610 function(oldState, newState) { |
| 580 /** @type {remoting.Error} */ | 611 /** @type {remoting.Error} */ |
| 581 var error; | 612 var error; |
| 582 switch (this.state_) { | 613 switch (this.state_) { |
| 583 case remoting.ClientSession.State.CONNECTED: | 614 case remoting.ClientSession.State.CONNECTED: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 * Enable or disable logging of connection errors due to a host being offline. | 691 * Enable or disable logging of connection errors due to a host being offline. |
| 661 * For example, if attempting a connection using a cached JID, host-offline | 692 * For example, if attempting a connection using a cached JID, host-offline |
| 662 * errors should not be logged because the JID will be refreshed and the | 693 * errors should not be logged because the JID will be refreshed and the |
| 663 * connection retried. | 694 * connection retried. |
| 664 * | 695 * |
| 665 * @param {boolean} enable True to log host-offline errors; false to suppress. | 696 * @param {boolean} enable True to log host-offline errors; false to suppress. |
| 666 */ | 697 */ |
| 667 remoting.ClientSession.prototype.logHostOfflineErrors = function(enable) { | 698 remoting.ClientSession.prototype.logHostOfflineErrors = function(enable) { |
| 668 this.logHostOfflineErrors_ = enable; | 699 this.logHostOfflineErrors_ = enable; |
| 669 }; | 700 }; |
| OLD | NEW |