| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ |
| 6 #define GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ |
| 7 | 7 |
| 8 #include "google_apis/gcm/engine/connection_factory.h" | 8 #include "google_apis/gcm/engine/connection_factory.h" |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class NetLog; | 22 class NetLog; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace gcm { | 25 namespace gcm { |
| 26 | 26 |
| 27 class ConnectionHandlerImpl; | 27 class ConnectionHandlerImpl; |
| 28 class GCMStatsRecorder; | 28 class GCMStatsRecorder; |
| 29 | 29 |
| 30 class GCM_EXPORT ConnectionFactoryImpl : | 30 class GCM_EXPORT ConnectionFactoryImpl : |
| 31 public ConnectionFactory, | 31 public ConnectionFactory, |
| 32 public net::NetworkChangeNotifier::ConnectionTypeObserver, | 32 public net::NetworkChangeNotifier::NetworkChangeObserver { |
| 33 public net::NetworkChangeNotifier::IPAddressObserver { | |
| 34 public: | 33 public: |
| 35 ConnectionFactoryImpl( | 34 ConnectionFactoryImpl( |
| 36 const std::vector<GURL>& mcs_endpoints, | 35 const std::vector<GURL>& mcs_endpoints, |
| 37 const net::BackoffEntry::Policy& backoff_policy, | 36 const net::BackoffEntry::Policy& backoff_policy, |
| 38 scoped_refptr<net::HttpNetworkSession> network_session, | 37 scoped_refptr<net::HttpNetworkSession> network_session, |
| 39 net::NetLog* net_log, | 38 net::NetLog* net_log, |
| 40 GCMStatsRecorder* recorder); | 39 GCMStatsRecorder* recorder); |
| 41 virtual ~ConnectionFactoryImpl(); | 40 virtual ~ConnectionFactoryImpl(); |
| 42 | 41 |
| 43 // ConnectionFactory implementation. | 42 // ConnectionFactory implementation. |
| 44 virtual void Initialize( | 43 virtual void Initialize( |
| 45 const BuildLoginRequestCallback& request_builder, | 44 const BuildLoginRequestCallback& request_builder, |
| 46 const ConnectionHandler::ProtoReceivedCallback& read_callback, | 45 const ConnectionHandler::ProtoReceivedCallback& read_callback, |
| 47 const ConnectionHandler::ProtoSentCallback& write_callback) OVERRIDE; | 46 const ConnectionHandler::ProtoSentCallback& write_callback) OVERRIDE; |
| 48 virtual ConnectionHandler* GetConnectionHandler() const OVERRIDE; | 47 virtual ConnectionHandler* GetConnectionHandler() const OVERRIDE; |
| 49 virtual void Connect() OVERRIDE; | 48 virtual void Connect() OVERRIDE; |
| 50 virtual bool IsEndpointReachable() const OVERRIDE; | 49 virtual bool IsEndpointReachable() const OVERRIDE; |
| 51 virtual std::string GetConnectionStateString() const OVERRIDE; | 50 virtual std::string GetConnectionStateString() const OVERRIDE; |
| 52 virtual base::TimeTicks NextRetryAttempt() const OVERRIDE; | 51 virtual base::TimeTicks NextRetryAttempt() const OVERRIDE; |
| 53 virtual void SignalConnectionReset(ConnectionResetReason reason) OVERRIDE; | 52 virtual void SignalConnectionReset(ConnectionResetReason reason) OVERRIDE; |
| 54 virtual void SetConnectionListener(ConnectionListener* listener) OVERRIDE; | 53 virtual void SetConnectionListener(ConnectionListener* listener) OVERRIDE; |
| 55 | 54 |
| 56 // NetworkChangeNotifier observer implementations. | 55 // NetworkChangeObserver implementation. |
| 57 virtual void OnConnectionTypeChanged( | 56 virtual void OnNetworkChanged( |
| 58 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 57 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 59 virtual void OnIPAddressChanged() OVERRIDE; | |
| 60 | 58 |
| 61 // Returns the server to which the factory is currently connected, or if | 59 // Returns the server to which the factory is currently connected, or if |
| 62 // a connection is currently pending, the server to which the next connection | 60 // a connection is currently pending, the server to which the next connection |
| 63 // attempt will be made. | 61 // attempt will be made. |
| 64 GURL GetCurrentEndpoint() const; | 62 GURL GetCurrentEndpoint() const; |
| 65 | 63 |
| 66 // Returns the IPEndpoint to which the factory is currently connected. If no | 64 // Returns the IPEndpoint to which the factory is currently connected. If no |
| 67 // connection is active, returns an empty IPEndpoint. | 65 // connection is active, returns an empty IPEndpoint. |
| 68 net::IPEndPoint GetPeerIP(); | 66 net::IPEndPoint GetPeerIP(); |
| 69 | 67 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 scoped_ptr<net::BackoffEntry> previous_backoff_; | 140 scoped_ptr<net::BackoffEntry> previous_backoff_; |
| 143 | 141 |
| 144 // Whether a connection attempt is currently actively in progress. | 142 // Whether a connection attempt is currently actively in progress. |
| 145 bool connecting_; | 143 bool connecting_; |
| 146 | 144 |
| 147 // Whether the client is waiting for backoff to finish before attempting to | 145 // Whether the client is waiting for backoff to finish before attempting to |
| 148 // connect. Canary jobs are able to preempt connections pending backoff | 146 // connect. Canary jobs are able to preempt connections pending backoff |
| 149 // expiration. | 147 // expiration. |
| 150 bool waiting_for_backoff_; | 148 bool waiting_for_backoff_; |
| 151 | 149 |
| 150 // Whether the NetworkChangeNotifier has informed the client that there is |
| 151 // no current connection. No connection attempts will be made until the |
| 152 // client is informed of a valid connection type. |
| 153 bool waiting_for_network_online_; |
| 154 |
| 152 // Whether login successfully completed after the connection was established. | 155 // Whether login successfully completed after the connection was established. |
| 153 // If a connection reset happens while attempting to log in, the current | 156 // If a connection reset happens while attempting to log in, the current |
| 154 // backoff entry is reused (after incrementing with a new failure). | 157 // backoff entry is reused (after incrementing with a new failure). |
| 155 bool logging_in_; | 158 bool logging_in_; |
| 156 | 159 |
| 157 // The time of the last login completion. Used for calculating whether to | 160 // The time of the last login completion. Used for calculating whether to |
| 158 // restore a previous backoff entry and for measuring uptime. | 161 // restore a previous backoff entry and for measuring uptime. |
| 159 base::TimeTicks last_login_time_; | 162 base::TimeTicks last_login_time_; |
| 160 | 163 |
| 161 // The current connection handler, if one exists. | 164 // The current connection handler, if one exists. |
| 162 scoped_ptr<ConnectionHandler> connection_handler_; | 165 scoped_ptr<ConnectionHandler> connection_handler_; |
| 163 | 166 |
| 164 // Builder for generating new login requests. | 167 // Builder for generating new login requests. |
| 165 BuildLoginRequestCallback request_builder_; | 168 BuildLoginRequestCallback request_builder_; |
| 166 | 169 |
| 167 // Recorder that records GCM activities for debugging purpose. Not owned. | 170 // Recorder that records GCM activities for debugging purpose. Not owned. |
| 168 GCMStatsRecorder* recorder_; | 171 GCMStatsRecorder* recorder_; |
| 169 | 172 |
| 170 // Listener for connection change events. | 173 // Listener for connection change events. |
| 171 ConnectionListener* listener_; | 174 ConnectionListener* listener_; |
| 172 | 175 |
| 173 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; | 176 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; |
| 174 | 177 |
| 175 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); | 178 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); |
| 176 }; | 179 }; |
| 177 | 180 |
| 178 } // namespace gcm | 181 } // namespace gcm |
| 179 | 182 |
| 180 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ | 183 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ |
| OLD | NEW |