Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Unified Diff: google_apis/gcm/engine/connection_factory_impl.h

Issue 54743007: [GCM] Add connection factory for creating MCS connections (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e837895d110b6e373a7c3b07432c6a39b0fd36fe
--- /dev/null
+++ b/google_apis/gcm/engine/connection_factory_impl.h
@@ -0,0 +1,99 @@
+// 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 :
+ 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;
+ virtual base::TimeTicks NextRetryAttempt() const OVERRIDE;
+
+ // NetworkChangeNotifier observer implementations.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
+ virtual void OnIPAddressChanged() OVERRIDE;
+
+ protected:
+ // Implementation of Connect(..). If not in backoff, uses |login_request_|
+ // in attempting a connection/handshake. On connection/handshake failure, goes
+ // into backoff.
+ // Virtual for testing.
+ virtual void ConnectImpl();
+
+ // Helper method for initalizing the connection hander.
+ // Virtual for testing.
+ virtual void InitHandler();
+
+ // Helper method for creating a backoff entry.
+ // Virtual for testing.
+ virtual scoped_ptr<net::BackoffEntry> CreateBackoffEntry(
+ const net::BackoffEntry::Policy* const policy);
+
+ // Callback for Socket connection completion.
+ void OnConnectDone(int result);
+
+ private:
+ // 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_;
akalin 2013/11/21 04:13:09 const?
Nicolas Zea 2013/11/22 05:39:18 Done.
+ // Net log to use in connection attempts.
+ net::NetLog* net_log_;
akalin 2013/11/21 04:13:09 * const?
Nicolas Zea 2013/11/22 05:39:18 Done.
+ // The handle to the socket for the current connection, if one exists.
+ net::ClientSocketHandle socket_handle_;
+ // Connection attempt backoff policy.
+ scoped_ptr<net::BackoffEntry> backoff_entry_;
akalin 2013/11/21 04:13:09 const?
Nicolas Zea 2013/11/22 05:39:18 Set via virtual method for testing overrides, so d
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698