OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ | |
6 #define GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ | |
7 | |
8 #include "google_apis/gcm/engine/connection_factory.h" | |
9 | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "google_apis/gcm/protocol/mcs.pb.h" | |
12 #include "net/base/backoff_entry.h" | |
13 #include "net/base/network_change_notifier.h" | |
14 #include "net/socket/client_socket_handle.h" | |
15 #include "url/gurl.h" | |
16 | |
17 namespace net { | |
18 class HttpNetworkSession; | |
19 class NetLog; | |
20 } | |
21 | |
22 namespace gcm { | |
23 | |
24 class ConnectionHandlerImpl; | |
25 | |
26 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
| |
27 public ConnectionFactory, | |
28 public net::NetworkChangeNotifier::ConnectionTypeObserver, | |
29 public net::NetworkChangeNotifier::IPAddressObserver { | |
30 public: | |
31 ConnectionFactoryImpl( | |
32 const GURL& mcs_endpoint, | |
33 scoped_refptr<net::HttpNetworkSession> network_session, | |
34 net::NetLog* net_log); | |
35 virtual ~ConnectionFactoryImpl(); | |
36 | |
37 // ConnectionFactory implementation. | |
38 virtual ConnectionHandler* BuildConnectionHandler( | |
39 const ConnectionHandler::ProtoReceivedCallback& read_callback, | |
40 const ConnectionHandler::ProtoSentCallback& write_callback) OVERRIDE; | |
41 virtual void Connect(const mcs_proto::LoginRequest& login_request) OVERRIDE; | |
42 virtual bool IsEndpointReachable() const OVERRIDE; | |
43 | |
44 // NetworkChangeNotifier observer implementations. | |
45 virtual void OnConnectionTypeChanged( | |
46 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
47 virtual void OnIPAddressChanged() OVERRIDE; | |
48 | |
49 private: | |
50 // Implementation of Connect(..). If not in backoff, uses |login_request_| | |
51 // in attempting a connection/handshake. On connection/handshake failure, goes | |
52 // into backoff. | |
53 void ConnectImpl(); | |
54 | |
55 // Callback for Socket connection completion. | |
56 void OnConnectDone(int result); | |
57 | |
58 // ConnectionHandler callback for connection issues. | |
59 void ConnectionHandlerCallback(int result); | |
60 | |
61 // The MCS endpoint to make connections to. | |
62 const GURL mcs_endpoint_; | |
63 | |
64 // ---- net:: components for establishing connections. ---- | |
65 // Network session for creating new connections. | |
66 scoped_refptr<net::HttpNetworkSession> network_session_; | |
67 // Net log to use in connection attempts. | |
68 net::NetLog* net_log_; | |
69 // The handle to the socket for the current connection, if one exists. | |
70 net::ClientSocketHandle socket_handle_; | |
71 // Connection attempt backoff policy. | |
72 net::BackoffEntry backoff_entry_; | |
73 | |
74 // The current connection handler, if one exists. | |
75 scoped_ptr<ConnectionHandlerImpl> connection_handler_; | |
76 | |
77 // The current login request if a connection attempt is in progress/pending. | |
78 mcs_proto::LoginRequest login_request_; | |
79 | |
80 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); | |
83 }; | |
84 | |
85 } // namespace gcm | |
86 | |
87 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ | |
OLD | NEW |