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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: google_apis/gcm/engine/connection_factory_impl.cc
diff --git a/google_apis/gcm/engine/connection_factory_impl.cc b/google_apis/gcm/engine/connection_factory_impl.cc
index 67dab986357359282be3801f335d061de23c1f9d..e3d054531b23834ba1f31b87ebb1ae991928a3a7 100644
--- a/google_apis/gcm/engine/connection_factory_impl.cc
+++ b/google_apis/gcm/engine/connection_factory_impl.cc
@@ -45,6 +45,8 @@ bool ShouldRestorePreviousBackoff(const base::TimeTicks& login_time,
base::TimeDelta::FromSeconds(kConnectionResetWindowSecs);
}
+const int kMaxClientEvents = 30;
Peter Beverloo 2016/11/28 15:05:15 ++docs. Explain what it is and how this number was
harkness 2016/12/01 10:34:34 Done.
+
} // namespace
ConnectionFactoryImpl::ConnectionFactoryImpl(
@@ -205,6 +207,17 @@ void ConnectionFactoryImpl::SignalConnectionReset(
// connection.
}
+ // Record that the connection has ended.
+ if (logging_in_) {
+ // If this was a login failure, the connection established time would have
+ // been set and it would have marked a successful connection, so explicitly
+ // clear that.
+ current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION);
+ current_event_.clear_time_connection_established_ms();
+ // TODO(harkness): What error code do we want to set?
+ }
+ current_event_.set_time_connection_ended_ms(NowTicks().ToInternalValue());
Peter Beverloo 2016/11/28 15:05:14 Here and elsewhere: I'm not comfortable using ToI
harkness 2016/12/01 10:34:34 Sure, that seems reasonable.
+
CloseSocket();
DCHECK(!IsEndpointReachable());
@@ -260,6 +273,9 @@ base::TimeTicks ConnectionFactoryImpl::NextRetryAttempt() const {
void ConnectionFactoryImpl::OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType type) {
+ // Record the current network type.
+ network_type_ = type;
Peter Beverloo 2016/11/28 15:05:15 Since we only fire OnNetworkChanged() when it actu
harkness 2016/12/01 10:34:34 You're right, that is going to be a problem. I hav
+
if (type == net::NetworkChangeNotifier::CONNECTION_NONE) {
DVLOG(1) << "Network lost, resettion connection.";
waiting_for_network_online_ = true;
@@ -296,6 +312,31 @@ net::IPEndPoint ConnectionFactoryImpl::GetPeerIP() {
}
void ConnectionFactoryImpl::ConnectImpl() {
+ if (total_client_events_ >= 0) {
Peter Beverloo 2016/11/28 15:05:15 Instead of having |total_client_events_|, I think
harkness 2016/12/01 10:34:34 Refactored this into the ClientEventTracker, which
+ // If starting a new connection, the previous connection is completed, so
+ // move
+ // the current client event onto the list of past events.
+ mcs_proto::ClientEvent* client_event = nullptr;
+ if (total_client_events_ < kMaxClientEvents) {
+ client_event = client_events_.Add();
+ } else {
+ // If the maximum number of stored events has been exceeded, start
+ // overwriting older entries.
+ client_event =
+ client_events_.Mutable(total_client_events_ % kMaxClientEvents);
+ }
+ client_event->CopyFrom(current_event_);
+ current_event_.Clear();
Peter Beverloo 2016/11/28 15:05:15 it seems to me like this code would become *a lot*
harkness 2016/12/01 10:34:34 Done.
+ }
+ total_client_events_++;
+
+ current_event_.set_time_connection_started_ms(NowTicks().ToInternalValue());
+ current_event_.set_network_type(network_type_);
+
+ StartConnection();
+}
+
+void ConnectionFactoryImpl::StartConnection() {
DCHECK(!IsEndpointReachable());
// TODO(zea): Make this a dcheck again. crbug.com/462319
CHECK(!socket_handle_.socket());
@@ -324,6 +365,7 @@ void ConnectionFactoryImpl::InitHandler() {
// May be null in tests.
mcs_proto::LoginRequest login_request;
if (!request_builder_.is_null()) {
+ // TODO(harkness): Pass the previous ClientEvents into the request builder.
Peter Beverloo 2016/11/28 15:05:15 This also needs to build a ClientEvent for DISCARD
harkness 2016/12/01 10:34:34 TODO added.
request_builder_.Run(&login_request);
DCHECK(login_request.IsInitialized());
}
@@ -371,6 +413,12 @@ void ConnectionFactoryImpl::OnConnectDone(int result) {
backoff_entry_->InformOfRequest(false);
UMA_HISTOGRAM_SPARSE_SLOWLY("GCM.ConnectionFailureErrorCode", result);
+ // Record the failed connection so information about it can be sent in the
+ // next login request.
+ current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION);
+ current_event_.set_time_connection_ended_ms(NowTicks().ToInternalValue());
+ current_event_.set_error_code(result);
+
// If there are other endpoints available, use the next endpoint on the
// subsequent retry.
next_endpoint_++;
@@ -419,6 +467,18 @@ void ConnectionFactoryImpl::ConnectionHandlerCallback(int result) {
backoff_entry_->Reset();
logging_in_ = false;
+ // Record the successful connection so information about it can be sent in the
+ // next login request. If there is a login failure, this will need to be
+ // updated to a failed connection.
+ current_event_.set_type(mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION);
+ current_event_.set_time_connection_established_ms(
+ NowTicks().ToInternalValue());
+
+ // A completed connection means that the old client event data has now been
+ // sent to GCM. Delete old data and reinitialize the count.
+ client_events_.Clear();
+ total_client_events_ = 0;
+
if (listener_)
listener_->OnConnected(GetCurrentEndpoint(), GetPeerIP());
}

Powered by Google App Engine
This is Rietveld 408576698