The goog.net.BrowserChannel Class

goog.net.BrowserChannel(opt_clientVersion)

Encapsulates the logic for a single BrowserChannel.

opt_clientVersion {string=}
An application-specific version number that is sent to the server when connected.

.BACK_CHANNEL_MAX_RETRIES {number}

Maximum number of attempts to connect to the server for back channel requests.

The goog.net.BrowserChannel.Error Enum

Enum type for identifying a BrowserChannel error. … more

The goog.net.BrowserChannel.Event Namespace {Object}

Events fired by BrowserChannel and associated objects … more

.FORWARD_CHANNEL_RETRY_TIMEOUT {number}

The timeout in milliseconds for a forward channel request.

The goog.net.BrowserChannel.Handler Class

Interface for the browser channel handler … more

.INACTIVE_CHANNEL_RETRY_FACTOR {number}

When retrying for an inactive channel, we will multiply the total delay by this number.

.LATEST_CHANNEL_VERSION {number}

The latest protocol version that this class supports. We request this version from the server when opening the connection. Should match com.google.net.browserchannel.BrowserChannel.LATEST_CHANNEL_VERSION.

The goog.net.BrowserChannel.LogSaver Namespace

A LogSaver that can be used to accumulate all the debug logs for BrowserChannels so they can be sent to the server when a problem is detected. … more

The normal response for forward channel requests. Used only before version 8 of the protocol.

.OUTSTANDING_DATA_BACKCHANNEL_RETRY_CUTOFF {number}

A guess at a cutoff at which to no longer assume the backchannel is dead when we are slow to receive data. Number in bytes. Assumption: The worst bandwidth we work on is 50 kilobits/sec 50kbits/sec * (1 byte / 8 bits) * 6 sec dead backchannel timeout

The goog.net.BrowserChannel.QueuedMap Class

Simple container class for a (mapId, map) pair. … more

.RTT_ESTIMATE {number}

A number in MS of how long we guess the maxmium amount of time a round trip to the server should take. In the future this could be substituted with a real measurement of the RTT.

The goog.net.BrowserChannel.ServerReachability Enum

Types of events which reveal information about the reachability of the server. … more

The goog.net.BrowserChannel.ServerReachabilityEvent Class

Event class for goog.net.BrowserChannel.Event.SERVER_REACHABILITY_EVENT. … more

The goog.net.BrowserChannel.Stat Enum

Enum that identifies events for statistics that are interesting to track. TODO(user) - Change name not to use Event or use EventTarget … more

The goog.net.BrowserChannel.StatEvent Class

Event class for goog.net.BrowserChannel.Event.STAT_EVENT … more

The goog.net.BrowserChannel.State Enum

Enum type for the browser channel state machine. … more

The goog.net.BrowserChannel.TimingEvent Class

Event class for goog.net.BrowserChannel.Event.TIMING_EVENT … more

.connect(testPath, channelPath, opt_extraParams, opt_oldSessionId, opt_oldArrayId)

Starts the channel. This initiates connections to the server.

testPath {string}
The path for the test connection.
channelPath {string}
The path for the channel connection.
opt_extraParams {Object=}
Extra parameter keys and values to add to the requests.
opt_oldSessionId {string=}
Session ID from a previous session.
opt_oldArrayId {number=}
The last array ID from a previous session.

.correctHostPrefix(serverHostPrefix)

Decides which host prefix should be used, if any. If there is a handler, allows the handler to validate a host prefix provided by the server, and optionally override it.

serverHostPrefix {?string}
The host prefix provided by the server.
returns {?string}
The host prefix to actually use, if any. Will return null if the use of host prefixes was disabled via setAllowHostPrefix().

.createChannelRequest(channel, channelDebug, opt_sessionId, opt_requestId, opt_retryId)

Instantiates a ChannelRequest with the given parameters. Overidden in tests.

channel {goog.net.BrowserChannel|goog.net.BrowserTestChannel}
The BrowserChannel that owns this request.
channelDebug {goog.net.ChannelDebug}
A ChannelDebug to use for logging.
opt_sessionId {string=}
The session id for the channel.
opt_requestId {string|number=}
The request id for this request.
opt_retryId {number=}
The retry id for this request.
returns {goog.net.ChannelRequest}
The created channel request.

.createDataUri(hostPrefix, path, opt_overridePort)

Creates a data Uri applying logic for secondary hostprefix, port overrides, and versioning.

