OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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. |
| 4 |
| 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_ANDROID_H_ |
| 6 #define COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_ANDROID_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "components/gcm_driver/gcm_activity.h" |
| 13 |
| 14 namespace gcm { |
| 15 |
| 16 struct RecordedActivities; |
| 17 |
| 18 // Stats recorder for Android, used for recording stats and activities on the |
| 19 // GCM Driver level for debugging purposes. Based on the GCMStatsRecorder, as |
| 20 // defined in the GCM Engine, which does not exist on Android. |
| 21 class GCMStatsRecorderAndroid { |
| 22 public: |
| 23 // A delegate interface that allows the GCMStatsRecorderAndroid instance to |
| 24 // interact with its container. |
| 25 class Delegate { |
| 26 public: |
| 27 // Called when the GCMStatsRecorderAndroid is recording activities and a new |
| 28 // activity has just been recorded. |
| 29 virtual void OnActivityRecorded() = 0; |
| 30 }; |
| 31 |
| 32 // A weak reference to |delegate| is stored, so it must outlive the recorder. |
| 33 explicit GCMStatsRecorderAndroid(Delegate* delegate); |
| 34 ~GCMStatsRecorderAndroid(); |
| 35 |
| 36 // Clears the recorded activities. |
| 37 void Clear(); |
| 38 |
| 39 // Collects all recorded activities into |*recorded_activities|. |
| 40 void CollectActivities(RecordedActivities* recorded_activities) const; |
| 41 |
| 42 // Records that a registration for |app_id| has been sent. |
| 43 void RecordRegistrationSent(const std::string& app_id); |
| 44 |
| 45 // Records that the registration sent for |app_id| has received a response. |
| 46 // |success| indicates whether the registration was successful. |
| 47 void RecordRegistrationResponse(const std::string& app_id, bool success); |
| 48 |
| 49 // Records that an unregistration for |app_id| has been sent. |
| 50 void RecordUnregistrationSent(const std::string& app_id); |
| 51 |
| 52 // Records that the unregistration sent for |app_id| has received a response. |
| 53 // |success| indicates whether the unregistration was successful. |
| 54 void RecordUnregistrationResponse(const std::string& app_id, bool success); |
| 55 |
| 56 // Records that a data message has been received for |app_id|. |
| 57 void RecordDataMessageReceived(const std::string& app_id, |
| 58 int message_byte_size); |
| 59 |
| 60 bool is_recording() const { return is_recording_; } |
| 61 void set_is_recording(bool recording) { is_recording_ = recording; } |
| 62 |
| 63 private: |
| 64 void RecordRegistration(const std::string& app_id, |
| 65 const std::string& event, |
| 66 const std::string& details); |
| 67 |
| 68 // Delegate made available by the container. May be a nullptr. |
| 69 Delegate* delegate_; |
| 70 |
| 71 // Toggle determining whether the recorder is recording. |
| 72 bool is_recording_ = false; |
| 73 |
| 74 // Recorded registration activities (which includes unregistrations). |
| 75 std::deque<RegistrationActivity> registration_activities_; |
| 76 |
| 77 // Recorded received message activities. |
| 78 std::deque<ReceivingActivity> receiving_activities_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorderAndroid); |
| 81 }; |
| 82 |
| 83 } // namespace gcm |
| 84 |
| 85 #endif // COMPONENTS_GCM_DRIVER_GCM_STATS_RECORDER_ANDROID_H_ |
OLD | NEW |