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

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

Issue 2481873002: Added ClientEvent proto and structure for storing events in the factory. (Closed)
Patch Set: Created 4 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 unified diff | Download patch
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 <stddef.h> 10 #include <stddef.h>
11 11
12 #include <google/protobuf/repeated_field.h>
13
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h" 16 #include "base/time/time.h"
15 #include "google_apis/gcm/engine/connection_handler.h" 17 #include "google_apis/gcm/engine/connection_handler.h"
16 #include "google_apis/gcm/protocol/mcs.pb.h" 18 #include "google_apis/gcm/protocol/mcs.pb.h"
17 #include "net/base/backoff_entry.h" 19 #include "net/base/backoff_entry.h"
18 #include "net/base/network_change_notifier.h" 20 #include "net/base/network_change_notifier.h"
19 #include "net/log/net_log_with_source.h" 21 #include "net/log/net_log_with_source.h"
20 #include "net/proxy/proxy_info.h" 22 #include "net/proxy/proxy_info.h"
21 #include "net/proxy/proxy_service.h" 23 #include "net/proxy/proxy_service.h"
22 #include "net/socket/client_socket_handle.h" 24 #include "net/socket/client_socket_handle.h"
23 #include "url/gurl.h" 25 #include "url/gurl.h"
24 26
27 namespace mcs_proto {
28 class ClientEvent;
29 }
30
25 namespace net { 31 namespace net {
26 class HttpNetworkSession; 32 class HttpNetworkSession;
27 class NetLog; 33 class NetLog;
28 } 34 }
29 35
30 namespace gcm { 36 namespace gcm {
31 37
32 class ConnectionHandlerImpl; 38 class ConnectionHandlerImpl;
33 class GCMStatsRecorder; 39 class GCMStatsRecorder;
34 40
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Returns the server to which the factory is currently connected, or if 78 // Returns the server to which the factory is currently connected, or if
73 // a connection is currently pending, the server to which the next connection 79 // a connection is currently pending, the server to which the next connection
74 // attempt will be made. 80 // attempt will be made.
75 GURL GetCurrentEndpoint() const; 81 GURL GetCurrentEndpoint() const;
76 82
77 // Returns the IPEndpoint to which the factory is currently connected. If no 83 // Returns the IPEndpoint to which the factory is currently connected. If no
78 // connection is active, returns an empty IPEndpoint. 84 // connection is active, returns an empty IPEndpoint.
79 net::IPEndPoint GetPeerIP(); 85 net::IPEndPoint GetPeerIP();
80 86
81 protected: 87 protected:
82 // Implementation of Connect(..). If not in backoff, uses |login_request_| 88 // Initiate the connection to the GCM server.
83 // in attempting a connection/handshake. On connection/handshake failure, goes
84 // into backoff.
85 // Virtual for testing. 89 // Virtual for testing.
86 virtual void ConnectImpl(); 90 virtual void StartConnection();
87 91
88 // Helper method for initalizing the connection hander. 92 // Helper method for initalizing the connection hander.
89 // Virtual for testing. 93 // Virtual for testing.
90 virtual void InitHandler(); 94 virtual void InitHandler();
91 95
92 // Helper method for creating a backoff entry. 96 // Helper method for creating a backoff entry.
93 // Virtual for testing. 97 // Virtual for testing.
94 virtual std::unique_ptr<net::BackoffEntry> CreateBackoffEntry( 98 virtual std::unique_ptr<net::BackoffEntry> CreateBackoffEntry(
95 const net::BackoffEntry::Policy* const policy); 99 const net::BackoffEntry::Policy* const policy);
96 100
97 // Helper method for creating the connection handler. 101 // Helper method for creating the connection handler.
98 // Virtual for testing. 102 // Virtual for testing.
99 virtual std::unique_ptr<ConnectionHandler> CreateConnectionHandler( 103 virtual std::unique_ptr<ConnectionHandler> CreateConnectionHandler(
100 base::TimeDelta read_timeout, 104 base::TimeDelta read_timeout,
101 const ConnectionHandler::ProtoReceivedCallback& read_callback, 105 const ConnectionHandler::ProtoReceivedCallback& read_callback,
102 const ConnectionHandler::ProtoSentCallback& write_callback, 106 const ConnectionHandler::ProtoSentCallback& write_callback,
103 const ConnectionHandler::ConnectionChangedCallback& connection_callback); 107 const ConnectionHandler::ConnectionChangedCallback& connection_callback);
104 108
105 // Returns the current time in Ticks. 109 // Returns the current time in Ticks.
106 // Virtual for testing. 110 // Virtual for testing.
107 virtual base::TimeTicks NowTicks(); 111 virtual base::TimeTicks NowTicks();
108 112
109 // Callback for Socket connection completion. 113 // Callback for Socket connection completion.
110 void OnConnectDone(int result); 114 void OnConnectDone(int result);
111 115
112 // ConnectionHandler callback for connection issues. 116 // ConnectionHandler callback for connection issues.
113 void ConnectionHandlerCallback(int result); 117 void ConnectionHandlerCallback(int result);
114 118
119 // Connection attempts since the last successful connection.
120 google::protobuf::RepeatedPtrField<mcs_proto::ClientEvent> client_events_;
121
122 // Current connection attempt.
123 mcs_proto::ClientEvent current_event_;
124
115 private: 125 private:
116 // Helper method for checking backoff and triggering a connection as 126 // Helper method for checking backoff and triggering a connection as
117 // necessary. 127 // necessary.
118 void ConnectWithBackoff(); 128 void ConnectWithBackoff();
119 129
130 // Implementation of Connect(..). If not in backoff, uses |login_request_|
131 // in attempting a connection/handshake. On connection/handshake failure, goes
132 // into backoff.
133 void ConnectImpl();
134
120 // Proxy resolution and connection functions. 135 // Proxy resolution and connection functions.
121 void OnProxyResolveDone(int status); 136 void OnProxyResolveDone(int status);
122 void OnProxyConnectDone(int status); 137 void OnProxyConnectDone(int status);
123 int ReconsiderProxyAfterError(int error); 138 int ReconsiderProxyAfterError(int error);
124 void ReportSuccessfulProxyConnection(); 139 void ReportSuccessfulProxyConnection();
125 140
126 // Closes the local socket if one is present, and resets connection handler. 141 // Closes the local socket if one is present, and resets connection handler.
127 void CloseSocket(); 142 void CloseSocket();
128 143
129 // Updates the GCM Network Session's HttpAuthCache with the HTTP Network 144 // Updates the GCM Network Session's HttpAuthCache with the HTTP Network
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 207
193 // Builder for generating new login requests. 208 // Builder for generating new login requests.
194 BuildLoginRequestCallback request_builder_; 209 BuildLoginRequestCallback request_builder_;
195 210
196 // Recorder that records GCM activities for debugging purpose. Not owned. 211 // Recorder that records GCM activities for debugging purpose. Not owned.
197 GCMStatsRecorder* recorder_; 212 GCMStatsRecorder* recorder_;
198 213
199 // Listener for connection change events. 214 // Listener for connection change events.
200 ConnectionListener* listener_; 215 ConnectionListener* listener_;
201 216
217 // The total number of ClientEvents which are currently buffered.
218 int total_client_events_ = -1;
219
220 // The state of the network when last updated.
221 net::NetworkChangeNotifier::ConnectionType network_type_ =
222 net::NetworkChangeNotifier::CONNECTION_NONE;
223
202 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; 224 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_;
203 225
204 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); 226 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl);
205 }; 227 };
206 228
207 } // namespace gcm 229 } // namespace gcm
208 230
209 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ 231 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/connection_factory_impl.cc » ('j') | google_apis/gcm/engine/connection_factory_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698