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

Side by Side Diff: google_apis/gcm/engine/connection_factory_impl.h

Issue 160703002: [GCM] Track connection failures properly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/time/time.h"
11 #include "google_apis/gcm/protocol/mcs.pb.h" 12 #include "google_apis/gcm/protocol/mcs.pb.h"
12 #include "net/base/backoff_entry.h" 13 #include "net/base/backoff_entry.h"
13 #include "net/base/network_change_notifier.h" 14 #include "net/base/network_change_notifier.h"
14 #include "net/socket/client_socket_handle.h" 15 #include "net/socket/client_socket_handle.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 namespace net { 18 namespace net {
18 class HttpNetworkSession; 19 class HttpNetworkSession;
19 class NetLog; 20 class NetLog;
20 } 21 }
(...skipping 16 matching lines...) Expand all
37 38
38 // ConnectionFactory implementation. 39 // ConnectionFactory implementation.
39 virtual void Initialize( 40 virtual void Initialize(
40 const BuildLoginRequestCallback& request_builder, 41 const BuildLoginRequestCallback& request_builder,
41 const ConnectionHandler::ProtoReceivedCallback& read_callback, 42 const ConnectionHandler::ProtoReceivedCallback& read_callback,
42 const ConnectionHandler::ProtoSentCallback& write_callback) OVERRIDE; 43 const ConnectionHandler::ProtoSentCallback& write_callback) OVERRIDE;
43 virtual ConnectionHandler* GetConnectionHandler() const OVERRIDE; 44 virtual ConnectionHandler* GetConnectionHandler() const OVERRIDE;
44 virtual void Connect() OVERRIDE; 45 virtual void Connect() OVERRIDE;
45 virtual bool IsEndpointReachable() const OVERRIDE; 46 virtual bool IsEndpointReachable() const OVERRIDE;
46 virtual base::TimeTicks NextRetryAttempt() const OVERRIDE; 47 virtual base::TimeTicks NextRetryAttempt() const OVERRIDE;
47 virtual void SignalConnectionReset() OVERRIDE; 48 virtual void SignalConnectionReset(ConnectionResetReason reason) OVERRIDE;
48 49
49 // NetworkChangeNotifier observer implementations. 50 // NetworkChangeNotifier observer implementations.
50 virtual void OnConnectionTypeChanged( 51 virtual void OnConnectionTypeChanged(
51 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 52 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
52 virtual void OnIPAddressChanged() OVERRIDE; 53 virtual void OnIPAddressChanged() OVERRIDE;
53 54
54 protected: 55 protected:
55 // Implementation of Connect(..). If not in backoff, uses |login_request_| 56 // Implementation of Connect(..). If not in backoff, uses |login_request_|
56 // in attempting a connection/handshake. On connection/handshake failure, goes 57 // in attempting a connection/handshake. On connection/handshake failure, goes
57 // into backoff. 58 // into backoff.
(...skipping 26 matching lines...) Expand all
84 // The backoff policy to use. 85 // The backoff policy to use.
85 const net::BackoffEntry::Policy backoff_policy_; 86 const net::BackoffEntry::Policy backoff_policy_;
86 87
87 // ---- net:: components for establishing connections. ---- 88 // ---- net:: components for establishing connections. ----
88 // Network session for creating new connections. 89 // Network session for creating new connections.
89 const scoped_refptr<net::HttpNetworkSession> network_session_; 90 const scoped_refptr<net::HttpNetworkSession> network_session_;
90 // Net log to use in connection attempts. 91 // Net log to use in connection attempts.
91 net::NetLog* const net_log_; 92 net::NetLog* const net_log_;
92 // The handle to the socket for the current connection, if one exists. 93 // The handle to the socket for the current connection, if one exists.
93 net::ClientSocketHandle socket_handle_; 94 net::ClientSocketHandle socket_handle_;
94 // Connection attempt backoff policy. 95 // Current backoff entry.
95 scoped_ptr<net::BackoffEntry> backoff_entry_; 96 scoped_ptr<net::BackoffEntry> backoff_entry_;
96 // Backoff policy from previous backoff attempt. 97 // Backoff entry from previous connection attempt. Updated on each login
98 // completion.
97 scoped_ptr<net::BackoffEntry> previous_backoff_; 99 scoped_ptr<net::BackoffEntry> previous_backoff_;
98 base::TimeTicks backoff_reset_time_;
99 100
100 // Whether a connection attempt is currently in progress or we're in backoff 101 // Whether a connection attempt is currently in progress or we're in backoff
101 // waiting until the next connection attempt. |!connecting_| denotes 102 // waiting until the next connection attempt. |!connecting_| denotes
102 // steady state with an active connection. 103 // steady state with an active connection.
103 bool connecting_; 104 bool connecting_;
104 105
106 // Whether login successfully completed after the connection was established.
107 // If a connection reset happens while attempting to log in, the current
108 // backoff entry is reused (after incrementing with a new failure).
109 bool logging_in_;
110
111 // The time of the last login completion. Used for calculating whether to
112 // restore a previous backoff entry and for measuring uptime.
113 base::TimeTicks last_login_time_;
114
105 // The current connection handler, if one exists. 115 // The current connection handler, if one exists.
106 scoped_ptr<ConnectionHandlerImpl> connection_handler_; 116 scoped_ptr<ConnectionHandlerImpl> connection_handler_;
107 117
108 // Builder for generating new login requests. 118 // Builder for generating new login requests.
109 BuildLoginRequestCallback request_builder_; 119 BuildLoginRequestCallback request_builder_;
110 120
111 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; 121 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_;
112 122
113 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); 123 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl);
114 }; 124 };
115 125
116 } // namespace gcm 126 } // namespace gcm
117 127
118 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ 128 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/connection_factory.h ('k') | google_apis/gcm/engine/connection_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698