hostPrefix {?string}
The host prefix.
path {string}
The path on the host (may be absolute or relative).
opt_overridePort {number=}
Optional override port.
returns {goog.Uri}
The data URI.

.createXhrIo(hostPrefix)

Called when BC needs to create an XhrIo object. Override in a subclass if you need to customize the behavior, for example to enable the creation of XHR's capable of calling a secondary domain.

hostPrefix {?string}
The host prefix, if we need an XhrIo object capable of calling a secondary domain.
returns {!goog.net.XhrIo}
A new XhrIo object.

.disconnect()

Disconnects and closes the channel.

.getAllowChunkedMode()

Returns whether chunked mode is allowed. In certain debugging situations, it's useful for the application to have a way to disable chunked mode for a user.

returns {boolean}
Whether chunked mode is allowed.

.getAllowHostPrefix()

Returns whether the channel allows the use of a subdomain. There may be cases where this isn't allowed.

returns {boolean}
Whether a host prefix is allowed.

.getBackChannelMaxRetries()

returns {number}
The max number of back-channel retries, which is a constant.

.getBackChannelUri(hostPrefix, path)

Gets the Uri used for the connection that receives data from the server.

hostPrefix {?string}
The host prefix.
path {string}
The path on the host.
returns {goog.Uri}
The back channel URI.

.getChannelDebug()

Returns the browserchannel logger.

returns {goog.net.ChannelDebug}
The channel debug object.

.getExtraHeaders()

Returns the extra HTTP headers to add to all the requests sent to the server.

returns {Object}
The HTTP headers, or null.

.getForwardChannelMaxRetries()

returns {number}
The max number of forward-channel retries, which will be 0 in fail-fast mode.

.getForwardChannelUri(path)

Gets the Uri used for the connection that sends data to the server.

path {string}
The path on the host.
returns {goog.Uri}
The forward channel URI.

.getHandler()

Returns the handler used for channel callback events.

returns {goog.net.BrowserChannel.Handler}
The handler.

.getLastArrayId()

returns {number}
The last array id received.

.getLastStatusCode()

Return the last status code received for a request.

returns {number}
The last status code received for a request.

.getSessionId()

Returns the session id of the channel. Only available after the channel has been opened.

returns {string}
Session ID.

.getStatEventTarget()

Returns the singleton event target for stat events.

returns {goog.events.EventTarget}
The event target for stat events.

.getState()

Returns the browser channel state.

returns {goog.net.BrowserChannel.State}
The current state of the browser channel.

.hasOutstandingRequests()

Returns whether there are outstanding requests servicing the channel.

returns {boolean}
true if there are outstanding requests.

.isActive()

Gets whether this channel is currently active. This is used to determine the length of time to wait before retrying. This call delegates to the handler.

returns {boolean}
Whether the channel is currently active.

.isBuffered()

Returns whether the channel is buffered or not. This state is valid for querying only after the test connection has completed. This may be queried in the goog.net.BrowserChannel.okToMakeRequest() callback. A channel may be buffered if the test connection determines that a chunked response could not be sent down within a suitable time.

returns {boolean}
Whether the channel is buffered.

.isClosed()

Returns whether the channel is closed

returns {boolean}
true if the channel is closed.

.notifyServerReachabilityEvent(reachabilityType)

Notify the channel that a particular fine grained network event has occurred. Should be considered package-private.

reachabilityType {goog.net.BrowserChannel.ServerReachability}
The reachability event type.

.notifyStatEvent(stat)

Helper function to call the stat event callback.

stat {goog.net.BrowserChannel.Stat}
The stat.

.notifyTimingEvent(size, rtt, retries)

Helper function to notify listeners about POST request performance.

size {number}
Number of characters in the POST data.
rtt {number}
The amount of time from POST start to response.
retries {number}
The number of times the POST had to be retried.

.onEndExecution()

Helper function to call the end hook

.onRequestComplete(request)

Callback from ChannelRequest that indicates a request has completed.

request {goog.net.ChannelRequest}
The request object.

.onRequestData(request, responseText)

Callback from ChannelRequest for when new data is received

request {goog.net.ChannelRequest}
The request object.
responseText {string}
The text of the response.

.onStartExecution()

Helper function to call the start hook

.sendMap(map, opt_context)

