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

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

Issue 213693002: [GCM] Add support for canary connection attempts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor tests Created 6 years, 9 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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 // Helper method for initalizing the connection hander. 69 // Helper method for initalizing the connection hander.
70 // Virtual for testing. 70 // Virtual for testing.
71 virtual void InitHandler(); 71 virtual void InitHandler();
72 72
73 // Helper method for creating a backoff entry. 73 // Helper method for creating a backoff entry.
74 // Virtual for testing. 74 // Virtual for testing.
75 virtual scoped_ptr<net::BackoffEntry> CreateBackoffEntry( 75 virtual scoped_ptr<net::BackoffEntry> CreateBackoffEntry(
76 const net::BackoffEntry::Policy* const policy); 76 const net::BackoffEntry::Policy* const policy);
77 77
78 // Helper method for creating the connection handler.
79 // Virtual for testing.
80 virtual scoped_ptr<ConnectionHandler> CreateConnectionHandler(
81 base::TimeDelta read_timeout,
82 const ConnectionHandler::ProtoReceivedCallback& read_callback,
83 const ConnectionHandler::ProtoSentCallback& write_callback,
84 const ConnectionHandler::ConnectionChangedCallback& connection_callback);
85
78 // Returns the current time in Ticks. 86 // Returns the current time in Ticks.
79 // Virtual for testing. 87 // Virtual for testing.
80 virtual base::TimeTicks NowTicks(); 88 virtual base::TimeTicks NowTicks();
81 89
82 // Callback for Socket connection completion. 90 // Callback for Socket connection completion.
83 void OnConnectDone(int result); 91 void OnConnectDone(int result);
84 92
85 // ConnectionHandler callback for connection issues. 93 // ConnectionHandler callback for connection issues.
86 void ConnectionHandlerCallback(int result); 94 void ConnectionHandlerCallback(int result);
87 95
88 private: 96 private:
97 // Helper method for checking backoff and triggering a connection as
98 // necessary.
99 void ConnectWithBackoff();
100
89 // Proxy resolution and connection functions. 101 // Proxy resolution and connection functions.
90 void OnProxyResolveDone(int status); 102 void OnProxyResolveDone(int status);
91 void OnProxyConnectDone(int status); 103 void OnProxyConnectDone(int status);
92 int ReconsiderProxyAfterError(int error); 104 int ReconsiderProxyAfterError(int error);
93 void ReportSuccessfulProxyConnection(); 105 void ReportSuccessfulProxyConnection();
94 106
95 void CloseSocket(); 107 void CloseSocket();
96 108
97 // The MCS endpoints to make connections to, sorted in order of priority. 109 // The MCS endpoints to make connections to, sorted in order of priority.
98 const std::vector<GURL> mcs_endpoints_; 110 const std::vector<GURL> mcs_endpoints_;
(...skipping 15 matching lines...) Expand all
114 // The current proxy info. 126 // The current proxy info.
115 net::ProxyInfo proxy_info_; 127 net::ProxyInfo proxy_info_;
116 // The handle to the socket for the current connection, if one exists. 128 // The handle to the socket for the current connection, if one exists.
117 net::ClientSocketHandle socket_handle_; 129 net::ClientSocketHandle socket_handle_;
118 // Current backoff entry. 130 // Current backoff entry.
119 scoped_ptr<net::BackoffEntry> backoff_entry_; 131 scoped_ptr<net::BackoffEntry> backoff_entry_;
120 // Backoff entry from previous connection attempt. Updated on each login 132 // Backoff entry from previous connection attempt. Updated on each login
121 // completion. 133 // completion.
122 scoped_ptr<net::BackoffEntry> previous_backoff_; 134 scoped_ptr<net::BackoffEntry> previous_backoff_;
123 135
124 // Whether a connection attempt is currently in progress or we're in backoff 136 // Whether a connection attempt is currently actively in progress.
125 // waiting until the next connection attempt. |!connecting_| denotes
126 // steady state with an active connection.
127 bool connecting_; 137 bool connecting_;
128 138
139 // Whether the client is waiting for backoff to finish before attempting to
140 // connect. Canary jobs are able to preempt connections pending backoff
141 // expiration.
142 bool waiting_for_backoff_;
143
129 // Whether login successfully completed after the connection was established. 144 // Whether login successfully completed after the connection was established.
130 // If a connection reset happens while attempting to log in, the current 145 // If a connection reset happens while attempting to log in, the current
131 // backoff entry is reused (after incrementing with a new failure). 146 // backoff entry is reused (after incrementing with a new failure).
132 bool logging_in_; 147 bool logging_in_;
133 148
134 // The time of the last login completion. Used for calculating whether to 149 // The time of the last login completion. Used for calculating whether to
135 // restore a previous backoff entry and for measuring uptime. 150 // restore a previous backoff entry and for measuring uptime.
136 base::TimeTicks last_login_time_; 151 base::TimeTicks last_login_time_;
137 152
138 // The current connection handler, if one exists. 153 // The current connection handler, if one exists.
139 scoped_ptr<ConnectionHandlerImpl> connection_handler_; 154 scoped_ptr<ConnectionHandler> connection_handler_;
140 155
141 // Builder for generating new login requests. 156 // Builder for generating new login requests.
142 BuildLoginRequestCallback request_builder_; 157 BuildLoginRequestCallback request_builder_;
143 158
144 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; 159 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_;
145 160
146 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); 161 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl);
147 }; 162 };
148 163
149 } // namespace gcm 164 } // namespace gcm
150 165
151 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ 166 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698