gcm_stats_recorder_android.h 3.7 KB

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