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

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

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 #include "google_apis/gcm/engine/connection_factory_impl.h" 5 #include "google_apis/gcm/engine/connection_factory_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 DCHECK(read_callback_.is_null()); 92 DCHECK(read_callback_.is_null());
93 DCHECK(write_callback_.is_null()); 93 DCHECK(write_callback_.is_null());
94 94
95 previous_backoff_ = CreateBackoffEntry(&backoff_policy_); 95 previous_backoff_ = CreateBackoffEntry(&backoff_policy_);
96 backoff_entry_ = CreateBackoffEntry(&backoff_policy_); 96 backoff_entry_ = CreateBackoffEntry(&backoff_policy_);
97 request_builder_ = request_builder; 97 request_builder_ = request_builder;
98 read_callback_ = read_callback; 98 read_callback_ = read_callback;
99 write_callback_ = write_callback; 99 write_callback_ = write_callback;
100 100
101 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 101 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
102 waiting_for_network_online_ = net::NetworkChangeNotifier::IsOffline(); 102 waiting_for_network_online_ = net::NetworkChangeNotifier::IsOffline();
Nicolas Zea 2016/12/01 18:51:49 You probably need to notify the event tracker that
harkness 2016/12/05 15:39:00 Ah! That's exactly the method I needed, and someho
103 } 103 }
104 104
105 ConnectionHandler* ConnectionFactoryImpl::GetConnectionHandler() const { 105 ConnectionHandler* ConnectionFactoryImpl::GetConnectionHandler() const {
106 return connection_handler_.get(); 106 return connection_handler_.get();
107 } 107 }
108 108
109 void ConnectionFactoryImpl::Connect() { 109 void ConnectionFactoryImpl::Connect() {
110 if (!connection_handler_) { 110 if (!connection_handler_) {
111 connection_handler_ = CreateConnectionHandler( 111 connection_handler_ = CreateConnectionHandler(
112 base::TimeDelta::FromMilliseconds(kReadTimeoutMs), read_callback_, 112 base::TimeDelta::FromMilliseconds(kReadTimeoutMs), read_callback_,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (!last_login_time_.is_null()) { 198 if (!last_login_time_.is_null()) {
199 UMA_HISTOGRAM_CUSTOM_TIMES("GCM.ConnectionUpTime", 199 UMA_HISTOGRAM_CUSTOM_TIMES("GCM.ConnectionUpTime",
200 NowTicks() - last_login_time_, 200 NowTicks() - last_login_time_,
201 base::TimeDelta::FromSeconds(1), 201 base::TimeDelta::FromSeconds(1),
202 base::TimeDelta::FromHours(24), 202 base::TimeDelta::FromHours(24),
203 50); 203 50);
204 // |last_login_time_| will be reset below, before attempting the new 204 // |last_login_time_| will be reset below, before attempting the new
205 // connection. 205 // connection.
206 } 206 }
207 207
208 if (logging_in_)
209 event_tracker_.ConnectionLoginFailed();
210 event_tracker_.EndConnectionAttempt();
Peter Beverloo 2016/12/02 15:19:13 It seems to me like you'd want this to live in Con
harkness 2016/12/05 15:39:01 The problem here may be naming. The issue is that
Peter Beverloo 2016/12/05 16:29:34 When a connection attempt fails, the connection it
211
208 CloseSocket(); 212 CloseSocket();
209 DCHECK(!IsEndpointReachable()); 213 DCHECK(!IsEndpointReachable());
210 214
211 // TODO(zea): if the network is offline, don't attempt to connect. 215 // TODO(zea): if the network is offline, don't attempt to connect.
212 // See crbug.com/396687 216 // See crbug.com/396687
213 217
214 // Network changes get special treatment as they can trigger a one-off canary 218 // Network changes get special treatment as they can trigger a one-off canary
215 // request that bypasses backoff (but does nothing if a connection is in 219 // request that bypasses backoff (but does nothing if a connection is in
216 // progress). Other connection reset events can be ignored as a connection 220 // progress). Other connection reset events can be ignored as a connection
217 // is already awaiting backoff expiration. 221 // is already awaiting backoff expiration.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 257 }
254 258
255 base::TimeTicks ConnectionFactoryImpl::NextRetryAttempt() const { 259 base::TimeTicks ConnectionFactoryImpl::NextRetryAttempt() const {
256 if (!backoff_entry_) 260 if (!backoff_entry_)
257 return base::TimeTicks(); 261 return base::TimeTicks();
258 return backoff_entry_->GetReleaseTime(); 262 return backoff_entry_->GetReleaseTime();
259 } 263 }
260 264
261 void ConnectionFactoryImpl::OnNetworkChanged( 265 void ConnectionFactoryImpl::OnNetworkChanged(
262 net::NetworkChangeNotifier::ConnectionType type) { 266 net::NetworkChangeNotifier::ConnectionType type) {
267 // Let the connection tracker know about the network type.
Peter Beverloo 2016/12/02 15:19:13 nit: I'd drop the comment. It's already clear from
harkness 2016/12/05 15:39:00 Removed.
268 event_tracker_.OnNetworkChanged(type);
269
263 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) { 270 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) {
264 DVLOG(1) << "Network lost, resettion connection."; 271 DVLOG(1) << "Network lost, resettion connection.";
265 waiting_for_network_online_ = true; 272 waiting_for_network_online_ = true;
266 273
267 // Will do nothing due to |waiting_for_network_online_ == true|. 274 // Will do nothing due to |waiting_for_network_online_ == true|.
268 // TODO(zea): make the above statement actually true. See crbug.com/396687 275 // TODO(zea): make the above statement actually true. See crbug.com/396687
269 SignalConnectionReset(NETWORK_CHANGE); 276 SignalConnectionReset(NETWORK_CHANGE);
270 return; 277 return;
271 } 278 }
272 279
(...skipping 16 matching lines...) Expand all
289 296
290 net::IPEndPoint ip_endpoint; 297 net::IPEndPoint ip_endpoint;
291 int result = socket_handle_.socket()->GetPeerAddress(&ip_endpoint); 298 int result = socket_handle_.socket()->GetPeerAddress(&ip_endpoint);
292 if (result != net::OK) 299 if (result != net::OK)
293 return net::IPEndPoint(); 300 return net::IPEndPoint();
294 301
295 return ip_endpoint; 302 return ip_endpoint;
296 } 303 }
297 304
298 void ConnectionFactoryImpl::ConnectImpl() { 305 void ConnectionFactoryImpl::ConnectImpl() {
306 event_tracker_.StartConnectionAttempt();
307 StartConnection();
308 }
309
310 void ConnectionFactoryImpl::StartConnection() {
299 DCHECK(!IsEndpointReachable()); 311 DCHECK(!IsEndpointReachable());
300 // TODO(zea): Make this a dcheck again. crbug.com/462319 312 // TODO(zea): Make this a dcheck again. crbug.com/462319
301 CHECK(!socket_handle_.socket()); 313 CHECK(!socket_handle_.socket());
302 314
303 // TODO(zea): if the network is offline, don't attempt to connect. 315 // TODO(zea): if the network is offline, don't attempt to connect.
304 // See crbug.com/396687 316 // See crbug.com/396687
305 317
306 connecting_ = true; 318 connecting_ = true;
307 GURL current_endpoint = GetCurrentEndpoint(); 319 GURL current_endpoint = GetCurrentEndpoint();
308 recorder_->RecordConnectionInitiated(current_endpoint.host()); 320 recorder_->RecordConnectionInitiated(current_endpoint.host());
309 RebuildNetworkSessionAuthCache(); 321 RebuildNetworkSessionAuthCache();
310 int status = gcm_network_session_->proxy_service()->ResolveProxy( 322 int status = gcm_network_session_->proxy_service()->ResolveProxy(
311 current_endpoint, 323 current_endpoint,
312 std::string(), 324 std::string(),
313 &proxy_info_, 325 &proxy_info_,
314 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, 326 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone,
315 weak_ptr_factory_.GetWeakPtr()), 327 weak_ptr_factory_.GetWeakPtr()),
316 &pac_request_, 328 &pac_request_,
317 NULL, 329 NULL,
318 net_log_); 330 net_log_);
319 if (status != net::ERR_IO_PENDING) 331 if (status != net::ERR_IO_PENDING)
320 OnProxyResolveDone(status); 332 OnProxyResolveDone(status);
321 } 333 }
322 334
323 void ConnectionFactoryImpl::InitHandler() { 335 void ConnectionFactoryImpl::InitHandler() {
324 // May be null in tests. 336 // May be null in tests.
325 mcs_proto::LoginRequest login_request; 337 mcs_proto::LoginRequest login_request;
326 if (!request_builder_.is_null()) { 338 if (!request_builder_.is_null()) {
339 event_tracker_.WriteToLoginRequest(&login_request);
Peter Beverloo 2016/12/02 15:19:13 MCSClient::ResetStateAndBuildLoginRequest actually
harkness 2016/12/05 15:39:00 Nice catch! It looks like this isn't caught by the
327 request_builder_.Run(&login_request); 340 request_builder_.Run(&login_request);
328 DCHECK(login_request.IsInitialized()); 341 DCHECK(login_request.IsInitialized());
329 } 342 }
330 343
331 connection_handler_->Init(login_request, socket_handle_.socket()); 344 connection_handler_->Init(login_request, socket_handle_.socket());
332 } 345 }
333 346
334 std::unique_ptr<net::BackoffEntry> ConnectionFactoryImpl::CreateBackoffEntry( 347 std::unique_ptr<net::BackoffEntry> ConnectionFactoryImpl::CreateBackoffEntry(
335 const net::BackoffEntry::Policy* const policy) { 348 const net::BackoffEntry::Policy* const policy) {
336 return std::unique_ptr<net::BackoffEntry>(new net::BackoffEntry(policy)); 349 return std::unique_ptr<net::BackoffEntry>(new net::BackoffEntry(policy));
(...skipping 27 matching lines...) Expand all
364 DCHECK_NE(result, net::OK); 377 DCHECK_NE(result, net::OK);
365 if (result == net::ERR_IO_PENDING) 378 if (result == net::ERR_IO_PENDING)
366 return; // Proxy reconsideration pending. Return. 379 return; // Proxy reconsideration pending. Return.
367 LOG(ERROR) << "Failed to connect to MCS endpoint with error " << result; 380 LOG(ERROR) << "Failed to connect to MCS endpoint with error " << result;
368 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", false); 381 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", false);
369 recorder_->RecordConnectionFailure(result); 382 recorder_->RecordConnectionFailure(result);
370 CloseSocket(); 383 CloseSocket();
371 backoff_entry_->InformOfRequest(false); 384 backoff_entry_->InformOfRequest(false);
372 UMA_HISTOGRAM_SPARSE_SLOWLY("GCM.ConnectionFailureErrorCode", result); 385 UMA_HISTOGRAM_SPARSE_SLOWLY("GCM.ConnectionFailureErrorCode", result);
373 386
387 event_tracker_.ConnectionAttemptFailed(result);
388 event_tracker_.EndConnectionAttempt();
389
374 // If there are other endpoints available, use the next endpoint on the 390 // If there are other endpoints available, use the next endpoint on the
375 // subsequent retry. 391 // subsequent retry.
376 next_endpoint_++; 392 next_endpoint_++;
377 if (next_endpoint_ >= mcs_endpoints_.size()) 393 if (next_endpoint_ >= mcs_endpoints_.size())
378 next_endpoint_ = 0; 394 next_endpoint_ = 0;
379 connecting_ = false; 395 connecting_ = false;
380 Connect(); 396 Connect();
381 return; 397 return;
382 } 398 }
383 399
(...skipping 28 matching lines...) Expand all
412 428
413 // Handshake complete, reset backoff. If the login failed with an error, 429 // Handshake complete, reset backoff. If the login failed with an error,
414 // the client should invoke SignalConnectionReset(LOGIN_FAILURE), which will 430 // the client should invoke SignalConnectionReset(LOGIN_FAILURE), which will
415 // restore the previous backoff. 431 // restore the previous backoff.
416 DVLOG(1) << "Handshake complete."; 432 DVLOG(1) << "Handshake complete.";
417 last_login_time_ = NowTicks(); 433 last_login_time_ = NowTicks();
418 previous_backoff_.swap(backoff_entry_); 434 previous_backoff_.swap(backoff_entry_);
419 backoff_entry_->Reset(); 435 backoff_entry_->Reset();
420 logging_in_ = false; 436 logging_in_ = false;
421 437
438 event_tracker_.ConnectionAttemptSucceeded();
Peter Beverloo 2016/12/02 15:19:13 It seems to me that, logically, this would be a be
harkness 2016/12/05 15:39:01 Actually, I think this placement is correct. The m
Peter Beverloo 2016/12/05 16:29:34 Acknowledged.
439
422 if (listener_) 440 if (listener_)
423 listener_->OnConnected(GetCurrentEndpoint(), GetPeerIP()); 441 listener_->OnConnected(GetCurrentEndpoint(), GetPeerIP());
424 } 442 }
425 443
426 // This has largely been copied from 444 // This has largely been copied from
427 // HttpStreamFactoryImpl::Job::DoResolveProxyComplete. This should be 445 // HttpStreamFactoryImpl::Job::DoResolveProxyComplete. This should be
428 // refactored into some common place. 446 // refactored into some common place.
429 void ConnectionFactoryImpl::OnProxyResolveDone(int status) { 447 void ConnectionFactoryImpl::OnProxyResolveDone(int status) {
430 pac_request_ = NULL; 448 pac_request_ = NULL;
431 DVLOG(1) << "Proxy resolution status: " << status; 449 DVLOG(1) << "Proxy resolution status: " << status;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 591
574 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { 592 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() {
575 if (!http_network_session_ || !http_network_session_->http_auth_cache()) 593 if (!http_network_session_ || !http_network_session_->http_auth_cache())
576 return; 594 return;
577 595
578 gcm_network_session_->http_auth_cache()->UpdateAllFrom( 596 gcm_network_session_->http_auth_cache()->UpdateAllFrom(
579 *http_network_session_->http_auth_cache()); 597 *http_network_session_->http_auth_cache());
580 } 598 }
581 599
582 } // namespace gcm 600 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698