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
& sender_ids
) override
;
59 void RecordRegistrationResponse(const std::string
& app_id
,
60 const std::vector
<std::string
>& sender_ids
,
61 RegistrationRequest::Status status
) override
;
62 void RecordRegistrationRetryRequested(
63 const std::string
& app_id
,
64 const std::vector
<std::string
>& sender_ids
,
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
,
71 int64 delay_msec
) override
;
72 void RecordDataMessageReceived(const std::string
& app_id
,
73 const std::string
& from
,
74 int message_byte_size
,
75 bool to_registered_app
,
76 ReceivedMessageType message_type
) override
;
77 void RecordDataSentToWire(const std::string
& app_id
,
78 const std::string
& receiver_id
,
79 const std::string
& message_id
,
81 void RecordNotifySendStatus(const std::string
& app_id
,
82 const std::string
& receiver_id
,
83 const std::string
& message_id
,
84 MCSClient::MessageSendStatus status
,
87 void RecordIncomingSendError(const std::string
& app_id
,
88 const std::string
& receiver_id
,
89 const std::string
& message_id
) override
;
91 // Collect all recorded activities into the struct.
92 void CollectActivities(RecordedActivities
* recorder_activities
) const;
94 const std::deque
<CheckinActivity
>& checkin_activities() const {
95 return checkin_activities_
;
97 const std::deque
<ConnectionActivity
>& connection_activities() const {
98 return connection_activities_
;
100 const std::deque
<RegistrationActivity
>& registration_activities() const {
101 return registration_activities_
;
103 const std::deque
<ReceivingActivity
>& receiving_activities() const {
104 return receiving_activities_
;
106 const std::deque
<SendingActivity
>& sending_activities() const {
107 return sending_activities_
;
111 // Notify the recorder delegate, if it exists, that an activity has been
113 void NotifyActivityRecorded();
115 void RecordCheckin(const std::string
& event
,
116 const std::string
& details
);
118 void RecordConnection(const std::string
& event
,
119 const std::string
& details
);
121 void RecordRegistration(const std::string
& app_id
,
122 const std::string
& sender_id
,
123 const std::string
& event
,
124 const std::string
& details
);
126 void RecordReceiving(const std::string
& app_id
,
127 const std::string
& from
,
128 int message_byte_size
,
129 const std::string
& event
,
130 const std::string
& details
);
132 void RecordSending(const std::string
& app_id
,
133 const std::string
& receiver_id
,
134 const std::string
& message_id
,
135 const std::string
& event
,
136 const std::string
& details
);
141 std::deque
<CheckinActivity
> checkin_activities_
;
142 std::deque
<ConnectionActivity
> connection_activities_
;
143 std::deque
<RegistrationActivity
> registration_activities_
;
144 std::deque
<ReceivingActivity
> receiving_activities_
;
145 std::deque
<SendingActivity
> sending_activities_
;
147 base::TimeTicks last_connection_initiation_time_
;
148 base::TimeTicks last_connection_success_time_
;
149 bool data_message_received_since_connected_
;
150 base::TimeTicks last_received_data_message_burst_start_time_
;
151 base::TimeTicks last_received_data_message_time_within_burst_
;
152 int64 received_data_message_burst_size_
;
154 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorderImpl
);
159 #endif // COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_IMPL_H_