Index: components/gcm_driver/gcm_stats_recorder_android.cc |
diff --git a/components/gcm_driver/gcm_stats_recorder_android.cc b/components/gcm_driver/gcm_stats_recorder_android.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..99683de60e52beffe35f50703c120d0abeb7e634 |
--- /dev/null |
+++ b/components/gcm_driver/gcm_stats_recorder_android.cc |
@@ -0,0 +1,113 @@ |
+// Copyright 2015 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 "components/gcm_driver/gcm_stats_recorder_android.h" |
+ |
+#include "base/metrics/histogram_macros.h" |
+ |
+namespace gcm { |
+ |
+const size_t MAX_LOGGED_ACTIVITY_COUNT = 100; |
Nicolas Zea
2015/12/16 22:24:32
nit: put this in an anonymous namespace?
Peter Beverloo
2015/12/17 17:08:24
No need, constants have internal linkage by defaul
|
+ |
+GCMStatsRecorderAndroid::GCMStatsRecorderAndroid(Delegate* delegate) |
+ : delegate_(delegate) {} |
+ |
+GCMStatsRecorderAndroid::~GCMStatsRecorderAndroid() {} |
+ |
+void GCMStatsRecorderAndroid::Clear() { |
+ registration_activities_.clear(); |
+ receiving_activities_.clear(); |
+} |
+ |
+void GCMStatsRecorderAndroid::CollectActivities( |
+ RecordedActivities* recorder_activities) const { |
+ DCHECK(recorder_activities); |
+ |
+ recorder_activities->registration_activities.insert( |
+ recorder_activities->registration_activities.begin(), |
+ registration_activities_.begin(), |
+ registration_activities_.end()); |
+ recorder_activities->receiving_activities.insert( |
+ recorder_activities->receiving_activities.begin(), |
+ receiving_activities_.begin(), |
+ receiving_activities_.end()); |
+} |
+ |
+void GCMStatsRecorderAndroid::RecordRegistrationSent( |
+ const std::string& app_id) { |
+ UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1); |
+ if (!is_recording_) |
+ return; |
+ |
+ RecordRegistration(app_id, "Registration request sent", "" /* details */); |
+} |
+ |
+void GCMStatsRecorderAndroid::RecordRegistrationResponse( |
+ const std::string& app_id, |
+ bool success) { |
+ if (!is_recording_) |
+ return; |
+ |
+ RecordRegistration( |
+ app_id, "Registration response received", success ? "SUCCESS" |
Nicolas Zea
2015/12/16 22:24:32
nit: consider defining these as const char[] in an
Peter Beverloo
2015/12/17 17:08:24
Moved them to constants, but same reply re: the na
|
+ : "UNKNOWN_ERROR"); |
+} |
+ |
+void GCMStatsRecorderAndroid::RecordUnregistrationSent( |
+ const std::string& app_id) { |
+ UMA_HISTOGRAM_COUNTS("GCM.UnregistrationRequest", 1); |
+ if (!is_recording_) |
+ return; |
+ |
+ RecordRegistration(app_id, "Unregistration request sent", "" /* details */); |
+} |
+ |
+void GCMStatsRecorderAndroid::RecordUnregistrationResponse( |
+ const std::string& app_id, |
+ bool success) { |
+ if (!is_recording_) |
+ return; |
+ |
+ RecordRegistration( |
+ app_id, "Unregistration response received", success ? "SUCCESS" |
+ : "UNKNOWN_ERROR"); |
+} |
+ |
+void GCMStatsRecorderAndroid::RecordRegistration(const std::string& app_id, |
+ const std::string& event, |
+ const std::string& details) { |
+ RegistrationActivity activity; |
+ activity.app_id = app_id; |
+ activity.event = event; |
+ activity.details = details; |
+ |
+ // TODO(peter): Include the |source| (sender id(s)) of the registrations. |
+ |
+ registration_activities_.push_front(activity); |
+ if (registration_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) |
+ registration_activities_.pop_back(); |
+ |
+ if (delegate_) |
+ delegate_->OnActivityRecorded(); |
+} |
+ |
+void GCMStatsRecorderAndroid::RecordDataMessageReceived( |
+ const std::string& app_id, |
+ int message_byte_size) { |
+ UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); |
+ |
+ ReceivingActivity activity; |
+ activity.app_id = app_id; |
+ activity.message_byte_size = message_byte_size; |
+ activity.event = "Data msg received"; |
+ |
+ receiving_activities_.push_front(activity); |
+ if (receiving_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) |
+ receiving_activities_.pop_back(); |
+ |
+ if (delegate_) |
+ delegate_->OnActivityRecorded(); |
+} |
+ |
+} // namespace gcm |