Index: google_apis/gcm/engine/connection_event_tracker.cc |
diff --git a/google_apis/gcm/engine/connection_event_tracker.cc b/google_apis/gcm/engine/connection_event_tracker.cc |
index cad77ebd37e1387c8c24e1fadc0d7ca85401beaa..223cafcf0e38c84fbe8c7dc028a33ebaeb2c13bd 100644 |
--- a/google_apis/gcm/engine/connection_event_tracker.cc |
+++ b/google_apis/gcm/engine/connection_event_tracker.cc |
@@ -32,17 +32,22 @@ void ConnectionEventTracker::StartConnectionAttempt() { |
} |
void ConnectionEventTracker::EndConnectionAttempt() { |
- // TODO(harkness): Modify tests so that we can put a DCHECK here. |
Peter Beverloo
2017/01/11 14:31:48
Why isn't the TODO relevant anymore?
|
- if (completed_events_.size() == kMaxClientEvents) { |
- // Don't let the completed events grow beyond the max. |
- completed_events_.pop_front(); |
- number_discarded_events_++; |
+ // It is possible to get EndConnectionAttempt when there is not an in progress |
+ // event, because EndConnectionAttempt is called from SignalConnectionReset, |
+ // which will be called any time the network changes state. Only save the |
+ // current_event_ if it has data. |
+ if (current_event_.has_time_connection_started_ms()) { |
Peter Beverloo
2017/01/11 14:31:48
style nit: prefer early return over nesting.
if
harkness
2017/01/12 11:04:48
No longer applicable.
|
+ if (completed_events_.size() == kMaxClientEvents) { |
+ // Don't let the completed events grow beyond the max. |
+ completed_events_.pop_front(); |
+ number_discarded_events_++; |
+ } |
+ |
+ // Current event is finished, so add it to our list of completed events. |
+ current_event_.set_time_connection_ended_ms(base::Time::Now().ToJavaTime()); |
+ completed_events_.push_back(current_event_); |
+ current_event_.Clear(); |
} |
- |
- // Current event is now completed, so add it to our list of completed events. |
- current_event_.set_time_connection_ended_ms(base::Time::Now().ToJavaTime()); |
- completed_events_.push_back(current_event_); |
- current_event_.Clear(); |
} |
void ConnectionEventTracker::ConnectionAttemptSucceeded() { |