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 #ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
| 6 #define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/time/time.h" |
| 13 #include "google_apis/gcm/base/gcm_export.h" |
| 14 #include "google_apis/gcm/engine/mcs_client.h" |
| 15 |
| 16 namespace gcm { |
| 17 |
| 18 // Records GCM internal stats and activities for debugging purpose. Recording |
| 19 // can be turned on/off by calling SetRecording(...) function. It is turned off |
| 20 // by default. |
| 21 // This class is not thread safe. It is meant to be owned by a gcm client |
| 22 // instance. |
| 23 class GCM_EXPORT GCMStatsRecorder { |
| 24 public: |
| 25 // Contains data that are common to all activity kinds below. |
| 26 struct GCM_EXPORT Activity { |
| 27 Activity(); |
| 28 virtual ~Activity(); |
| 29 |
| 30 base::Time time; |
| 31 std::string event; // A short description of the event. |
| 32 std::string details; // Any additional detail about the event. |
| 33 }; |
| 34 |
| 35 // Contains relevant data of a send-message step. |
| 36 struct GCM_EXPORT SendingActivity : Activity { |
| 37 SendingActivity(); |
| 38 virtual ~SendingActivity(); |
| 39 |
| 40 std::string app_id; |
| 41 std::string receiver_id; |
| 42 std::string message_id; |
| 43 }; |
| 44 |
| 45 GCMStatsRecorder(); |
| 46 virtual ~GCMStatsRecorder(); |
| 47 |
| 48 // Indicates whether the recorder is currently recording activities or not. |
| 49 bool is_recording() const { |
| 50 return is_recording_; |
| 51 } |
| 52 |
| 53 // Turns recording on/off. |
| 54 void SetRecording(bool recording); |
| 55 |
| 56 // Clear all recorded activities. |
| 57 void Clear(); |
| 58 |
| 59 // Records that an outgoing data message was sent over the wire. |
| 60 void RecordDataSentToWire(const std::string& app_id, |
| 61 const std::string& receiver_id, |
| 62 const std::string& message_id, |
| 63 int queued); |
| 64 // Records that the MCS client sent a 'send status' notification to callback. |
| 65 void RecordNotifySendStatus(const std::string& app_id, |
| 66 const std::string& receiver_id, |
| 67 const std::string& message_id, |
| 68 MCSClient::MessageSendStatus status, |
| 69 int byte_size, |
| 70 int ttl); |
| 71 // Records that a 'send error' message was received. |
| 72 void RecordIncomingSendError(const std::string& app_id, |
| 73 const std::string& receiver_id, |
| 74 const std::string& message_id); |
| 75 |
| 76 // Records that a sending activity has occurred. It will be inserted to the |
| 77 // front of a queue ao that entries in the queue had reverse chronological |
| 78 // order. |
| 79 void CollectSendingActivities(std::vector<SendingActivity>* activities) const; |
| 80 |
| 81 const std::deque<SendingActivity>& sending_activities() const { |
| 82 return sending_activities_; |
| 83 } |
| 84 |
| 85 protected: |
| 86 void RecordSending(const std::string& app_id, |
| 87 const std::string& receiver_id, |
| 88 const std::string& message_id, |
| 89 const std::string& event, |
| 90 const std::string& details); |
| 91 |
| 92 bool is_recording_; |
| 93 |
| 94 std::deque<SendingActivity> sending_activities_; |
| 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); |
| 97 }; |
| 98 |
| 99 } // namespace gcm |
| 100 |
| 101 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
OLD | NEW |