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

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: Added ConnectionEventTracker to manage all the events. Created 4 years 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 "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "google_apis/gcm/engine/connection_event_tracker.h"
15 #include "google_apis/gcm/engine/connection_handler.h" 16 #include "google_apis/gcm/engine/connection_handler.h"
16 #include "google_apis/gcm/protocol/mcs.pb.h" 17 #include "google_apis/gcm/protocol/mcs.pb.h"
17 #include "net/base/backoff_entry.h" 18 #include "net/base/backoff_entry.h"
18 #include "net/base/network_change_notifier.h" 19 #include "net/base/network_change_notifier.h"
19 #include "net/log/net_log_with_source.h" 20 #include "net/log/net_log_with_source.h"
20 #include "net/proxy/proxy_info.h" 21 #include "net/proxy/proxy_info.h"
21 #include "net/proxy/proxy_service.h" 22 #include "net/proxy/proxy_service.h"
22 #include "net/socket/client_socket_handle.h" 23 #include "net/socket/client_socket_handle.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Returns the server to which the factory is currently connected, or if 73 // 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 74 // a connection is currently pending, the server to which the next connection
74 // attempt will be made. 75 // attempt will be made.
75 GURL GetCurrentEndpoint() const; 76 GURL GetCurrentEndpoint() const;
76 77
77 // Returns the IPEndpoint to which the factory is currently connected. If no 78 // Returns the IPEndpoint to which the factory is currently connected. If no
78 // connection is active, returns an empty IPEndpoint. 79 // connection is active, returns an empty IPEndpoint.
79 net::IPEndPoint GetPeerIP(); 80 net::IPEndPoint GetPeerIP();
80 81
81 protected: 82 protected:
82 // Implementation of Connect(..). If not in backoff, uses |login_request_| 83 // 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. 84 // Virtual for testing.
86 virtual void ConnectImpl(); 85 virtual void StartConnection();
87 86
88 // Helper method for initalizing the connection hander. 87 // Helper method for initalizing the connection hander.
89 // Virtual for testing. 88 // Virtual for testing.
90 virtual void InitHandler(); 89 virtual void InitHandler();
91 90
92 // Helper method for creating a backoff entry. 91 // Helper method for creating a backoff entry.
93 // Virtual for testing. 92 // Virtual for testing.
94 virtual std::unique_ptr<net::BackoffEntry> CreateBackoffEntry( 93 virtual std::unique_ptr<net::BackoffEntry> CreateBackoffEntry(
95 const net::BackoffEntry::Policy* const policy); 94 const net::BackoffEntry::Policy* const policy);
96 95
97 // Helper method for creating the connection handler. 96 // Helper method for creating the connection handler.
98 // Virtual for testing. 97 // Virtual for testing.
99 virtual std::unique_ptr<ConnectionHandler> CreateConnectionHandler( 98 virtual std::unique_ptr<ConnectionHandler> CreateConnectionHandler(
100 base::TimeDelta read_timeout, 99 base::TimeDelta read_timeout,
101 const ConnectionHandler::ProtoReceivedCallback& read_callback, 100 const ConnectionHandler::ProtoReceivedCallback& read_callback,
102 const ConnectionHandler::ProtoSentCallback& write_callback, 101 const ConnectionHandler::ProtoSentCallback& write_callback,
103 const ConnectionHandler::ConnectionChangedCallback& connection_callback); 102 const ConnectionHandler::ConnectionChangedCallback& connection_callback);
104 103
105 // Returns the current time in Ticks. 104 // Returns the current time in Ticks.
106 // Virtual for testing. 105 // Virtual for testing.
107 virtual base::TimeTicks NowTicks(); 106 virtual base::TimeTicks NowTicks();
108 107
109 // Callback for Socket connection completion. 108 // Callback for Socket connection completion.
110 void OnConnectDone(int result); 109 void OnConnectDone(int result);
111 110
112 // ConnectionHandler callback for connection issues. 111 // ConnectionHandler callback for connection issues.
113 void ConnectionHandlerCallback(int result); 112 void ConnectionHandlerCallback(int result);
114 113
114 // The tracker will maintain a list of all connection attempts with GCM,
115 // whether they suceeded, and their duration.
116 ConnectionEventTracker event_tracker_;
Nicolas Zea 2016/12/01 18:51:49 nit: protected members are kind of discouraged. I
Peter Beverloo 2016/12/02 15:19:13 +1 (our C++ style guide outright forbids this exce
harkness 2016/12/05 15:39:01 Moved it and added a ForTesting accessor.
117
115 private: 118 private:
116 // Helper method for checking backoff and triggering a connection as 119 // Helper method for checking backoff and triggering a connection as
117 // necessary. 120 // necessary.
118 void ConnectWithBackoff(); 121 void ConnectWithBackoff();
119 122
123 // Implementation of Connect(..). If not in backoff, uses |login_request_|
124 // in attempting a connection/handshake. On connection/handshake failure, goes
125 // into backoff.
126 void ConnectImpl();
127
120 // Proxy resolution and connection functions. 128 // Proxy resolution and connection functions.
121 void OnProxyResolveDone(int status); 129 void OnProxyResolveDone(int status);
122 void OnProxyConnectDone(int status); 130 void OnProxyConnectDone(int status);
123 int ReconsiderProxyAfterError(int error); 131 int ReconsiderProxyAfterError(int error);
124 void ReportSuccessfulProxyConnection(); 132 void ReportSuccessfulProxyConnection();
125 133
126 // Closes the local socket if one is present, and resets connection handler. 134 // Closes the local socket if one is present, and resets connection handler.
127 void CloseSocket(); 135 void CloseSocket();
128 136
129 // Updates the GCM Network Session's HttpAuthCache with the HTTP Network 137 // Updates the GCM Network Session's HttpAuthCache with the HTTP Network
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ConnectionListener* listener_; 208 ConnectionListener* listener_;
201 209
202 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_; 210 base::WeakPtrFactory<ConnectionFactoryImpl> weak_ptr_factory_;
203 211
204 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl); 212 DISALLOW_COPY_AND_ASSIGN(ConnectionFactoryImpl);
205 }; 213 };
206 214
207 } // namespace gcm 215 } // namespace gcm
208 216
209 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_ 217 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_FACTORY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698