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 "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 5 #include "google_apis/gcm/monitoring/gcm_stats_recorder.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" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 GCMStatsRecorder::SendingActivity::~SendingActivity() { | 178 GCMStatsRecorder::SendingActivity::~SendingActivity() { |
179 } | 179 } |
180 | 180 |
181 GCMStatsRecorder::RecordedActivities::RecordedActivities() { | 181 GCMStatsRecorder::RecordedActivities::RecordedActivities() { |
182 } | 182 } |
183 | 183 |
184 GCMStatsRecorder::RecordedActivities::~RecordedActivities() { | 184 GCMStatsRecorder::RecordedActivities::~RecordedActivities() { |
185 } | 185 } |
186 | 186 |
187 GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false) { | 187 GCMStatsRecorder::GCMStatsRecorder() : is_recording_(false), delegate_(NULL) { |
188 } | 188 } |
189 | 189 |
190 GCMStatsRecorder::~GCMStatsRecorder() { | 190 GCMStatsRecorder::~GCMStatsRecorder() { |
191 } | 191 } |
192 | 192 |
193 void GCMStatsRecorder::SetRecording(bool recording) { | 193 void GCMStatsRecorder::SetRecording(bool recording) { |
194 is_recording_ = recording; | 194 is_recording_ = recording; |
195 } | 195 } |
196 | 196 |
| 197 void GCMStatsRecorder::SetDelegate(Delegate* delegate) { |
| 198 delegate_ = delegate; |
| 199 } |
| 200 |
197 void GCMStatsRecorder::Clear() { | 201 void GCMStatsRecorder::Clear() { |
198 checkin_activities_.clear(); | 202 checkin_activities_.clear(); |
199 connection_activities_.clear(); | 203 connection_activities_.clear(); |
200 registration_activities_.clear(); | 204 registration_activities_.clear(); |
201 receiving_activities_.clear(); | 205 receiving_activities_.clear(); |
202 sending_activities_.clear(); | 206 sending_activities_.clear(); |
203 } | 207 } |
204 | 208 |
| 209 void GCMStatsRecorder::NotifyActivityRecorded() { |
| 210 if (delegate_) |
| 211 delegate_->OnActivityRecorded(); |
| 212 } |
| 213 |
205 void GCMStatsRecorder::RecordCheckin( | 214 void GCMStatsRecorder::RecordCheckin( |
206 const std::string& event, | 215 const std::string& event, |
207 const std::string& details) { | 216 const std::string& details) { |
208 CheckinActivity data; | 217 CheckinActivity data; |
209 CheckinActivity* inserted_data = InsertCircularBuffer( | 218 CheckinActivity* inserted_data = InsertCircularBuffer( |
210 &checkin_activities_, data); | 219 &checkin_activities_, data); |
211 inserted_data->event = event; | 220 inserted_data->event = event; |
212 inserted_data->details = details; | 221 inserted_data->details = details; |
| 222 NotifyActivityRecorded(); |
213 } | 223 } |
214 | 224 |
215 void GCMStatsRecorder::RecordCheckinInitiated(uint64 android_id) { | 225 void GCMStatsRecorder::RecordCheckinInitiated(uint64 android_id) { |
216 if (!is_recording_) | 226 if (!is_recording_) |
217 return; | 227 return; |
218 RecordCheckin("Checkin initiated", | 228 RecordCheckin("Checkin initiated", |
219 base::StringPrintf("Android Id: %" PRIu64, android_id)); | 229 base::StringPrintf("Android Id: %" PRIu64, android_id)); |
220 } | 230 } |
221 | 231 |
222 void GCMStatsRecorder::RecordCheckinDelayedDueToBackoff(int64 delay_msec) { | 232 void GCMStatsRecorder::RecordCheckinDelayedDueToBackoff(int64 delay_msec) { |
(...skipping 21 matching lines...) Expand all Loading... |
244 } | 254 } |
245 | 255 |
246 void GCMStatsRecorder::RecordConnection( | 256 void GCMStatsRecorder::RecordConnection( |
247 const std::string& event, | 257 const std::string& event, |
248 const std::string& details) { | 258 const std::string& details) { |
249 ConnectionActivity data; | 259 ConnectionActivity data; |
250 ConnectionActivity* inserted_data = InsertCircularBuffer( | 260 ConnectionActivity* inserted_data = InsertCircularBuffer( |
251 &connection_activities_, data); | 261 &connection_activities_, data); |
252 inserted_data->event = event; | 262 inserted_data->event = event; |
253 inserted_data->details = details; | 263 inserted_data->details = details; |
| 264 NotifyActivityRecorded(); |
254 } | 265 } |
255 | 266 |
256 void GCMStatsRecorder::RecordConnectionInitiated(const std::string& host) { | 267 void GCMStatsRecorder::RecordConnectionInitiated(const std::string& host) { |
257 if (!is_recording_) | 268 if (!is_recording_) |
258 return; | 269 return; |
259 RecordConnection("Connection initiated", host); | 270 RecordConnection("Connection initiated", host); |
260 } | 271 } |
261 | 272 |
262 void GCMStatsRecorder::RecordConnectionDelayedDueToBackoff(int64 delay_msec) { | 273 void GCMStatsRecorder::RecordConnectionDelayedDueToBackoff(int64 delay_msec) { |
263 if (!is_recording_) | 274 if (!is_recording_) |
(...skipping 29 matching lines...) Expand all Loading... |
293 const std::string& sender_ids, | 304 const std::string& sender_ids, |
294 const std::string& event, | 305 const std::string& event, |
295 const std::string& details) { | 306 const std::string& details) { |
296 RegistrationActivity data; | 307 RegistrationActivity data; |
297 RegistrationActivity* inserted_data = InsertCircularBuffer( | 308 RegistrationActivity* inserted_data = InsertCircularBuffer( |
298 ®istration_activities_, data); | 309 ®istration_activities_, data); |
299 inserted_data->app_id = app_id; | 310 inserted_data->app_id = app_id; |
300 inserted_data->sender_ids = sender_ids; | 311 inserted_data->sender_ids = sender_ids; |
301 inserted_data->event = event; | 312 inserted_data->event = event; |
302 inserted_data->details = details; | 313 inserted_data->details = details; |
| 314 NotifyActivityRecorded(); |
303 } | 315 } |
304 | 316 |
305 void GCMStatsRecorder::RecordRegistrationSent( | 317 void GCMStatsRecorder::RecordRegistrationSent( |
306 const std::string& app_id, | 318 const std::string& app_id, |
307 const std::string& sender_ids) { | 319 const std::string& sender_ids) { |
308 UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1); | 320 UMA_HISTOGRAM_COUNTS("GCM.RegistrationRequest", 1); |
309 if (!is_recording_) | 321 if (!is_recording_) |
310 return; | 322 return; |
311 RecordRegistration(app_id, sender_ids, | 323 RecordRegistration(app_id, sender_ids, |
312 "Registration request sent", std::string()); | 324 "Registration request sent", std::string()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 const std::string& event, | 383 const std::string& event, |
372 const std::string& details) { | 384 const std::string& details) { |
373 ReceivingActivity data; | 385 ReceivingActivity data; |
374 ReceivingActivity* inserted_data = InsertCircularBuffer( | 386 ReceivingActivity* inserted_data = InsertCircularBuffer( |
375 &receiving_activities_, data); | 387 &receiving_activities_, data); |
376 inserted_data->app_id = app_id; | 388 inserted_data->app_id = app_id; |
377 inserted_data->from = from; | 389 inserted_data->from = from; |
378 inserted_data->message_byte_size = message_byte_size; | 390 inserted_data->message_byte_size = message_byte_size; |
379 inserted_data->event = event; | 391 inserted_data->event = event; |
380 inserted_data->details = details; | 392 inserted_data->details = details; |
| 393 NotifyActivityRecorded(); |
381 } | 394 } |
382 | 395 |
383 void GCMStatsRecorder::RecordDataMessageReceived( | 396 void GCMStatsRecorder::RecordDataMessageReceived( |
384 const std::string& app_id, | 397 const std::string& app_id, |
385 const std::string& from, | 398 const std::string& from, |
386 int message_byte_size, | 399 int message_byte_size, |
387 bool to_registered_app, | 400 bool to_registered_app, |
388 ReceivedMessageType message_type) { | 401 ReceivedMessageType message_type) { |
389 if (to_registered_app) | 402 if (to_registered_app) |
390 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); | 403 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 const std::string& event, | 453 const std::string& event, |
441 const std::string& details) { | 454 const std::string& details) { |
442 SendingActivity data; | 455 SendingActivity data; |
443 SendingActivity* inserted_data = InsertCircularBuffer( | 456 SendingActivity* inserted_data = InsertCircularBuffer( |
444 &sending_activities_, data); | 457 &sending_activities_, data); |
445 inserted_data->app_id = app_id; | 458 inserted_data->app_id = app_id; |
446 inserted_data->receiver_id = receiver_id; | 459 inserted_data->receiver_id = receiver_id; |
447 inserted_data->message_id = message_id; | 460 inserted_data->message_id = message_id; |
448 inserted_data->event = event; | 461 inserted_data->event = event; |
449 inserted_data->details = details; | 462 inserted_data->details = details; |
| 463 NotifyActivityRecorded(); |
450 } | 464 } |
451 | 465 |
452 void GCMStatsRecorder::RecordDataSentToWire( | 466 void GCMStatsRecorder::RecordDataSentToWire( |
453 const std::string& app_id, | 467 const std::string& app_id, |
454 const std::string& receiver_id, | 468 const std::string& receiver_id, |
455 const std::string& message_id, | 469 const std::string& message_id, |
456 int queued) { | 470 int queued) { |
457 if (!is_recording_) | 471 if (!is_recording_) |
458 return; | 472 return; |
459 RecordSending(app_id, receiver_id, message_id, "Data msg sent to wire", | 473 RecordSending(app_id, receiver_id, message_id, "Data msg sent to wire", |
(...skipping 25 matching lines...) Expand all Loading... |
485 const std::string& receiver_id, | 499 const std::string& receiver_id, |
486 const std::string& message_id) { | 500 const std::string& message_id) { |
487 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); | 501 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); |
488 if (!is_recording_) | 502 if (!is_recording_) |
489 return; | 503 return; |
490 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", | 504 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", |
491 std::string()); | 505 std::string()); |
492 } | 506 } |
493 | 507 |
494 } // namespace gcm | 508 } // namespace gcm |
OLD | NEW |