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
& senders
) override
;
59 void RecordRegistrationResponse(const std::string
& app_id
,
60 const std::string
& senders
,
61 RegistrationRequest::Status status
) override
;
62 void RecordRegistrationRetryRequested(
63 const std::string
& app_id
,
64 const std::string
& senders
,
65 int retries_left
) override
;
66 void RecordUnregistrationSent(const std::string
& app_id
) override
;
67 void RecordUnregistrationResponse(
68 const std::string
& app_id
,
69 UnregistrationRequest::Status status
) override
;
70 void RecordUnregistrationRetryDelayed(const std::string
& app_id
,
72 int retries_left
) override
;
73 void RecordDataMessageReceived(const std::string
& app_id
,
74 const std::string
& from
,
75 int message_byte_size
,
76 bool to_registered_app
,
77 ReceivedMessageType message_type
) override
;
78 void RecordDataSentToWire(const std::string
& app_id
,
79 const std::string
& receiver_id
,
80 const std::string
& message_id
,
82 void RecordNotifySendStatus(const std::string
& app_id
,
83 const std::string
& receiver_id
,
84 const std::string
& message_id
,
85 MCSClient::MessageSendStatus status
,
88 void RecordIncomingSendError(const std::string
& app_id
,
89 const std::string
& receiver_id
,
90 const std::string
& message_id
) override
;
92 // Collect all recorded activities into the struct.
93 void CollectActivities(RecordedActivities
* recorder_activities
) const;
95 const std::deque
<CheckinActivity
>& checkin_activities() const {
96 return checkin_activities_
;
98 const std::deque
<ConnectionActivity
>& connection_activities() const {
99 return connection_activities_
;
101 const std::deque
<RegistrationActivity
>& registration_activities() const {
102 return registration_activities_
;
104 const std::deque
<ReceivingActivity
>& receiving_activities() const {
105 return receiving_activities_
;
107 const std::deque
<SendingActivity
>& sending_activities() const {
108 return sending_activities_
;
112 // Notify the recorder delegate, if it exists, that an activity has been
114 void NotifyActivityRecorded();
116 void RecordCheckin(const std::string
& event
,
117 const std::string
& details
);
119 void RecordConnection(const std::string
& event
,
120 const std::string
& details
);
122 void RecordRegistration(const std::string
& app_id
,
123 const std::string
& sender_id
,
124 const std::string
& event
,
125 const std::string
& details
);
127 void RecordReceiving(const std::string
& app_id
,
128 const std::string
& from
,
129 int message_byte_size
,
130 const std::string
& event
,
131 const std::string
& details
);
133 void RecordSending(const std::string
& app_id
,
134 const std::string
& receiver_id
,
135 const std::string
& message_id
,
136 const std::string
& event
,
137 const std::string
& details
);
142 std::deque
<CheckinActivity
> checkin_activities_
;
143 std::deque
<ConnectionActivity
> connection_activities_
;
144 std::deque
<RegistrationActivity
> registration_activities_
;
145 std::deque
<ReceivingActivity
> receiving_activities_
;
146 std::deque
<SendingActivity
> sending_activities_
;
148 base::TimeTicks last_connection_initiation_time_
;
149 base::TimeTicks last_connection_success_time_
;
150 bool data_message_received_since_connected_
;
151 base::TimeTicks last_received_data_message_burst_start_time_
;
152 base::TimeTicks last_received_data_message_time_within_burst_
;
153 int64 received_data_message_burst_size_
;
155 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorderImpl
);
160 #endif // COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_IMPL_H_