Minor Cleanup for SafeBrowsingResourceThrottleFactory.
[chromium-blink-merge.git] / components / gcm_driver / gcm_stats_recorder_impl.h
blobde11d49121b0d84ae4c6746caec45af3e76c4f82
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_
8 #include <deque>
9 #include <string>
10 #include <vector>
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"
20 namespace gcm {
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
24 // by default.
25 // This class is not thread safe. It is meant to be owned by a gcm client
26 // instance.
27 class GCMStatsRecorderImpl : public GCMStatsRecorder {
28 public:
29 GCMStatsRecorderImpl();
30 ~GCMStatsRecorderImpl() override;
32 // Indicates whether the recorder is currently recording activities or not.
33 bool is_recording() const {
34 return is_recording_;
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.
44 void Clear();
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,
65 int64 delay_msec,
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,
75 int64 delay_msec,
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,
85 int queued) override;
86 void RecordNotifySendStatus(const std::string& app_id,
87 const std::string& receiver_id,
88 const std::string& message_id,
89 MCSClient::MessageSendStatus status,
90 int byte_size,
91 int ttl) override;
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_;
115 protected:
116 // Notify the recorder delegate, if it exists, that an activity has been
117 // recorded.
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);
143 bool is_recording_;
144 Delegate* delegate_;
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);
162 } // namespace gcm
164 #endif // COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_IMPL_H_