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.
5 #ifndef COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_IMPL_H_
6 #define COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_IMPL_H_
12 #include "base/time/time.h"
13 #include "components/gcm_driver/gcm_activity.h"
14 #include "google_apis/gcm/engine/connection_factory.h"
15 #include "google_apis/gcm/engine/mcs_client.h"
16 #include "google_apis/gcm/engine/registration_request.h"
17 #include "google_apis/gcm/engine/unregistration_request.h"
18 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
22 // Records GCM internal stats and activities for debugging purpose. Recording
23 // can be turned on/off by calling SetRecording(...) function. It is turned off
25 // This class is not thread safe. It is meant to be owned by a gcm client
27 class GCMStatsRecorderImpl
: public GCMStatsRecorder
{
29 GCMStatsRecorderImpl();
30 ~GCMStatsRecorderImpl() override
;
32 // Indicates whether the recorder is currently recording activities or not.
33 bool is_recording() const {
37 // Turns recording on/off.
38 void SetRecording(bool recording
);
40 // Set a delegate to receive callback from the recorder.
41 void SetDelegate(Delegate
* delegate
);
43 // Clear all recorded activities.
46 // GCMStatsRecorder implementation:
47 void RecordCheckinInitiated(uint64 android_id
) override
;
48 void RecordCheckinDelayedDueToBackoff(int64 delay_msec
) override
;
49 void RecordCheckinSuccess() override
;
50 void RecordCheckinFailure(std::string status
, bool will_retry
) override
;
51 void RecordConnectionInitiated(const std::string
& host
) override
;
52 void RecordConnectionDelayedDueToBackoff(int64 delay_msec
) override
;
53 void RecordConnectionSuccess() override
;
54 void RecordConnectionFailure(int network_error
) override
;
55 void RecordConnectionResetSignaled(
56 ConnectionFactory::ConnectionResetReason reason
) override
;
57 void RecordRegistrationSent(const std::string
& app_id
,
58 const std::string
& source
) override
;
59 void RecordRegistrationResponse(const std::string
& app_id
,
60 const std::string
& source
,
61 RegistrationRequest::Status status
) override
;
62 void RecordRegistrationRetryDelayed(
63 const std::string
& app_id
,
64 const std::string
& source
,
66 int retries_left
) override
;
67 void RecordUnregistrationSent(const std::string
& app_id
,
68 const std::string
& source
) override
;
69 void RecordUnregistrationResponse(
70 const std::string
& app_id
,
71 const std::string
& source
,
72 UnregistrationRequest::Status status
) override
;
73 void RecordUnregistrationRetryDelayed(const std::string
& app_id
,
74 const std::string
& source
,
76 int retries_left
) override
;
77 void RecordDataMessageReceived(const std::string
& app_id
,
78 const std::string
& from
,
79 int message_byte_size
,
80 bool to_registered_app
,
81 ReceivedMessageType message_type
) override
;
82 void RecordDataSentToWire(const std::string
& app_id
,
83 const std::string
& receiver_id
,
84 const std::string
& message_id
,
86 void RecordNotifySendStatus(const std::string
& app_id
,
87 const std::string
& receiver_id
,
88 const std::string
& message_id
,
89 MCSClient::MessageSendStatus status
,
92 void RecordIncomingSendError(const std::string
& app_id
,
93 const std::string
& receiver_id
,
94 const std::string
& message_id
) override
;
96 // Collect all recorded activities into the struct.
97 void CollectActivities(RecordedActivities
* recorder_activities
) const;
99 const std::deque
<CheckinActivity
>& checkin_activities() const {
100 return checkin_activities_
;
102 const std::deque
<ConnectionActivity
>& connection_activities() const {
103 return connection_activities_
;
105 const std::deque
<RegistrationActivity
>& registration_activities() const {
106 return registration_activities_
;
108 const std::deque
<ReceivingActivity
>& receiving_activities() const {
109 return receiving_activities_
;
111 const std::deque
<SendingActivity
>& sending_activities() const {
112 return sending_activities_
;
116 // Notify the recorder delegate, if it exists, that an activity has been
118 void NotifyActivityRecorded();
120 void RecordCheckin(const std::string
& event
,
121 const std::string
& details
);
123 void RecordConnection(const std::string
& event
,
124 const std::string
& details
);
126 void RecordRegistration(const std::string
& app_id
,
127 const std::string
& source
,
128 const std::string
& event
,
129 const std::string
& details
);
131 void RecordReceiving(const std::string
& app_id
,
132 const std::string
& from
,
133 int message_byte_size
,
134 const std::string
& event
,
135 const std::string
& details
);
137 void RecordSending(const std::string
& app_id
,
138 const std::string
& receiver_id
,
139 const std::string
& message_id
,
140 const std::string
& event
,
141 const std::string
& details
);
146 std::deque
<CheckinActivity
> checkin_activities_
;
147 std::deque
<ConnectionActivity
> connection_activities_
;
148 std::deque
<RegistrationActivity
> registration_activities_
;
149 std::deque
<ReceivingActivity
> receiving_activities_
;
150 std::deque
<SendingActivity
> sending_activities_
;
152 base::TimeTicks last_connection_initiation_time_
;
153 base::TimeTicks last_connection_success_time_
;
154 bool data_message_received_since_connected_
;
155 base::TimeTicks last_received_data_message_burst_start_time_
;
156 base::TimeTicks last_received_data_message_time_within_burst_
;
157 int64 received_data_message_burst_size_
;
159 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorderImpl
);
164 #endif // COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_IMPL_H_