| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/gcm_driver/gcm_stats_recorder_impl.h" | 5 #include "components/gcm_driver/gcm_stats_recorder_impl.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 | 15 |
| 16 namespace gcm { | 16 namespace gcm { |
| 17 | 17 |
| 18 const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100; | 18 const uint32_t MAX_LOGGED_ACTIVITY_COUNT = 100; |
| 19 const int64 RECEIVED_DATA_MESSAGE_BURST_LENGTH_SECONDS = 2; | 19 const int64_t RECEIVED_DATA_MESSAGE_BURST_LENGTH_SECONDS = 2; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Insert an item to the front of deque while maintaining the size of the deque. | 23 // Insert an item to the front of deque while maintaining the size of the deque. |
| 24 // Overflow item is discarded. | 24 // Overflow item is discarded. |
| 25 template <typename T> | 25 template <typename T> |
| 26 T* InsertCircularBuffer(std::deque<T>* q, const T& item) { | 26 T* InsertCircularBuffer(std::deque<T>* q, const T& item) { |
| 27 DCHECK(q); | 27 DCHECK(q); |
| 28 q->push_front(item); | 28 q->push_front(item); |
| 29 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) { | 29 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 const std::string& event, | 174 const std::string& event, |
| 175 const std::string& details) { | 175 const std::string& details) { |
| 176 CheckinActivity data; | 176 CheckinActivity data; |
| 177 CheckinActivity* inserted_data = InsertCircularBuffer( | 177 CheckinActivity* inserted_data = InsertCircularBuffer( |
| 178 &checkin_activities_, data); | 178 &checkin_activities_, data); |
| 179 inserted_data->event = event; | 179 inserted_data->event = event; |
| 180 inserted_data->details = details; | 180 inserted_data->details = details; |
| 181 NotifyActivityRecorded(); | 181 NotifyActivityRecorded(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void GCMStatsRecorderImpl::RecordCheckinInitiated(uint64 android_id) { | 184 void GCMStatsRecorderImpl::RecordCheckinInitiated(uint64_t android_id) { |
| 185 if (!is_recording_) | 185 if (!is_recording_) |
| 186 return; | 186 return; |
| 187 RecordCheckin("Checkin initiated", | 187 RecordCheckin("Checkin initiated", |
| 188 base::StringPrintf("Android Id: %" PRIu64, android_id)); | 188 base::StringPrintf("Android Id: %" PRIu64, android_id)); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void GCMStatsRecorderImpl::RecordCheckinDelayedDueToBackoff(int64 delay_msec) { | 191 void GCMStatsRecorderImpl::RecordCheckinDelayedDueToBackoff( |
| 192 int64_t delay_msec) { |
| 192 if (!is_recording_) | 193 if (!is_recording_) |
| 193 return; | 194 return; |
| 194 RecordCheckin("Checkin backoff", | 195 RecordCheckin("Checkin backoff", |
| 195 base::StringPrintf("Delayed for %" PRId64 " msec", | 196 base::StringPrintf("Delayed for %" PRId64 " msec", |
| 196 delay_msec)); | 197 delay_msec)); |
| 197 } | 198 } |
| 198 | 199 |
| 199 void GCMStatsRecorderImpl::RecordCheckinSuccess() { | 200 void GCMStatsRecorderImpl::RecordCheckinSuccess() { |
| 200 if (!is_recording_) | 201 if (!is_recording_) |
| 201 return; | 202 return; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 226 void GCMStatsRecorderImpl::RecordConnectionInitiated(const std::string& host) { | 227 void GCMStatsRecorderImpl::RecordConnectionInitiated(const std::string& host) { |
| 227 last_connection_initiation_time_ = base::TimeTicks::Now(); | 228 last_connection_initiation_time_ = base::TimeTicks::Now(); |
| 228 last_connection_success_time_ = base::TimeTicks(); | 229 last_connection_success_time_ = base::TimeTicks(); |
| 229 data_message_received_since_connected_ = false; | 230 data_message_received_since_connected_ = false; |
| 230 if (!is_recording_) | 231 if (!is_recording_) |
| 231 return; | 232 return; |
| 232 RecordConnection("Connection initiated", host); | 233 RecordConnection("Connection initiated", host); |
| 233 } | 234 } |
| 234 | 235 |
| 235 void GCMStatsRecorderImpl::RecordConnectionDelayedDueToBackoff( | 236 void GCMStatsRecorderImpl::RecordConnectionDelayedDueToBackoff( |
| 236 int64 delay_msec) { | 237 int64_t delay_msec) { |
| 237 if (!is_recording_) | 238 if (!is_recording_) |
| 238 return; | 239 return; |
| 239 RecordConnection("Connection backoff", | 240 RecordConnection("Connection backoff", |
| 240 base::StringPrintf("Delayed for %" PRId64 " msec", | 241 base::StringPrintf("Delayed for %" PRId64 " msec", |
| 241 delay_msec)); | 242 delay_msec)); |
| 242 } | 243 } |
| 243 | 244 |
| 244 void GCMStatsRecorderImpl::RecordConnectionSuccess() { | 245 void GCMStatsRecorderImpl::RecordConnectionSuccess() { |
| 245 DCHECK(!last_connection_initiation_time_.is_null()); | 246 DCHECK(!last_connection_initiation_time_.is_null()); |
| 246 UMA_HISTOGRAM_MEDIUM_TIMES( | 247 UMA_HISTOGRAM_MEDIUM_TIMES( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 if (!is_recording_) | 301 if (!is_recording_) |
| 301 return; | 302 return; |
| 302 RecordRegistration(app_id, source, | 303 RecordRegistration(app_id, source, |
| 303 "Registration response received", | 304 "Registration response received", |
| 304 GetRegistrationStatusString(status)); | 305 GetRegistrationStatusString(status)); |
| 305 } | 306 } |
| 306 | 307 |
| 307 void GCMStatsRecorderImpl::RecordRegistrationRetryDelayed( | 308 void GCMStatsRecorderImpl::RecordRegistrationRetryDelayed( |
| 308 const std::string& app_id, | 309 const std::string& app_id, |
| 309 const std::string& source, | 310 const std::string& source, |
| 310 int64 delay_msec, | 311 int64_t delay_msec, |
| 311 int retries_left) { | 312 int retries_left) { |
| 312 if (!is_recording_) | 313 if (!is_recording_) |
| 313 return; | 314 return; |
| 314 RecordRegistration( | 315 RecordRegistration( |
| 315 app_id, | 316 app_id, |
| 316 source, | 317 source, |
| 317 "Registration retry delayed", | 318 "Registration retry delayed", |
| 318 base::StringPrintf("Delayed for %" PRId64 " msec, retries left: %d", | 319 base::StringPrintf("Delayed for %" PRId64 " msec, retries left: %d", |
| 319 delay_msec, | 320 delay_msec, |
| 320 retries_left)); | 321 retries_left)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 337 return; | 338 return; |
| 338 RecordRegistration(app_id, | 339 RecordRegistration(app_id, |
| 339 source, | 340 source, |
| 340 "Unregistration response received", | 341 "Unregistration response received", |
| 341 GetUnregistrationStatusString(status)); | 342 GetUnregistrationStatusString(status)); |
| 342 } | 343 } |
| 343 | 344 |
| 344 void GCMStatsRecorderImpl::RecordUnregistrationRetryDelayed( | 345 void GCMStatsRecorderImpl::RecordUnregistrationRetryDelayed( |
| 345 const std::string& app_id, | 346 const std::string& app_id, |
| 346 const std::string& source, | 347 const std::string& source, |
| 347 int64 delay_msec, | 348 int64_t delay_msec, |
| 348 int retries_left) { | 349 int retries_left) { |
| 349 if (!is_recording_) | 350 if (!is_recording_) |
| 350 return; | 351 return; |
| 351 RecordRegistration( | 352 RecordRegistration( |
| 352 app_id, | 353 app_id, |
| 353 source, | 354 source, |
| 354 "Unregistration retry delayed", | 355 "Unregistration retry delayed", |
| 355 base::StringPrintf("Delayed for %" PRId64 " msec, retries left: %d", | 356 base::StringPrintf("Delayed for %" PRId64 " msec, retries left: %d", |
| 356 delay_msec, | 357 delay_msec, |
| 357 retries_left)); | 358 retries_left)); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 const std::string& receiver_id, | 514 const std::string& receiver_id, |
| 514 const std::string& message_id) { | 515 const std::string& message_id) { |
| 515 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); | 516 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); |
| 516 if (!is_recording_) | 517 if (!is_recording_) |
| 517 return; | 518 return; |
| 518 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", | 519 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", |
| 519 std::string()); | 520 std::string()); |
| 520 } | 521 } |
| 521 | 522 |
| 522 } // namespace gcm | 523 } // namespace gcm |
| OLD | NEW |