Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 5 #ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
| 6 #define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 6 #define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 RecordedActivities(); | 88 RecordedActivities(); |
| 89 virtual ~RecordedActivities(); | 89 virtual ~RecordedActivities(); |
| 90 | 90 |
| 91 std::vector<GCMStatsRecorder::CheckinActivity> checkin_activities; | 91 std::vector<GCMStatsRecorder::CheckinActivity> checkin_activities; |
| 92 std::vector<GCMStatsRecorder::ConnectionActivity> connection_activities; | 92 std::vector<GCMStatsRecorder::ConnectionActivity> connection_activities; |
| 93 std::vector<GCMStatsRecorder::RegistrationActivity> registration_activities; | 93 std::vector<GCMStatsRecorder::RegistrationActivity> registration_activities; |
| 94 std::vector<GCMStatsRecorder::ReceivingActivity> receiving_activities; | 94 std::vector<GCMStatsRecorder::ReceivingActivity> receiving_activities; |
| 95 std::vector<GCMStatsRecorder::SendingActivity> sending_activities; | 95 std::vector<GCMStatsRecorder::SendingActivity> sending_activities; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 // A delegate interface that allows the GCMStatsRecorder instance to interact | |
| 99 // with its container. | |
| 100 class RecorderDelegate { | |
|
jianli
2014/05/06 22:54:53
Simpler to name it as Delegate since it is already
juyik
2014/05/07 00:07:48
Done.
| |
| 101 public: | |
| 102 // Called when the GCMStatsRecorder is recording activities and a new | |
| 103 // activity has just been recorded. | |
| 104 virtual void OnActivityRecorded() = 0; | |
| 105 }; | |
| 106 | |
| 98 GCMStatsRecorder(); | 107 GCMStatsRecorder(); |
| 99 virtual ~GCMStatsRecorder(); | 108 virtual ~GCMStatsRecorder(); |
| 100 | 109 |
| 101 // Indicates whether the recorder is currently recording activities or not. | 110 // Indicates whether the recorder is currently recording activities or not. |
| 102 bool is_recording() const { | 111 bool is_recording() const { |
| 103 return is_recording_; | 112 return is_recording_; |
| 104 } | 113 } |
| 105 | 114 |
| 106 // Turns recording on/off. | 115 // Turns recording on/off. |
| 107 void SetRecording(bool recording); | 116 void SetRecording(bool recording); |
| 108 | 117 |
| 118 // Set a delegate to receive async callback from the recorder. | |
| 119 void SetDelegate(RecorderDelegate* delegate); | |
| 120 | |
| 109 // Clear all recorded activities. | 121 // Clear all recorded activities. |
| 110 void Clear(); | 122 void Clear(); |
| 111 | 123 |
| 112 // All RecordXXXX methods below will record one activity. It will be inserted | 124 // All RecordXXXX methods below will record one activity. It will be inserted |
| 113 // to the front of a queue so that entries in the queue had reverse | 125 // to the front of a queue so that entries in the queue had reverse |
| 114 // chronological order. | 126 // chronological order. |
| 115 | 127 |
| 116 // Records that a check-in has been initiated. | 128 // Records that a check-in has been initiated. |
| 117 void RecordCheckinInitiated(uint64 android_id); | 129 void RecordCheckinInitiated(uint64 android_id); |
| 118 | 130 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 return registration_activities_; | 224 return registration_activities_; |
| 213 } | 225 } |
| 214 const std::deque<ReceivingActivity>& receiving_activities() const { | 226 const std::deque<ReceivingActivity>& receiving_activities() const { |
| 215 return receiving_activities_; | 227 return receiving_activities_; |
| 216 } | 228 } |
| 217 const std::deque<SendingActivity>& sending_activities() const { | 229 const std::deque<SendingActivity>& sending_activities() const { |
| 218 return sending_activities_; | 230 return sending_activities_; |
| 219 } | 231 } |
| 220 | 232 |
| 221 protected: | 233 protected: |
| 234 // Notify the recorder delegate, if it exists, that an activity has been | |
| 235 // recorded. | |
| 236 void NotifyActivityRecorded(); | |
| 222 void RecordCheckin(const std::string& event, | 237 void RecordCheckin(const std::string& event, |
| 223 const std::string& details); | 238 const std::string& details); |
| 224 void RecordConnection(const std::string& event, | 239 void RecordConnection(const std::string& event, |
| 225 const std::string& details); | 240 const std::string& details); |
| 226 void RecordRegistration(const std::string& app_id, | 241 void RecordRegistration(const std::string& app_id, |
| 227 const std::string& sender_id, | 242 const std::string& sender_id, |
| 228 const std::string& event, | 243 const std::string& event, |
| 229 const std::string& details); | 244 const std::string& details); |
| 230 void RecordReceiving(const std::string& app_id, | 245 void RecordReceiving(const std::string& app_id, |
| 231 const std::string& from, | 246 const std::string& from, |
| 232 int message_byte_size, | 247 int message_byte_size, |
| 233 const std::string& event, | 248 const std::string& event, |
| 234 const std::string& details); | 249 const std::string& details); |
| 235 void RecordSending(const std::string& app_id, | 250 void RecordSending(const std::string& app_id, |
| 236 const std::string& receiver_id, | 251 const std::string& receiver_id, |
| 237 const std::string& message_id, | 252 const std::string& message_id, |
| 238 const std::string& event, | 253 const std::string& event, |
| 239 const std::string& details); | 254 const std::string& details); |
| 240 | 255 |
| 241 bool is_recording_; | 256 bool is_recording_; |
| 257 RecorderDelegate* delegate_; | |
| 242 | 258 |
| 243 std::deque<CheckinActivity> checkin_activities_; | 259 std::deque<CheckinActivity> checkin_activities_; |
| 244 std::deque<ConnectionActivity> connection_activities_; | 260 std::deque<ConnectionActivity> connection_activities_; |
| 245 std::deque<RegistrationActivity> registration_activities_; | 261 std::deque<RegistrationActivity> registration_activities_; |
| 246 std::deque<ReceivingActivity> receiving_activities_; | 262 std::deque<ReceivingActivity> receiving_activities_; |
| 247 std::deque<SendingActivity> sending_activities_; | 263 std::deque<SendingActivity> sending_activities_; |
| 248 | 264 |
| 249 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); | 265 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); |
| 250 }; | 266 }; |
| 251 | 267 |
| 252 } // namespace gcm | 268 } // namespace gcm |
| 253 | 269 |
| 254 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ | 270 #endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
| OLD | NEW |