Chromium Code Reviews| 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.h" | 12 #include "base/metrics/histogram.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 MAX_LOGGED_ACTIVITY_COUNT = 100; |
| 19 const int64 RECEIVED_DATA_MESSAGE_BURST_LENGTH_SECONDS = 2; | |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // 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. |
| 23 // Overflow item is discarded. | 24 // Overflow item is discarded. |
| 24 template <typename T> | 25 template <typename T> |
| 25 T* InsertCircularBuffer(std::deque<T>* q, const T& item) { | 26 T* InsertCircularBuffer(std::deque<T>* q, const T& item) { |
| 26 DCHECK(q); | 27 DCHECK(q); |
| 27 q->push_front(item); | 28 q->push_front(item); |
| 28 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) { | 29 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 } | 356 } |
| 356 | 357 |
| 357 void GCMStatsRecorderImpl::RecordDataMessageReceived( | 358 void GCMStatsRecorderImpl::RecordDataMessageReceived( |
| 358 const std::string& app_id, | 359 const std::string& app_id, |
| 359 const std::string& from, | 360 const std::string& from, |
| 360 int message_byte_size, | 361 int message_byte_size, |
| 361 bool to_registered_app, | 362 bool to_registered_app, |
| 362 ReceivedMessageType message_type) { | 363 ReceivedMessageType message_type) { |
| 363 if (to_registered_app) | 364 if (to_registered_app) |
| 364 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); | 365 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); |
| 366 | |
| 367 base::Time new_timestamp = base::Time::Now(); | |
| 368 if (last_received_data_message_burst_start_time_.is_null()) { | |
| 369 last_received_data_message_burst_start_time_ = new_timestamp; | |
| 370 } else if ((new_timestamp - last_received_data_message_burst_start_time_) >= | |
| 371 base::TimeDelta::FromSeconds( | |
| 372 RECEIVED_DATA_MESSAGE_BURST_LENGTH_SECONDS)) { | |
| 373 UMA_HISTOGRAM_COUNTS( | |
| 374 "GCM.DataMessageBurstReceivedIntervalSeconds", | |
| 375 (new_timestamp - last_received_data_message_burst_start_time_) | |
| 376 .InSeconds()); | |
| 377 last_received_data_message_burst_start_time_ = new_timestamp; | |
| 378 } | |
| 379 | |
| 365 if (!is_recording_) | 380 if (!is_recording_) |
| 366 return; | 381 return; |
| 367 if (!to_registered_app) { | 382 if (!to_registered_app) { |
| 368 RecordReceiving(app_id, from, message_byte_size, "Data msg received", | 383 RecordReceiving(app_id, from, message_byte_size, "Data msg received", |
| 369 to_registered_app ? std::string() : | 384 to_registered_app ? std::string() : |
|
Chirantan Ekbote
2014/07/16 23:49:06
This isn't a part of this patch but don't we alrea
| |
| 370 "No such registered app found"); | 385 "No such registered app found"); |
| 371 } else { | 386 } else { |
| 372 switch(message_type) { | 387 switch(message_type) { |
| 373 case GCMStatsRecorderImpl::DATA_MESSAGE: | 388 case GCMStatsRecorderImpl::DATA_MESSAGE: |
| 374 RecordReceiving(app_id, from, message_byte_size, "Data msg received", | 389 RecordReceiving(app_id, from, message_byte_size, "Data msg received", |
| 375 std::string()); | 390 std::string()); |
| 376 break; | 391 break; |
| 377 case GCMStatsRecorderImpl::DELETED_MESSAGES: | 392 case GCMStatsRecorderImpl::DELETED_MESSAGES: |
| 378 RecordReceiving(app_id, from, message_byte_size, "Data msg received", | 393 RecordReceiving(app_id, from, message_byte_size, "Data msg received", |
| 379 "Message has been deleted on server"); | 394 "Message has been deleted on server"); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 const std::string& receiver_id, | 475 const std::string& receiver_id, |
| 461 const std::string& message_id) { | 476 const std::string& message_id) { |
| 462 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); | 477 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); |
| 463 if (!is_recording_) | 478 if (!is_recording_) |
| 464 return; | 479 return; |
| 465 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", | 480 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", |
| 466 std::string()); | 481 std::string()); |
| 467 } | 482 } |
| 468 | 483 |
| 469 } // namespace gcm | 484 } // namespace gcm |
| OLD | NEW |