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