Sends a request to the server. The format of the request is a Map data structure of key/value pairs. These maps are then encoded in a format suitable for the wire and then reconstituted as a Map data structure that the server can process.

map {Object|goog.structs.Map}
The map to send.
opt_context {?Object=}
The context associated with the map.

.setAllowChunkedMode(allowChunkedMode)

Sets whether chunked mode is allowed. In certain debugging situations, it's useful for the application to have a way to disable chunked mode for a user.

allowChunkedMode {boolean}
Whether chunked mode is allowed.

.setAllowHostPrefix(allowHostPrefix)

Sets whether the channel allows the use of a subdomain. There may be cases where this isn't allowed, for example, logging in with troutboard where using a subdomain causes Apache to force the user to authenticate twice.

allowHostPrefix {boolean}
Whether a host prefix is allowed.

.setChannelDebug(channelDebug)

Set the browserchannel logger. TODO(user): Add interface for channel loggers or remove this function.

channelDebug {goog.net.ChannelDebug}
The channel debug object.

.setEndThreadExecutionHook(endHook)

Allows the application to set an execution hooks for when BrowserChannel stops processing requests. This is useful to track timing or logging special information. The function takes no parameters and return void.

endHook {Function}
The function for the end hook.

.setExtraHeaders(extraHeaders)

Sets extra HTTP headers to add to all the requests sent to the server.

extraHeaders {Object}
The HTTP headers, or null.

.setFailFast(failFast)

When set to true, this changes the behavior of the forward channel so it will not retry requests; it will fail after one network failure, and if there was already one network failure, the request will fail immediately.

failFast {boolean}
Whether or not to fail fast.

.setForwardChannelMaxRetries(retries)

Sets the maximum number of attempts to connect to the server for forward channel requests.

retries {number}
The maximum number of attempts.

.setForwardChannelRequestTimeout(timeoutMs)

Sets the timeout for a forward channel request.

timeoutMs {number}
The timeout in milliseconds.

.setHandler(handler)

Sets the handler used for channel callback events.

handler {goog.net.BrowserChannel.Handler}
The handler to set.

.setParser(parser)

Sets a new parser for the response payload. A custom parser may be set to avoid using eval(), for example. By default, the parser uses {@code goog.json.unsafeParse}.

parser {!goog.string.Parser}
Parser.

.setRetryDelay(baseDelayMs, delaySeedMs)

baseDelayMs {number}
The base part of the retry delay, in ms.
delaySeedMs {number}
A random delay between 0 and this is added to the base part.

.setStartThreadExecutionHook(startHook)

Allows the application to set an execution hooks for when BrowserChannel starts processing requests. This is useful to track timing or logging special information. The function takes no parameters and return void.

startHook {Function}
The function for the start hook.

.setTimeout(fn, ms)

Wrapper around SafeTimeout which calls the start and end execution hooks with a try...finally block.

fn {Function}
The callback function.
ms {number}
The time in MS for the timer.
returns {number}
The ID of the timer.

.shouldUseSecondaryDomains()

Determines whether to use a secondary domain when the server gives us a host prefix. This allows us to work around browser per-domain connection limits. Currently, we only use secondary domains when using Trident's ActiveXObject, because it supports cross-domain requests out of the box. Even if we wanted to use secondary domains on Gecko/Webkit, they wouldn't work due to security restrictions on cross-origin XHRs. Note that in IE10 we no longer use ActiveX since it's not supported in Metro mode and IE10 supports XHR streaming. If you need to use secondary domains on other browsers, you'll need to override this method in a subclass, and make sure that those browsers use some messaging mechanism that works cross-domain.

returns {boolean}
Whether to use secondary domains.
@see
http://code.google.com/p/closure-library/issues/detail?id=339

.testConnectionBlocked(testChannel)

Callback from BrowserTestChannel for when the channel is blocked.

testChannel {goog.net.BrowserTestChannel}
The BrowserTestChannel.

.testConnectionFailure(testChannel, errorCode)

Callback from BrowserTestChannel for when the channel has an error.

testChannel {goog.net.BrowserTestChannel}
The BrowserTestChannel.
errorCode {goog.net.ChannelRequest.Error}
The error code of the failure.

.testConnectionFinished(testChannel, useChunked)

Callback from BrowserTestChannel for when the channel is finished.

testChannel {goog.net.BrowserTestChannel}
The BrowserTestChannel.
useChunked {boolean}
Whether we can chunk responses.