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