| 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()); |
| 313 } | 325 } |
| 314 | 326 |
| 315 void GCMStatsRecorder::RecordRegistrationResponse( | 327 void GCMStatsRecorder::RecordRegistrationResponse( |
| 316 const std::string& app_id, | 328 const std::string& app_id, |
| 317 const std::vector<std::string>& sender_ids, | 329 const std::vector<std::string>& sender_ids, |
| 318 RegistrationRequest::Status status) { | 330 RegistrationRequest::Status status) { |
| 331 if (!is_recording_) |
| 332 return; |
| 319 RecordRegistration(app_id, JoinString(sender_ids, ","), | 333 RecordRegistration(app_id, JoinString(sender_ids, ","), |
| 320 "Registration response received", | 334 "Registration response received", |
| 321 GetRegistrationStatusString(status)); | 335 GetRegistrationStatusString(status)); |
| 322 } | 336 } |
| 323 | 337 |
| 324 void GCMStatsRecorder::RecordRegistrationRetryRequested( | 338 void GCMStatsRecorder::RecordRegistrationRetryRequested( |
| 325 const std::string& app_id, | 339 const std::string& app_id, |
| 326 const std::vector<std::string>& sender_ids, | 340 const std::vector<std::string>& sender_ids, |
| 327 int retries_left) { | 341 int retries_left) { |
| 328 if (!is_recording_) | 342 if (!is_recording_) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 const std::string& event, | 385 const std::string& event, |
| 372 const std::string& details) { | 386 const std::string& details) { |
| 373 ReceivingActivity data; | 387 ReceivingActivity data; |
| 374 ReceivingActivity* inserted_data = InsertCircularBuffer( | 388 ReceivingActivity* inserted_data = InsertCircularBuffer( |
| 375 &receiving_activities_, data); | 389 &receiving_activities_, data); |
| 376 inserted_data->app_id = app_id; | 390 inserted_data->app_id = app_id; |
| 377 inserted_data->from = from; | 391 inserted_data->from = from; |
| 378 inserted_data->message_byte_size = message_byte_size; | 392 inserted_data->message_byte_size = message_byte_size; |
| 379 inserted_data->event = event; | 393 inserted_data->event = event; |
| 380 inserted_data->details = details; | 394 inserted_data->details = details; |
| 395 NotifyActivityRecorded(); |
| 381 } | 396 } |
| 382 | 397 |
| 383 void GCMStatsRecorder::RecordDataMessageReceived( | 398 void GCMStatsRecorder::RecordDataMessageReceived( |
| 384 const std::string& app_id, | 399 const std::string& app_id, |
| 385 const std::string& from, | 400 const std::string& from, |
| 386 int message_byte_size, | 401 int message_byte_size, |
| 387 bool to_registered_app, | 402 bool to_registered_app, |
| 388 ReceivedMessageType message_type) { | 403 ReceivedMessageType message_type) { |
| 389 if (to_registered_app) | 404 if (to_registered_app) |
| 390 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); | 405 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 const std::string& event, | 455 const std::string& event, |
| 441 const std::string& details) { | 456 const std::string& details) { |
| 442 SendingActivity data; | 457 SendingActivity data; |
| 443 SendingActivity* inserted_data = InsertCircularBuffer( | 458 SendingActivity* inserted_data = InsertCircularBuffer( |
| 444 &sending_activities_, data); | 459 &sending_activities_, data); |
| 445 inserted_data->app_id = app_id; | 460 inserted_data->app_id = app_id; |
| 446 inserted_data->receiver_id = receiver_id; | 461 inserted_data->receiver_id = receiver_id; |
| 447 inserted_data->message_id = message_id; | 462 inserted_data->message_id = message_id; |
| 448 inserted_data->event = event; | 463 inserted_data->event = event; |
| 449 inserted_data->details = details; | 464 inserted_data->details = details; |
| 465 NotifyActivityRecorded(); |
| 450 } | 466 } |
| 451 | 467 |
| 452 void GCMStatsRecorder::RecordDataSentToWire( | 468 void GCMStatsRecorder::RecordDataSentToWire( |
| 453 const std::string& app_id, | 469 const std::string& app_id, |
| 454 const std::string& receiver_id, | 470 const std::string& receiver_id, |
| 455 const std::string& message_id, | 471 const std::string& message_id, |
| 456 int queued) { | 472 int queued) { |
| 457 if (!is_recording_) | 473 if (!is_recording_) |
| 458 return; | 474 return; |
| 459 RecordSending(app_id, receiver_id, message_id, "Data msg sent to wire", | 475 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, | 501 const std::string& receiver_id, |
| 486 const std::string& message_id) { | 502 const std::string& message_id) { |
| 487 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); | 503 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); |
| 488 if (!is_recording_) | 504 if (!is_recording_) |
| 489 return; | 505 return; |
| 490 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", | 506 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", |
| 491 std::string()); | 507 std::string()); |
| 492 } | 508 } |
| 493 | 509 |
| 494 } // namespace gcm | 510 } // namespace gcm |
| OLD | NEW |