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

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: Rebase and address code review comments. 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 187 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();
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 293
290 net::IPEndPoint ip_endpoint; 294 net::IPEndPoint ip_endpoint;
291 int result = socket_handle_.socket()->GetPeerAddress(&ip_endpoint); 295 int result = socket_handle_.socket()->GetPeerAddress(&ip_endpoint);
292 if (result != net::OK) 296 if (result != net::OK)
293 return net::IPEndPoint(); 297 return net::IPEndPoint();
294 298
295 return ip_endpoint; 299 return ip_endpoint;
296 } 300 }
297 301
298 void ConnectionFactoryImpl::ConnectImpl() { 302 void ConnectionFactoryImpl::ConnectImpl() {
303 event_tracker_.StartConnectionAttempt();
304 StartConnection();
305 }
306
307 void ConnectionFactoryImpl::StartConnection() {
299 DCHECK(!IsEndpointReachable()); 308 DCHECK(!IsEndpointReachable());
300 // TODO(zea): Make this a dcheck again. crbug.com/462319 309 // TODO(zea): Make this a dcheck again. crbug.com/462319
301 CHECK(!socket_handle_.socket()); 310 CHECK(!socket_handle_.socket());
302 311
303 // TODO(zea): if the network is offline, don't attempt to connect. 312 // TODO(zea): if the network is offline, don't attempt to connect.
304 // See crbug.com/396687 313 // See crbug.com/396687
305 314
306 connecting_ = true; 315 connecting_ = true;
307 GURL current_endpoint = GetCurrentEndpoint(); 316 GURL current_endpoint = GetCurrentEndpoint();
308 recorder_->RecordConnectionInitiated(current_endpoint.host()); 317 recorder_->RecordConnectionInitiated(current_endpoint.host());
(...skipping 10 matching lines...) Expand all
319 if (status != net::ERR_IO_PENDING) 328 if (status != net::ERR_IO_PENDING)
320 OnProxyResolveDone(status); 329 OnProxyResolveDone(status);
321 } 330 }
322 331
323 void ConnectionFactoryImpl::InitHandler() { 332 void ConnectionFactoryImpl::InitHandler() {
324 // May be null in tests. 333 // May be null in tests.
325 mcs_proto::LoginRequest login_request; 334 mcs_proto::LoginRequest login_request;
326 if (!request_builder_.is_null()) { 335 if (!request_builder_.is_null()) {
327 request_builder_.Run(&login_request); 336 request_builder_.Run(&login_request);
328 DCHECK(login_request.IsInitialized()); 337 DCHECK(login_request.IsInitialized());
338 event_tracker_.WriteToLoginRequest(&login_request);
329 } 339 }
330 340
331 connection_handler_->Init(login_request, socket_handle_.socket()); 341 connection_handler_->Init(login_request, socket_handle_.socket());
332 } 342 }
333 343
334 std::unique_ptr<net::BackoffEntry> ConnectionFactoryImpl::CreateBackoffEntry( 344 std::unique_ptr<net::BackoffEntry> ConnectionFactoryImpl::CreateBackoffEntry(
335 const net::BackoffEntry::Policy* const policy) { 345 const net::BackoffEntry::Policy* const policy) {
336 return std::unique_ptr<net::BackoffEntry>(new net::BackoffEntry(policy)); 346 return std::unique_ptr<net::BackoffEntry>(new net::BackoffEntry(policy));
337 } 347 }
338 348
(...skipping 25 matching lines...) Expand all
364 DCHECK_NE(result, net::OK); 374 DCHECK_NE(result, net::OK);
365 if (result == net::ERR_IO_PENDING) 375 if (result == net::ERR_IO_PENDING)
366 return; // Proxy reconsideration pending. Return. 376 return; // Proxy reconsideration pending. Return.
367 LOG(ERROR) << "Failed to connect to MCS endpoint with error " << result; 377 LOG(ERROR) << "Failed to connect to MCS endpoint with error " << result;
368 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", false); 378 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", false);
369 recorder_->RecordConnectionFailure(result); 379 recorder_->RecordConnectionFailure(result);
370 CloseSocket(); 380 CloseSocket();
371 backoff_entry_->InformOfRequest(false); 381 backoff_entry_->InformOfRequest(false);
372 UMA_HISTOGRAM_SPARSE_SLOWLY("GCM.ConnectionFailureErrorCode", result); 382 UMA_HISTOGRAM_SPARSE_SLOWLY("GCM.ConnectionFailureErrorCode", result);
373 383
384 event_tracker_.ConnectionAttemptFailed(result);
385 event_tracker_.EndConnectionAttempt();
386
374 // If there are other endpoints available, use the next endpoint on the 387 // If there are other endpoints available, use the next endpoint on the
375 // subsequent retry. 388 // subsequent retry.
376 next_endpoint_++; 389 next_endpoint_++;
377 if (next_endpoint_ >= mcs_endpoints_.size()) 390 if (next_endpoint_ >= mcs_endpoints_.size())
378 next_endpoint_ = 0; 391 next_endpoint_ = 0;
379 connecting_ = false; 392 connecting_ = false;
380 Connect(); 393 Connect();
381 return; 394 return;
382 } 395 }
383 396
(...skipping 28 matching lines...) Expand all
412 425
413 // Handshake complete, reset backoff. If the login failed with an error, 426 // Handshake complete, reset backoff. If the login failed with an error,
414 // the client should invoke SignalConnectionReset(LOGIN_FAILURE), which will 427 // the client should invoke SignalConnectionReset(LOGIN_FAILURE), which will
415 // restore the previous backoff. 428 // restore the previous backoff.
416 DVLOG(1) << "Handshake complete."; 429 DVLOG(1) << "Handshake complete.";
417 last_login_time_ = NowTicks(); 430 last_login_time_ = NowTicks();
418 previous_backoff_.swap(backoff_entry_); 431 previous_backoff_.swap(backoff_entry_);
419 backoff_entry_->Reset(); 432 backoff_entry_->Reset();
420 logging_in_ = false; 433 logging_in_ = false;
421 434
435 event_tracker_.ConnectionAttemptSucceeded();
436
422 if (listener_) 437 if (listener_)
423 listener_->OnConnected(GetCurrentEndpoint(), GetPeerIP()); 438 listener_->OnConnected(GetCurrentEndpoint(), GetPeerIP());
424 } 439 }
425 440
426 // This has largely been copied from 441 // This has largely been copied from
427 // HttpStreamFactoryImpl::Job::DoResolveProxyComplete. This should be 442 // HttpStreamFactoryImpl::Job::DoResolveProxyComplete. This should be
428 // refactored into some common place. 443 // refactored into some common place.
429 void ConnectionFactoryImpl::OnProxyResolveDone(int status) { 444 void ConnectionFactoryImpl::OnProxyResolveDone(int status) {
430 pac_request_ = NULL; 445 pac_request_ = NULL;
431 DVLOG(1) << "Proxy resolution status: " << status; 446 DVLOG(1) << "Proxy resolution status: " << status;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 588
574 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { 589 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() {
575 if (!http_network_session_ || !http_network_session_->http_auth_cache()) 590 if (!http_network_session_ || !http_network_session_->http_auth_cache())
576 return; 591 return;
577 592
578 gcm_network_session_->http_auth_cache()->UpdateAllFrom( 593 gcm_network_session_->http_auth_cache()->UpdateAllFrom(
579 *http_network_session_->http_auth_cache()); 594 *http_network_session_->http_auth_cache());
580 } 595 }
581 596
582 } // namespace gcm 597 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698