Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "google_apis/gcm/gcm_stats_recorder.h" | |
| 6 | |
| 7 #include <deque> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/strings/string_util.h" | |
| 12 #include "base/strings/stringprintf.h" | |
| 13 | |
| 14 namespace gcm { | |
| 15 | |
| 16 const uint32 MAX_LOGGED_ACTIVITY_COUNT = 100; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 template <typename T> | |
| 21 T* InsertCircularBuffer(std::deque<T>* q, const T& item) { | |
| 22 DCHECK(q); | |
| 23 q->push_front(item); | |
| 24 if (q->size() > MAX_LOGGED_ACTIVITY_COUNT) { | |
| 25 q->pop_back(); | |
| 26 } | |
| 27 return &q->front(); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 GCMStatsRecorder::Activity::Activity() | |
| 33 : time(base::Time::Now()) { | |
| 34 } | |
| 35 | |
| 36 GCMStatsRecorder::Activity::~Activity() { | |
| 37 } | |
| 38 | |
| 39 GCMStatsRecorder::SendingActivity::SendingActivity() { | |
| 40 } | |
| 41 | |
| 42 GCMStatsRecorder::SendingActivity::~SendingActivity() { | |
| 43 } | |
| 44 | |
| 45 GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) { | |
| 46 } | |
| 47 | |
| 48 GCMStatsRecorder::~GCMStatsRecorder() { | |
| 49 } | |
| 50 | |
| 51 void GCMStatsRecorder::SetRecording(bool recording) { | |
| 52 is_recording_ = recording; | |
| 53 } | |
| 54 | |
| 55 void GCMStatsRecorder::Clear() { | |
| 56 sending_activities_.clear(); | |
| 57 } | |
| 58 | |
| 59 void GCMStatsRecorder::RecordSending(const std::string& app_id, | |
| 60 const std::string& receiver_id, | |
| 61 const std::string& message_id, | |
| 62 const std::string& event, | |
| 63 const std::string& details) { | |
| 64 if (!is_recording_) | |
| 65 return; | |
| 66 SendingActivity data; | |
| 67 SendingActivity* inserted_data = InsertCircularBuffer( | |
| 68 &sending_activities_, data); | |
| 69 inserted_data->app_id = app_id; | |
| 70 inserted_data->receiver_id = receiver_id; | |
| 71 inserted_data->message_id = message_id; | |
| 72 inserted_data->event = event; | |
| 73 inserted_data->details = details; | |
| 74 } | |
| 75 | |
| 76 void GCMStatsRecorder::RecordSendingWithUMAEnum( | |
| 77 const std::string& app_id, | |
| 78 const std::string& receiver_id, | |
| 79 const std::string& message_id, | |
| 80 const std::string& event, | |
| 81 const std::string& details, | |
| 82 const std::string& uma_name, | |
| 83 int uma_value, | |
| 84 int uma_value_bound) { | |
| 85 RecordSending(app_id, receiver_id, message_id, event, details); | |
| 86 UMA_HISTOGRAM_ENUMERATION(uma_name, uma_value, uma_value_bound); | |
|
jianli
2014/03/21 18:25:27
It seems to me the only difference among these 3 R
juyik
2014/03/26 04:06:03
According to team consensus, I have changed the cl
| |
| 87 } | |
| 88 | |
| 89 void GCMStatsRecorder::RecordSendingWithUMACounts( | |
| 90 const std::string& app_id, | |
| 91 const std::string& receiver_id, | |
| 92 const std::string& message_id, | |
| 93 const std::string& event, | |
| 94 const std::string& details, | |
| 95 const std::string& uma_name, | |
| 96 int uma_value) { | |
| 97 RecordSending(app_id, receiver_id, message_id, event, details); | |
| 98 UMA_HISTOGRAM_COUNTS(uma_name, uma_value); | |
| 99 } | |
| 100 | |
| 101 } // namespace gcm | |
| OLD | NEW |