Chromium Code Reviews| Index: google_apis/gcm/engine/connection_factory_impl.h |
| diff --git a/google_apis/gcm/engine/connection_factory_impl.h b/google_apis/gcm/engine/connection_factory_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a687aa7924266d81f4b5a4bec2009e19811e8d41 |
| --- /dev/null |
| +++ b/google_apis/gcm/engine/connection_factory_impl.h |
| @@ -0,0 +1,87 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ |
| +#define GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ |
| + |
| +#include "google_apis/gcm/engine/connection_factory.h" |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "google_apis/gcm/protocol/mcs.pb.h" |
| +#include "net/base/backoff_entry.h" |
| +#include "net/base/network_change_notifier.h" |
| +#include "net/socket/client_socket_handle.h" |
| +#include "url/gurl.h" |
| + |
| +namespace net { |
| +class HttpNetworkSession; |
| +class NetLog; |
| +} |
| + |
| +namespace gcm { |
| + |
| +class ConnectionHandlerImpl; |
| + |
| +class GCM_EXPORT ConnectionFactoryImpl : |
|
akalin
2013/11/02 00:15:43
tests for ConnectionFactoryImpl?
Nicolas Zea
2013/11/15 23:37:35
Wasn't sure how best to test the backoff logic, or
|
| + public ConnectionFactory, |
| + public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| + public net::NetworkChangeNotifier::IPAddressObserver { |
| + public: |
| + ConnectionFactoryImpl( |
| + const GURL& mcs_endpoint, |
| + scoped_refptr<net::HttpNetworkSession> network_session, |
| + net::NetLog* net_log); |
| + virtual ~ConnectionFactoryImpl(); |
| + |
| + // ConnectionFactory implementation. |
| + virtual ConnectionHandler* BuildConnectionHandler( |
| + const ConnectionHandler::ProtoReceivedCallback& read_callback, |
| + const ConnectionHandler::ProtoSentCallback& write_callback) OVERRIDE; |
| + virtual void Connect(const mcs_proto::LoginRequest& login_request) OVERRIDE; |
| + virtual bool IsEndpointReachable() const OVERRIDE; |
| + |
| + // NetworkChangeNotifier observer implementations. |
| + virtual void OnConnectionTypeChanged( |
| + net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| + virtual void OnIPAddressChanged() OVERRIDE; |
| + |
| + private: |
| + // Implementation of Connect(..). If not in backoff, uses |login_request_| |
| + // in attempting a connection/handshake. On connection/handshake failure, goes |
| + // into backoff. |
| + void ConnectImpl(); |
| + |
| + // Callback for Socket connection completion. |
| + void OnConnectDone(int result); |
| + |
| + // ConnectionHandler callback for connection issues. |
| + void ConnectionHandlerCallback(int result); |
| + |
| + // The MCS endpoint to make connections to. |
| + const GURL mcs_endpoint_; |
| + |
| + // ---- net:: components for establishing connections. ---- |
| + // Network session for creating new connections. |
| + scoped_refptr<net::HttpNetworkSession> network_session_; |
| + // Net log to use in connection attempts. |
| + net::NetLog* net_log_; |
| + // The handle to the socket for the current connection, if one exists. |
| + net::ClientSocketHandle socket_handle_; |
| + // Connection attempt backoff policy. |
| + net::BackoffEntry backoff_entry_; |
| + |
| + // The current connection handler, if one exists. |
| + scoped_ptr<ConnectionHandlerImpl> connection_handler_; |
| + |
| + // The current login request if a connection attempt is in progress/pending. |
| + mcs_proto::LoginRequest login_request_; |
| + |
| + base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); |
| +}; |
| + |
| +} // namespace gcm |
| + |
| +#endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ |