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

Unified Diff: google_apis/gcm/engine/connection_event_tracker.cc

Issue 2481873002: Added ClientEvent proto and structure for storing events in the factory. (Closed)
Patch Set: Integrated 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..d1e85b8870eba0160532501a608859df2db82ed2
--- /dev/null
+++ b/google_apis/gcm/engine/connection_event_tracker.cc
@@ -0,0 +1,86 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "google_apis/gcm/engine/connection_event_tracker.h"
+
+#include "base/time/time.h"
+#include "net/base/network_change_notifier.h"
+
+namespace {
+
+// The maxiumum number of events which are stored before deleting old ones.
+// This mirrors the behaviour of the GMS Core connection tracking.
+constexpr size_t kMaxClientEvents = 30;
+
+} // namespace
+
+namespace gcm {
+
+ConnectionEventTracker::ConnectionEventTracker() = default;
+
+ConnectionEventTracker::~ConnectionEventTracker() = default;
+
+void ConnectionEventTracker::StartConnectionAttempt() {
+ // TODO(harkness): Can we dcheck here that there is not an in progress
+ // connection?
+ current_event_.set_time_connection_started_ms(base::Time::Now().ToJavaTime());
+ // The connection type is passed to the server and stored there, so the
+ // values should remain consistent.
+ current_event_.set_network_type(
+ static_cast<int>(net::NetworkChangeNotifier::GetConnectionType()));
+}
+
+void ConnectionEventTracker::EndConnectionAttempt() {
+ // TODO(harkness): Modify tests so that we can put a DCHECK here.
+ if (completed_events_.size() == kMaxClientEvents) {
+ // Don't let the completed events grow beyond the max.
+ completed_events_.pop_front();
+ // TODO(harkness): Keep track of deleted events.
+ }
+
+ // 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() {
+ // 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(
+ base::Time::Now().ToJavaTime());
+
+ // A completed connection means that the old client event data has now been
+ // sent to GCM. Delete old data.
+ completed_events_.clear();
+}
+
+void ConnectionEventTracker::ConnectionLoginFailed() {
+ // A login failure would have originally been marked as a successful
+ // connection, so now that it failed, that needs to be updated.
+ DCHECK_EQ(current_event_.type(),
+ mcs_proto::ClientEvent::SUCCESSFUL_CONNECTION);
+
+ current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION);
+ current_event_.clear_time_connection_established_ms();
+ current_event_.set_error_code(net::ERR_CONNECTION_RESET);
+}
+
+void ConnectionEventTracker::ConnectionAttemptFailed(int error) {
+ DCHECK_NE(error, net::OK);
+
+ current_event_.set_type(mcs_proto::ClientEvent::FAILED_CONNECTION);
+ current_event_.set_error_code(error);
+}
+
+void ConnectionEventTracker::WriteToLoginRequest(
+ mcs_proto::LoginRequest* request) {
+ DCHECK(request);
+ for (const mcs_proto::ClientEvent& event : completed_events_)
+ request->add_client_event()->CopyFrom(event);
+}
+
+} // namespace gcm
« no previous file with comments | « google_apis/gcm/engine/connection_event_tracker.h ('k') | google_apis/gcm/engine/connection_event_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698