| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "components/gcm_driver/gcm_stats_recorder_android.h" | 7 #include "components/gcm_driver/gcm_stats_recorder_android.h" |
| 8 | 8 |
| 9 namespace gcm { | 9 namespace gcm { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const size_t MAX_LOGGED_ACTIVITY_COUNT = 100; | 13 const size_t MAX_LOGGED_ACTIVITY_COUNT = 100; |
| 14 | 14 |
| 15 const char kSuccess[] = "SUCCESS"; | 15 const char kSuccess[] = "SUCCESS"; |
| 16 const char kUnknownError[] = "UNKNOWN_ERROR"; | 16 const char kUnknownError[] = "UNKNOWN_ERROR"; |
| 17 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 GCMStatsRecorderAndroid::GCMStatsRecorderAndroid(Delegate* delegate) | 20 GCMStatsRecorderAndroid::GCMStatsRecorderAndroid(Delegate* delegate) |
| 21 : delegate_(delegate) {} | 21 : delegate_(delegate) {} |
| 22 | 22 |
| 23 GCMStatsRecorderAndroid::~GCMStatsRecorderAndroid() {} | 23 GCMStatsRecorderAndroid::~GCMStatsRecorderAndroid() {} |
| 24 | 24 |
| 25 void GCMStatsRecorderAndroid::Clear() { | 25 void GCMStatsRecorderAndroid::Clear() { |
| 26 registration_activities_.clear(); | 26 registration_activities_.clear(); |
| 27 receiving_activities_.clear(); | 27 receiving_activities_.clear(); |
| 28 decryption_failure_activities_.clear(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void GCMStatsRecorderAndroid::CollectActivities( | 31 void GCMStatsRecorderAndroid::CollectActivities( |
| 31 RecordedActivities* recorded_activities) const { | 32 RecordedActivities* recorded_activities) const { |
| 32 DCHECK(recorded_activities); | 33 DCHECK(recorded_activities); |
| 33 | 34 |
| 34 recorded_activities->registration_activities.insert( | 35 recorded_activities->registration_activities.insert( |
| 35 recorded_activities->registration_activities.begin(), | 36 recorded_activities->registration_activities.begin(), |
| 36 registration_activities_.begin(), | 37 registration_activities_.begin(), |
| 37 registration_activities_.end()); | 38 registration_activities_.end()); |
| 38 recorded_activities->receiving_activities.insert( | 39 recorded_activities->receiving_activities.insert( |
| 39 recorded_activities->receiving_activities.begin(), | 40 recorded_activities->receiving_activities.begin(), |
| 40 receiving_activities_.begin(), | 41 receiving_activities_.begin(), |
| 41 receiving_activities_.end()); | 42 receiving_activities_.end()); |
| 43 recorded_activities->decryption_failure_activities.insert( |
| 44 recorded_activities->decryption_failure_activities.begin(), |
| 45 decryption_failure_activities_.begin(), |
| 46 decryption_failure_activities_.end()); |
| 42 } | 47 } |
| 43 | 48 |
| 44 void GCMStatsRecorderAndroid::RecordRegistrationSent( | 49 void GCMStatsRecorderAndroid::RecordRegistrationSent( |
| 45 const std::string& app_id) { | 50 const std::string& app_id) { |
| 46 if (!is_recording_) | 51 if (!is_recording_) |
| 47 return; | 52 return; |
| 48 | 53 |
| 49 RecordRegistration(app_id, "Registration request sent", "" /* details */); | 54 RecordRegistration(app_id, "Registration request sent", "" /* details */); |
| 50 } | 55 } |
| 51 | 56 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 activity.event = "Data msg received"; | 114 activity.event = "Data msg received"; |
| 110 | 115 |
| 111 receiving_activities_.push_front(activity); | 116 receiving_activities_.push_front(activity); |
| 112 if (receiving_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) | 117 if (receiving_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) |
| 113 receiving_activities_.pop_back(); | 118 receiving_activities_.pop_back(); |
| 114 | 119 |
| 115 if (delegate_) | 120 if (delegate_) |
| 116 delegate_->OnActivityRecorded(); | 121 delegate_->OnActivityRecorded(); |
| 117 } | 122 } |
| 118 | 123 |
| 124 void GCMStatsRecorderAndroid::RecordDecryptionFailure( |
| 125 const std::string& app_id, |
| 126 GCMEncryptionProvider::DecryptionFailure reason) { |
| 127 if (!is_recording_) |
| 128 return; |
| 129 |
| 130 DecryptionFailureActivity activity; |
| 131 activity.app_id = app_id; |
| 132 activity.details = |
| 133 GCMEncryptionProvider::ToDecryptionFailureDetailsString(reason); |
| 134 |
| 135 decryption_failure_activities_.push_front(activity); |
| 136 if (decryption_failure_activities_.size() > MAX_LOGGED_ACTIVITY_COUNT) |
| 137 decryption_failure_activities_.pop_back(); |
| 138 |
| 139 if (delegate_) |
| 140 delegate_->OnActivityRecorded(); |
| 141 } |
| 142 |
| 119 } // namespace gcm | 143 } // namespace gcm |
| OLD | NEW |