gcm_stats_recorder.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifndef GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_
  5. #define GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "google_apis/gcm/base/gcm_export.h"
  10. #include "google_apis/gcm/engine/connection_factory.h"
  11. #include "google_apis/gcm/engine/mcs_client.h"
  12. #include "google_apis/gcm/engine/registration_request.h"
  13. #include "google_apis/gcm/engine/unregistration_request.h"
  14. namespace gcm {
  15. // Defines the interface to record GCM internal stats and activities for
  16. // debugging purpose.
  17. class GCM_EXPORT GCMStatsRecorder {
  18. public:
  19. // Type of a received message
  20. enum ReceivedMessageType {
  21. // Data message.
  22. DATA_MESSAGE,
  23. // Message that indicates some messages have been deleted on the server.
  24. DELETED_MESSAGES,
  25. };
  26. // A delegate interface that allows the GCMStatsRecorderImpl instance to
  27. // interact with its container.
  28. class Delegate {
  29. public:
  30. // Called when the GCMStatsRecorderImpl is recording activities and a new
  31. // activity has just been recorded.
  32. virtual void OnActivityRecorded() = 0;
  33. };
  34. GCMStatsRecorder() {}
  35. virtual ~GCMStatsRecorder() {}
  36. // Records that a check-in has been initiated.
  37. virtual void RecordCheckinInitiated(uint64_t android_id) = 0;
  38. // Records that a check-in has been delayed due to backoff.
  39. virtual void RecordCheckinDelayedDueToBackoff(int64_t delay_msec) = 0;
  40. // Records that a check-in request has succeeded.
  41. virtual void RecordCheckinSuccess() = 0;
  42. // Records that a check-in request has failed. If a retry will be tempted then
  43. // will_retry should be true.
  44. virtual void RecordCheckinFailure(const std::string& status,
  45. bool will_retry) = 0;
  46. // Records that a connection to MCS has been initiated.
  47. virtual void RecordConnectionInitiated(const std::string& host) = 0;
  48. // Records that a connection has been delayed due to backoff.
  49. virtual void RecordConnectionDelayedDueToBackoff(int64_t delay_msec) = 0;
  50. // Records that connection has been successfully established.
  51. virtual void RecordConnectionSuccess() = 0;
  52. // Records that connection has failed with a network error code.
  53. virtual void RecordConnectionFailure(int network_error) = 0;
  54. // Records that connection reset has been signaled.
  55. virtual void RecordConnectionResetSignaled(
  56. ConnectionFactory::ConnectionResetReason reason) = 0;
  57. // Records that a registration request has been sent. This could be initiated
  58. // directly from API, or from retry logic.
  59. virtual void RecordRegistrationSent(const std::string& app_id,
  60. const std::string& source) = 0;
  61. // Records that a registration response has been received from server.
  62. virtual void RecordRegistrationResponse(
  63. const std::string& app_id,
  64. const std::string& source,
  65. RegistrationRequest::Status status) = 0;
  66. // Records that a registration retry has been requested and delayed due to
  67. // backoff logic.
  68. virtual void RecordRegistrationRetryDelayed(const std::string& app_id,
  69. const std::string& source,
  70. int64_t delay_msec,
  71. int retries_left) = 0;
  72. // Records that an unregistration request has been sent. This could be
  73. // initiated directly from API, or from retry logic.
  74. virtual void RecordUnregistrationSent(const std::string& app_id,
  75. const std::string& source) = 0;
  76. // Records that an unregistration response has been received from server.
  77. virtual void RecordUnregistrationResponse(
  78. const std::string& app_id,
  79. const std::string& source,
  80. UnregistrationRequest::Status status) = 0;
  81. // Records that an unregistration retry has been requested and delayed due to
  82. // backoff logic.
  83. virtual void RecordUnregistrationRetryDelayed(const std::string& app_id,
  84. const std::string& source,
  85. int64_t delay_msec,
  86. int retries_left) = 0;
  87. // Records that a data message has been received. If it indicates that one or
  88. // more messages were dropped on the server, message_type should be
  89. // DELETED_MESSAGES.
  90. virtual void RecordDataMessageReceived(const std::string& app_id,
  91. const std::string& from,
  92. int message_byte_size,
  93. ReceivedMessageType message_type) = 0;
  94. // Records that an outgoing data message was sent over the wire.
  95. virtual void RecordDataSentToWire(const std::string& app_id,
  96. const std::string& receiver_id,
  97. const std::string& message_id,
  98. int queued) = 0;
  99. // Records that the MCS client sent a 'send status' notification to callback.
  100. virtual void RecordNotifySendStatus(const std::string& app_id,
  101. const std::string& receiver_id,
  102. const std::string& message_id,
  103. MCSClient::MessageSendStatus status,
  104. int byte_size,
  105. int ttl) = 0;
  106. // Records that a 'send error' message was received.
  107. virtual void RecordIncomingSendError(const std::string& app_id,
  108. const std::string& receiver_id,
  109. const std::string& message_id) = 0;
  110. };
  111. } // namespace gcm
  112. #endif // GOOGLE_APIS_GCM_MONITORING_GCM_STATS_RECORDER_H_