namespace gcm {
class ConnectionHandlerImpl;
+class GCMStatsRecorder;
class GCM_EXPORT ConnectionFactoryImpl :
public ConnectionFactory,
- public net::NetworkChangeNotifier::ConnectionTypeObserver,
- public net::NetworkChangeNotifier::IPAddressObserver {
+ public net::NetworkChangeNotifier::NetworkChangeObserver {
public:
+ // |http_network_session| is an optional network session to use as a source
+ // for proxy auth credentials (via its HttpAuthCache). |gcm_network_session|
+ // is the network session through which GCM connections should be made, and
+ // must not be the same as |http_network_session|.
ConnectionFactoryImpl(
const std::vector<GURL>& mcs_endpoints,
const net::BackoffEntry::Policy& backoff_policy,
- scoped_refptr<net::HttpNetworkSession> network_session,
- net::NetLog* net_log);
+ const scoped_refptr<net::HttpNetworkSession>& gcm_network_session,
+ const scoped_refptr<net::HttpNetworkSession>& http_network_session,
+ net::NetLog* net_log,
+ GCMStatsRecorder* recorder);
virtual ~ConnectionFactoryImpl();
// ConnectionFactory implementation.
virtual ConnectionHandler* GetConnectionHandler() const OVERRIDE;
virtual void Connect() OVERRIDE;
virtual bool IsEndpointReachable() const OVERRIDE;
+ virtual std::string GetConnectionStateString() const OVERRIDE;
virtual base::TimeTicks NextRetryAttempt() const OVERRIDE;
virtual void SignalConnectionReset(ConnectionResetReason reason) OVERRIDE;
+ virtual void SetConnectionListener(ConnectionListener* listener) OVERRIDE;
- // NetworkChangeNotifier observer implementations.
- virtual void OnConnectionTypeChanged(
+ // NetworkChangeObserver implementation.
+ virtual void OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
- virtual void OnIPAddressChanged() OVERRIDE;
// Returns the server to which the factory is currently connected, or if
// a connection is currently pending, the server to which the next connection
// attempt will be made.
GURL GetCurrentEndpoint() const;
+ // Returns the IPEndpoint to which the factory is currently connected. If no
+ // connection is active, returns an empty IPEndpoint.
+ net::IPEndPoint GetPeerIP();
+
protected:
// Implementation of Connect(..). If not in backoff, uses |login_request_|
// in attempting a connection/handshake. On connection/handshake failure, goes
int ReconsiderProxyAfterError(int error);
void ReportSuccessfulProxyConnection();
+ // Closes the local socket if one is present, and resets connection handler.
void CloseSocket();
+ // Updates the GCM Network Session's HttpAuthCache with the HTTP Network
+ // Session's cache, if available.
+ void RebuildNetworkSessionAuthCache();
+
// The MCS endpoints to make connections to, sorted in order of priority.
const std::vector<GURL> mcs_endpoints_;
// Index to the endpoint for which a connection should be attempted next.
const net::BackoffEntry::Policy backoff_policy_;
// ---- net:: components for establishing connections. ----
- // Network session for creating new connections.
- const scoped_refptr<net::HttpNetworkSession> network_session_;
+ // Network session for creating new GCM connections.
+ const scoped_refptr<net::HttpNetworkSession> gcm_network_session_;
+ // HTTP Network session. If set, is used for extracting proxy auth
+ // credentials. If not set, is ignored.
+ const scoped_refptr<net::HttpNetworkSession> http_network_session_;
// Net log to use in connection attempts.
net::BoundNetLog bound_net_log_;
// The current PAC request, if one exists. Owned by the proxy service.
// expiration.
bool waiting_for_backoff_;
+ // Whether the NetworkChangeNotifier has informed the client that there is
+ // no current connection. No connection attempts will be made until the
+ // client is informed of a valid connection type.
+ bool waiting_for_network_online_;
+
// Whether login successfully completed after the connection was established.
// If a connection reset happens while attempting to log in, the current
// backoff entry is reused (after incrementing with a new failure).
// Builder for generating new login requests.
BuildLoginRequestCallback request_builder_;
+ // Recorder that records GCM activities for debugging purpose. Not owned.
+ GCMStatsRecorder* recorder_;
+
+ // Listener for connection change events.
+ ConnectionListener* listener_;
+
base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl);