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 #ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 5 #ifndef GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECODER_H_ |
juyik
2014/06/02 19:19:04
RECODER -> RECORDER
Same below.
jianli
2014/06/02 19:46:30
Done.
| |
6 #define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 6 #define GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECODER_H_ |
7 | 7 |
8 #include <deque> | |
9 #include <string> | 8 #include <string> |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
13 #include "google_apis/gcm/base/gcm_export.h" | 12 #include "google_apis/gcm/base/gcm_export.h" |
14 #include "google_apis/gcm/engine/connection_factory.h" | 13 #include "google_apis/gcm/engine/connection_factory.h" |
15 #include "google_apis/gcm/engine/mcs_client.h" | 14 #include "google_apis/gcm/engine/mcs_client.h" |
16 #include "google_apis/gcm/engine/registration_request.h" | 15 #include "google_apis/gcm/engine/registration_request.h" |
17 #include "google_apis/gcm/engine/unregistration_request.h" | 16 #include "google_apis/gcm/engine/unregistration_request.h" |
18 #include "google_apis/gcm/gcm_activity.h" | |
19 | 17 |
20 namespace gcm { | 18 namespace gcm { |
21 | 19 |
22 // Records GCM internal stats and activities for debugging purpose. Recording | 20 // Defines the interface to record GCM internal stats and activities for |
23 // can be turned on/off by calling SetRecording(...) function. It is turned off | 21 // debugging purpose. |
24 // by default. | |
25 // This class is not thread safe. It is meant to be owned by a gcm client | |
26 // instance. | |
27 class GCM_EXPORT GCMStatsRecorder { | 22 class GCM_EXPORT GCMStatsRecorder { |
28 public: | 23 public: |
29 // Type of a received message | 24 // Type of a received message |
30 enum ReceivedMessageType { | 25 enum ReceivedMessageType { |
31 // Data message. | 26 // Data message. |
32 DATA_MESSAGE, | 27 DATA_MESSAGE, |
33 // Message that indicates some messages have been deleted on the server. | 28 // Message that indicates some messages have been deleted on the server. |
34 DELETED_MESSAGES, | 29 DELETED_MESSAGES, |
35 }; | 30 }; |
36 | 31 |
37 // A delegate interface that allows the GCMStatsRecorder instance to interact | 32 GCMStatsRecorder() {} |
38 // with its container. | 33 virtual ~GCMStatsRecorder() {} |
39 class Delegate { | |
40 public: | |
41 // Called when the GCMStatsRecorder is recording activities and a new | |
42 // activity has just been recorded. | |
43 virtual void OnActivityRecorded() = 0; | |
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 // Set a delegate to receive callback from the recorder. | |
58 void SetDelegate(Delegate* delegate); | |
59 | |
60 // Clear all recorded activities. | |
61 void Clear(); | |
62 | |
63 // All RecordXXXX methods below will record one activity. It will be inserted | |
64 // to the front of a queue so that entries in the queue had reverse | |
65 // chronological order. | |
66 | 34 |
67 // Records that a check-in has been initiated. | 35 // Records that a check-in has been initiated. |
68 void RecordCheckinInitiated(uint64 android_id); | 36 virtual void RecordCheckinInitiated(uint64 android_id) = 0; |
69 | 37 |
70 // Records that a check-in has been delayed due to backoff. | 38 // Records that a check-in has been delayed due to backoff. |
71 void RecordCheckinDelayedDueToBackoff(int64 delay_msec); | 39 virtual void RecordCheckinDelayedDueToBackoff(int64 delay_msec) = 0; |
72 | 40 |
73 // Records that a check-in request has succeeded. | 41 // Records that a check-in request has succeeded. |
74 void RecordCheckinSuccess(); | 42 virtual void RecordCheckinSuccess() = 0; |
75 | 43 |
76 // Records that a check-in request has failed. If a retry will be tempted then | 44 // Records that a check-in request has failed. If a retry will be tempted then |
77 // will_retry should be true. | 45 // will_retry should be true. |
78 void RecordCheckinFailure(std::string status, bool will_retry); | 46 virtual void RecordCheckinFailure(std::string status, bool will_retry) = 0; |
79 | 47 |
80 // Records that a connection to MCS has been initiated. | 48 // Records that a connection to MCS has been initiated. |
81 void RecordConnectionInitiated(const std::string& host); | 49 virtual void RecordConnectionInitiated(const std::string& host) = 0; |
82 | 50 |
83 // Records that a connection has been delayed due to backoff. | 51 // Records that a connection has been delayed due to backoff. |
84 void RecordConnectionDelayedDueToBackoff(int64 delay_msec); | 52 virtual void RecordConnectionDelayedDueToBackoff(int64 delay_msec) = 0; |
85 | 53 |
86 // Records that connection has been successfully established. | 54 // Records that connection has been successfully established. |
87 void RecordConnectionSuccess(); | 55 virtual void RecordConnectionSuccess() = 0; |
88 | 56 |
89 // Records that connection has failed with a network error code. | 57 // Records that connection has failed with a network error code. |
90 void RecordConnectionFailure(int network_error); | 58 virtual void RecordConnectionFailure(int network_error) = 0; |
91 | 59 |
92 // Records that connection reset has been signaled. | 60 // Records that connection reset has been signaled. |
93 void RecordConnectionResetSignaled( | 61 virtual void RecordConnectionResetSignaled( |
94 ConnectionFactory::ConnectionResetReason reason); | 62 ConnectionFactory::ConnectionResetReason reason) = 0; |
95 | 63 |
96 // Records that a registration request has been sent. This could be initiated | 64 // Records that a registration request has been sent. This could be initiated |
97 // directly from API, or from retry logic. | 65 // directly from API, or from retry logic. |
98 void RecordRegistrationSent(const std::string& app_id, | 66 virtual void RecordRegistrationSent(const std::string& app_id, |
99 const std::string& sender_ids); | 67 const std::string& sender_ids) = 0; |
100 | 68 |
101 // Records that a registration response has been received from server. | 69 // Records that a registration response has been received from server. |
102 void RecordRegistrationResponse(const std::string& app_id, | 70 virtual void RecordRegistrationResponse( |
103 const std::vector<std::string>& sender_ids, | 71 const std::string& app_id, |
104 RegistrationRequest::Status status); | 72 const std::vector<std::string>& sender_ids, |
73 RegistrationRequest::Status status) = 0; | |
105 | 74 |
106 // Records that a registration retry has been requested. The actual retry | 75 // Records that a registration retry has been requested. The actual retry |
107 // action may not occur until some time later according to backoff logic. | 76 // action may not occur until some time later according to backoff logic. |
108 void RecordRegistrationRetryRequested( | 77 virtual void RecordRegistrationRetryRequested( |
109 const std::string& app_id, | 78 const std::string& app_id, |
110 const std::vector<std::string>& sender_ids, | 79 const std::vector<std::string>& sender_ids, |
111 int retries_left); | 80 int retries_left) = 0; |
112 | 81 |
113 // Records that an unregistration request has been sent. This could be | 82 // Records that an unregistration request has been sent. This could be |
114 // initiated directly from API, or from retry logic. | 83 // initiated directly from API, or from retry logic. |
115 void RecordUnregistrationSent(const std::string& app_id); | 84 virtual void RecordUnregistrationSent(const std::string& app_id) = 0; |
116 | 85 |
117 // Records that an unregistration response has been received from server. | 86 // Records that an unregistration response has been received from server. |
118 void RecordUnregistrationResponse(const std::string& app_id, | 87 virtual void RecordUnregistrationResponse( |
119 UnregistrationRequest::Status status); | 88 const std::string& app_id, |
89 UnregistrationRequest::Status status) = 0; | |
120 | 90 |
121 // Records that an unregistration retry has been requested and delayed due to | 91 // Records that an unregistration retry has been requested and delayed due to |
122 // backoff logic. | 92 // backoff logic. |
123 void RecordUnregistrationRetryDelayed(const std::string& app_id, | 93 virtual void RecordUnregistrationRetryDelayed(const std::string& app_id, |
124 int64 delay_msec); | 94 int64 delay_msec) = 0; |
125 | 95 |
126 // Records that a data message has been received. If this message is not | 96 // Records that a data message has been received. If this message is not |
127 // sent to a registered app, to_registered_app shoudl be false. If it | 97 // sent to a registered app, to_registered_app shoudl be false. If it |
128 // indicates that a message has been dropped on the server, is_message_dropped | 98 // indicates that a message has been dropped on the server, is_message_dropped |
129 // should be true. | 99 // should be true. |
130 void RecordDataMessageReceived(const std::string& app_id, | 100 virtual void RecordDataMessageReceived(const std::string& app_id, |
131 const std::string& from, | 101 const std::string& from, |
132 int message_byte_size, | 102 int message_byte_size, |
133 bool to_registered_app, | 103 bool to_registered_app, |
134 ReceivedMessageType message_type); | 104 ReceivedMessageType message_type) = 0; |
135 | 105 |
136 // Records that an outgoing data message was sent over the wire. | 106 // Records that an outgoing data message was sent over the wire. |
137 void RecordDataSentToWire(const std::string& app_id, | 107 virtual void RecordDataSentToWire(const std::string& app_id, |
138 const std::string& receiver_id, | 108 const std::string& receiver_id, |
139 const std::string& message_id, | 109 const std::string& message_id, |
140 int queued); | 110 int queued) = 0; |
141 // Records that the MCS client sent a 'send status' notification to callback. | 111 // Records that the MCS client sent a 'send status' notification to callback. |
142 void RecordNotifySendStatus(const std::string& app_id, | 112 virtual void RecordNotifySendStatus(const std::string& app_id, |
143 const std::string& receiver_id, | 113 const std::string& receiver_id, |
144 const std::string& message_id, | 114 const std::string& message_id, |
145 MCSClient::MessageSendStatus status, | 115 MCSClient::MessageSendStatus status, |
146 int byte_size, | 116 int byte_size, |
147 int ttl); | 117 int ttl) = 0; |
148 // Records that a 'send error' message was received. | 118 // Records that a 'send error' message was received. |
149 void RecordIncomingSendError(const std::string& app_id, | 119 virtual void RecordIncomingSendError(const std::string& app_id, |
150 const std::string& receiver_id, | 120 const std::string& receiver_id, |
151 const std::string& message_id); | 121 const std::string& message_id) = 0; |
152 | |
153 // Collect all recorded activities into the struct. | |
154 void CollectActivities(RecordedActivities* recorder_activities) const; | |
155 | |
156 const std::deque<CheckinActivity>& checkin_activities() const { | |
157 return checkin_activities_; | |
158 } | |
159 const std::deque<ConnectionActivity>& connection_activities() const { | |
160 return connection_activities_; | |
161 } | |
162 const std::deque<RegistrationActivity>& registration_activities() const { | |
163 return registration_activities_; | |
164 } | |
165 const std::deque<ReceivingActivity>& receiving_activities() const { | |
166 return receiving_activities_; | |
167 } | |
168 const std::deque<SendingActivity>& sending_activities() const { | |
169 return sending_activities_; | |
170 } | |
171 | |
172 protected: | |
173 // Notify the recorder delegate, if it exists, that an activity has been | |
174 // recorded. | |
175 void NotifyActivityRecorded(); | |
176 | |
177 void RecordCheckin(const std::string& event, | |
178 const std::string& details); | |
179 | |
180 void RecordConnection(const std::string& event, | |
181 const std::string& details); | |
182 | |
183 void RecordRegistration(const std::string& app_id, | |
184 const std::string& sender_id, | |
185 const std::string& event, | |
186 const std::string& details); | |
187 | |
188 void RecordReceiving(const std::string& app_id, | |
189 const std::string& from, | |
190 int message_byte_size, | |
191 const std::string& event, | |
192 const std::string& details); | |
193 | |
194 void RecordSending(const std::string& app_id, | |
195 const std::string& receiver_id, | |
196 const std::string& message_id, | |
197 const std::string& event, | |
198 const std::string& details); | |
199 | |
200 bool is_recording_; | |
201 Delegate* delegate_; | |
202 | |
203 std::deque<CheckinActivity> checkin_activities_; | |
204 std::deque<ConnectionActivity> connection_activities_; | |
205 std::deque<RegistrationActivity> registration_activities_; | |
206 std::deque<ReceivingActivity> receiving_activities_; | |
207 std::deque<SendingActivity> sending_activities_; | |
208 | |
209 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); | |
210 }; | 122 }; |
211 | 123 |
212 } // namespace gcm | 124 } // namespace gcm |
213 | 125 |
214 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 126 #endif // GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECODER_H_ |
OLD | NEW |