OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/gcm_driver/gcm_stats_recorder_android.h" |
| 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 8 |
| 9 namespace gcm { |
| 10 |
| 11 const size_t MAX_LOGGED_ACTIVITY_COUNT = 100; |
| 12 |
| 13 const char kSuccess[] = "SUCCESS"; |
| 14 const char kUnknownError[] = "UNKNOWN_ERROR"; |
| 15 |
| 16 GCMStatsRecorderAndroid::GCMStatsRecorderAndroid(Delegate* delegate) |
| 17 : delegate_(delegate) {} |
| 18 |
| 19 GCMStatsRecorderAndroid::~GCMStatsRecorderAndroid() {} |
| 20 |
| 21 void GCMStatsRecorderAndroid::Clear() { |
| 22 registration_activities_.clear(); |
| 23 receiving_activities_.clear(); |
| 24 } |
| 25 |
| 26 void GCMStatsRecorderAndroid::CollectActivities( |
| 27 RecordedActivities* recorder_activities) const { |
| 28 DCHECK(recorder_activities); |
| 29 |
| 30 recorder_activities->registration_activities.insert( |
| 31 recorder_activities->registration_activities.begin(), |
| 32 registration_activities_.begin(), |
| 33 registration_activities_.end()); |
| 34 recorder_activities->receiving_activities.insert( |
| 35 recorder_activities->receiving_activities.begin(), |
| 36 receiving_activities_.begin(), |
| 37 receiving_activities_.end()); |
| 38 } |
| 39 |
| 40 void GCMStatsRecorderAndroid::RecordRegistrationSent( |
| 41 const std::string& app_id) { |
| 42 UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1); |
| 43 if (!is_recording_) |
| 44 return; |
| 45 |
| 46 RecordRegistration(app_id, "Registration request sent", "" /* details */); |
| 47 } |
| 48 |
| 49 void GCMStatsRecorderAndroid::RecordRegistrationResponse( |
| 50 const std::string& app_id, |
| 51 bool success) { |
| 52 if (!is_recording_) |
| 53 return; |
| 54 |
| 55 RecordRegistration( |
| 56 app_id, "Registration response received", success ? kSuccess |
| 57 : kUnknownError); |
| 58 } |
| 59 |
| 60 void GCMStatsRecorderAndroid::RecordUnregistrationSent( |
| 61 const std::string& app_id) { |
| 62 UMA_HISTOGRAM_COUNTS("GCM.UnregistrationRequest", 1); |
| 63 if (!is_recording_) |
| 64 return; |
| 65 |
| 66 RecordRegistration(app_id, "Unregistration request sent", "" /* details */); |
| 67 } |
| 68 |
| 69 void GCMStatsRecorderAndroid::RecordUnregistrationResponse( |
| 70 const std::string& app_id, |
| 71 bool success) { |
| 72 if (!is_recording_) |
| 73 return; |
| 74 |
| 75 RecordRegistration( |
| 76 app_id, "Unregistration response received", success ? kSuccess |
| 77 : kUnknownError); |
| 78 } |
| 79 |
| 80 void GCMStatsRecorderAndroid::RecordRegistration(const std::string& app_id, |
| 81 const std::string& event, |
| 82 const std::string& details) { |
| 83 RegistrationActivity activity; |
| 84 activity.app_id = app_id; |
| 85 activity.event = event; |
| 86 activity.details = details; |
| 87 |
| 88 // TODO(peter): Include the |source| (sender id(s)) of the registrations. |
| 89 |
| 90 registration_activities_.push_front(activity); |
| 91 if (registration_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) |
| 92 registration_activities_.pop_back(); |
| 93 |
| 94 if (delegate_) |
| 95 delegate_->OnActivityRecorded(); |
| 96 } |
| 97 |
| 98 void GCMStatsRecorderAndroid::RecordDataMessageReceived( |
| 99 const std::string& app_id, |
| 100 int message_byte_size) { |
| 101 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); |
| 102 |
| 103 ReceivingActivity activity; |
| 104 activity.app_id = app_id; |
| 105 activity.message_byte_size = message_byte_size; |
| 106 activity.event = "Data msg received"; |
| 107 |
| 108 receiving_activities_.push_front(activity); |
| 109 if (receiving_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) |
| 110 receiving_activities_.pop_back(); |
| 111 |
| 112 if (delegate_) |
| 113 delegate_->OnActivityRecorded(); |
| 114 } |
| 115 |
| 116 } // namespace gcm |
OLD | NEW |