| Index: google_apis/gcm/monitoring/gcm_stats_recorder.h
|
| diff --git a/google_apis/gcm/monitoring/gcm_stats_recorder.h b/google_apis/gcm/monitoring/gcm_stats_recorder.h
|
| index 71b6c6ac35e25d0cb29cfb9fc60f001e70fa3a2a..fb8e805889b5eaf1db1e97368384401847eed667 100644
|
| --- a/google_apis/gcm/monitoring/gcm_stats_recorder.h
|
| +++ b/google_apis/gcm/monitoring/gcm_stats_recorder.h
|
| @@ -11,7 +11,10 @@
|
|
|
| #include "base/time/time.h"
|
| #include "google_apis/gcm/base/gcm_export.h"
|
| +#include "google_apis/gcm/engine/connection_factory.h"
|
| #include "google_apis/gcm/engine/mcs_client.h"
|
| +#include "google_apis/gcm/engine/registration_request.h"
|
| +#include "google_apis/gcm/engine/unregistration_request.h"
|
|
|
| namespace gcm {
|
|
|
| @@ -22,6 +25,14 @@ namespace gcm {
|
| // instance.
|
| class GCM_EXPORT GCMStatsRecorder {
|
| public:
|
| + // Type of a received message
|
| + enum ReceivedMessageType {
|
| + // Data message.
|
| + DATA_MESSAGE,
|
| + // Message that indicates some messages have been deleted on the server.
|
| + DELETED_MESSAGES,
|
| + };
|
| +
|
| // Contains data that are common to all activity kinds below.
|
| struct GCM_EXPORT Activity {
|
| Activity();
|
| @@ -32,6 +43,31 @@ class GCM_EXPORT GCMStatsRecorder {
|
| std::string details; // Any additional detail about the event.
|
| };
|
|
|
| + // Contains relevant data of a connection activity.
|
| + struct GCM_EXPORT ConnectionActivity : Activity {
|
| + ConnectionActivity();
|
| + virtual ~ConnectionActivity();
|
| + };
|
| +
|
| + // Contains relevant data of a registration/unregistration step.
|
| + struct GCM_EXPORT RegistrationActivity : Activity {
|
| + RegistrationActivity();
|
| + virtual ~RegistrationActivity();
|
| +
|
| + std::string app_id;
|
| + std::string sender_ids; // Comma separated sender ids.
|
| + };
|
| +
|
| + // Contains relevant data of a message receiving event.
|
| + struct GCM_EXPORT ReceivingActivity : Activity {
|
| + ReceivingActivity();
|
| + virtual ~ReceivingActivity();
|
| +
|
| + std::string app_id;
|
| + std::string from;
|
| + int message_byte_size;
|
| + };
|
| +
|
| // Contains relevant data of a send-message step.
|
| struct GCM_EXPORT SendingActivity : Activity {
|
| SendingActivity();
|
| @@ -42,6 +78,16 @@ class GCM_EXPORT GCMStatsRecorder {
|
| std::string message_id;
|
| };
|
|
|
| + struct GCM_EXPORT RecordedActivities {
|
| + RecordedActivities();
|
| + virtual ~RecordedActivities();
|
| +
|
| + std::vector<GCMStatsRecorder::ConnectionActivity> connection_activities;
|
| + std::vector<GCMStatsRecorder::RegistrationActivity> registration_activities;
|
| + std::vector<GCMStatsRecorder::ReceivingActivity> receiving_activities;
|
| + std::vector<GCMStatsRecorder::SendingActivity> sending_activities;
|
| + };
|
| +
|
| GCMStatsRecorder();
|
| virtual ~GCMStatsRecorder();
|
|
|
| @@ -56,6 +102,66 @@ class GCM_EXPORT GCMStatsRecorder {
|
| // Clear all recorded activities.
|
| void Clear();
|
|
|
| + // All RecordXXXX methods below will record one activity. It will be inserted
|
| + // to the front of a queue so that entries in the queue had reverse
|
| + // chronological order.
|
| +
|
| + // Records that a connection to MCS has been initiated.
|
| + void RecordConnectionInitiated(const std::string& host);
|
| +
|
| + // Records that a connection has been delayed due to backoff.
|
| + void RecordConnectionDelayedDueToBackoff(int64 delay_msec);
|
| +
|
| + // Records that connection has been successfully established.
|
| + void RecordConnectionSuccess();
|
| +
|
| + // Records that connection has failed with a network error code.
|
| + void RecordConnectionFailure(int network_error);
|
| +
|
| + // Records that connection reset has been signaled.
|
| + void RecordConnectionResetSignaled(
|
| + ConnectionFactory::ConnectionResetReason reason);
|
| +
|
| + // Records that a registration request has been sent. This could be initiated
|
| + // directly from API, or from retry logic.
|
| + void RecordRegistrationSent(const std::string& app_id,
|
| + const std::string& sender_ids);
|
| +
|
| + // Records that a registration response has been received from server.
|
| + void RecordRegistrationResponse(const std::string& app_id,
|
| + const std::vector<std::string>& sender_ids,
|
| + RegistrationRequest::Status status);
|
| +
|
| + // Records that a registration retry has been requested. The actual retry
|
| + // action may not occur until some time later according to backoff logic.
|
| + void RecordRegistrationRetryRequested(
|
| + const std::string& app_id,
|
| + const std::vector<std::string>& sender_ids,
|
| + int retries_left);
|
| +
|
| + // Records that an unregistration request has been sent. This could be
|
| + // initiated directly from API, or from retry logic.
|
| + void RecordUnregistrationSent(const std::string& app_id);
|
| +
|
| + // Records that an unregistration response has been received from server.
|
| + void RecordUnregistrationResponse(const std::string& app_id,
|
| + UnregistrationRequest::Status status);
|
| +
|
| + // Records that an unregistration retry has been requested and delayed due to
|
| + // backoff logic.
|
| + void RecordUnregistrationRetryDelayed(const std::string& app_id,
|
| + int64 delay_msec);
|
| +
|
| + // Records that a data message has been received. If this message is not
|
| + // sent to a registered app, to_registered_app shoudl be false. If it
|
| + // indicates that a message has been dropped on the server, is_message_dropped
|
| + // should be true.
|
| + void RecordDataMessageRecieved(const std::string& app_id,
|
| + const std::string& from,
|
| + int message_byte_size,
|
| + bool to_registered_app,
|
| + ReceivedMessageType message_type);
|
| +
|
| // Records that an outgoing data message was sent over the wire.
|
| void RecordDataSentToWire(const std::string& app_id,
|
| const std::string& receiver_id,
|
| @@ -73,16 +179,34 @@ class GCM_EXPORT GCMStatsRecorder {
|
| const std::string& receiver_id,
|
| const std::string& message_id);
|
|
|
| - // Records that a sending activity has occurred. It will be inserted to the
|
| - // front of a queue ao that entries in the queue had reverse chronological
|
| - // order.
|
| - void CollectSendingActivities(std::vector<SendingActivity>* activities) const;
|
| + // Collect all recorded activities into the struct.
|
| + void CollectActivities(RecordedActivities* recorder_activities) const;
|
|
|
| + const std::deque<ConnectionActivity>& connection_activities() const {
|
| + return connection_activities_;
|
| + }
|
| + const std::deque<RegistrationActivity>& registration_activities() const {
|
| + return registration_activities_;
|
| + }
|
| + const std::deque<ReceivingActivity>& receiving_activities() const {
|
| + return receiving_activities_;
|
| + }
|
| const std::deque<SendingActivity>& sending_activities() const {
|
| return sending_activities_;
|
| }
|
|
|
| protected:
|
| + void RecordConnection(const std::string& event,
|
| + const std::string& details);
|
| + void RecordRegistration(const std::string& app_id,
|
| + const std::string& sender_id,
|
| + const std::string& event,
|
| + const std::string& details);
|
| + void RecordReceiving(const std::string& app_id,
|
| + const std::string& from,
|
| + int message_byte_size,
|
| + const std::string& event,
|
| + const std::string& details);
|
| void RecordSending(const std::string& app_id,
|
| const std::string& receiver_id,
|
| const std::string& message_id,
|
| @@ -91,6 +215,9 @@ class GCM_EXPORT GCMStatsRecorder {
|
|
|
| bool is_recording_;
|
|
|
| + std::deque<ConnectionActivity> connection_activities_;
|
| + std::deque<RegistrationActivity> registration_activities_;
|
| + std::deque<ReceivingActivity> receiving_activities_;
|
| std::deque<SendingActivity> sending_activities_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder);
|
|
|