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 virtual ~GCMStatsRecorderImpl();
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 virtual void RecordCheckinInitiated(uint64 android_id
) OVERRIDE
;
48 virtual void RecordCheckinDelayedDueToBackoff(int64 delay_msec
) OVERRIDE
;
49 virtual void RecordCheckinSuccess() OVERRIDE
;
50 virtual void RecordCheckinFailure(std::string status
,
51 bool will_retry
) OVERRIDE
;
52 virtual void RecordConnectionInitiated(const std::string
& host
) OVERRIDE
;
53 virtual void RecordConnectionDelayedDueToBackoff(int64 delay_msec
) OVERRIDE
;
54 virtual void RecordConnectionSuccess() OVERRIDE
;
55 virtual void RecordConnectionFailure(int network_error
) OVERRIDE
;
56 virtual void RecordConnectionResetSignaled(
57 ConnectionFactory::ConnectionResetReason reason
) OVERRIDE
;
58 virtual void RecordRegistrationSent(const std::string
& app_id
,
59 const std::string
& sender_ids
) OVERRIDE
;
60 virtual void RecordRegistrationResponse(
61 const std::string
& app_id
,
62 const std::vector
<std::string
>& sender_ids
,
63 RegistrationRequest::Status status
) OVERRIDE
;
64 virtual void RecordRegistrationRetryRequested(
65 const std::string
& app_id
,
66 const std::vector
<std::string
>& sender_ids
,
67 int retries_left
) OVERRIDE
;
68 virtual void RecordUnregistrationSent(const std::string
& app_id
) OVERRIDE
;
69 virtual void RecordUnregistrationResponse(
70 const std::string
& app_id
,
71 UnregistrationRequest::Status status
) OVERRIDE
;
72 virtual void RecordUnregistrationRetryDelayed(const std::string
& app_id
,
73 int64 delay_msec
) OVERRIDE
;
74 virtual void RecordDataMessageReceived(
75 const std::string
& app_id
,
76 const std::string
& from
,
77 int message_byte_size
,
78 bool to_registered_app
,
79 ReceivedMessageType message_type
) OVERRIDE
;
80 virtual void RecordDataSentToWire(const std::string
& app_id
,
81 const std::string
& receiver_id
,
82 const std::string
& message_id
,
84 virtual void RecordNotifySendStatus(const std::string
& app_id
,
85 const std::string
& receiver_id
,
86 const std::string
& message_id
,
87 MCSClient::MessageSendStatus status
,
90 virtual void RecordIncomingSendError(const std::string
& app_id
,
91 const std::string
& receiver_id
,
92 const std::string
& message_id
) OVERRIDE
;
94 // Collect all recorded activities into the struct.
95 void CollectActivities(RecordedActivities
* recorder_activities
) const;
97 const std::deque
<CheckinActivity
>& checkin_activities() const {
98 return checkin_activities_
;
100 const std::deque
<ConnectionActivity
>& connection_activities() const {
101 return connection_activities_
;
103 const std::deque
<RegistrationActivity
>& registration_activities() const {
104 return registration_activities_
;
106 const std::deque
<ReceivingActivity
>& receiving_activities() const {
107 return receiving_activities_
;
109 const std::deque
<SendingActivity
>& sending_activities() const {
110 return sending_activities_
;
114 // Notify the recorder delegate, if it exists, that an activity has been
116 void NotifyActivityRecorded();
118 void RecordCheckin(const std::string
& event
,
119 const std::string
& details
);
121 void RecordConnection(const std::string
& event
,
122 const std::string
& details
);
124 void RecordRegistration(const std::string
& app_id
,
125 const std::string
& sender_id
,
126 const std::string
& event
,
127 const std::string
& details
);
129 void RecordReceiving(const std::string
& app_id
,
130 const std::string
& from
,
131 int message_byte_size
,
132 const std::string
& event
,
133 const std::string
& details
);
135 void RecordSending(const std::string
& app_id
,
136 const std::string
& receiver_id
,
137 const std::string
& message_id
,
138 const std::string
& event
,
139 const std::string
& details
);
144 std::deque
<CheckinActivity
> checkin_activities_
;
145 std::deque
<ConnectionActivity
> connection_activities_
;
146 std::deque
<RegistrationActivity
> registration_activities_
;
147 std::deque
<ReceivingActivity
> receiving_activities_
;
148 std::deque
<SendingActivity
> sending_activities_
;
150 base::TimeTicks last_connection_initiation_time_
;
151 base::TimeTicks last_connection_success_time_
;
152 bool data_message_received_since_connected_
;
153 base::TimeTicks last_received_data_message_burst_start_time_
;
154 base::TimeTicks last_received_data_message_time_within_burst_
;
155 int64 received_data_message_burst_size_
;
157 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorderImpl
);
162 #endif // COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_IMPL_H_