feedback_data.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.
  4. #ifndef COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_
  5. #define COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/sequence_checker.h"
  12. #include "components/feedback/feedback_common.h"
  13. #include "components/feedback/feedback_uploader.h"
  14. #include "url/gurl.h"
  15. namespace base {
  16. class RefCountedString;
  17. }
  18. class TracingManager;
  19. namespace feedback {
  20. class FeedbackData : public FeedbackCommon {
  21. public:
  22. FeedbackData(base::WeakPtr<feedback::FeedbackUploader> uploader,
  23. TracingManager* tracing_manager);
  24. FeedbackData(const FeedbackData&) = delete;
  25. FeedbackData& operator=(const FeedbackData&) = delete;
  26. // Called once we've updated all the data from the feedback page.
  27. void OnFeedbackPageDataComplete();
  28. // Kicks off compression of the system information for this instance.
  29. void CompressSystemInfo();
  30. // Sets the histograms for this instance and kicks off its
  31. // compression.
  32. void SetAndCompressHistograms(std::string histograms);
  33. // Sets the attached file data and kicks off its compression.
  34. void AttachAndCompressFileData(std::string attached_filedata);
  35. // Returns true if we've completed all the tasks needed before we can send
  36. // feedback - at this time this is includes getting the feedback page data
  37. // and compressing the system logs.
  38. bool IsDataComplete();
  39. // Sends the feedback report if we have all our data complete.
  40. void SendReport();
  41. // Getters
  42. const std::string& attached_filename() const {
  43. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  44. return attached_filename_;
  45. }
  46. const std::string& attached_file_uuid() const {
  47. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  48. return attached_file_uuid_;
  49. }
  50. const std::string& screenshot_uuid() const {
  51. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  52. return screenshot_uuid_;
  53. }
  54. int trace_id() const {
  55. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  56. return trace_id_;
  57. }
  58. bool from_assistant() const {
  59. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  60. return from_assistant_;
  61. }
  62. bool assistant_debug_info_allowed() const {
  63. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  64. return assistant_debug_info_allowed_;
  65. }
  66. // Setters
  67. void set_attached_filename(const std::string& attached_filename) {
  68. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  69. attached_filename_ = attached_filename;
  70. }
  71. void set_attached_file_uuid(const std::string& uuid) {
  72. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  73. attached_file_uuid_ = uuid;
  74. }
  75. void set_screenshot_uuid(const std::string& uuid) {
  76. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  77. screenshot_uuid_ = uuid;
  78. }
  79. void set_trace_id(int trace_id) {
  80. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  81. trace_id_ = trace_id;
  82. }
  83. void set_from_assistant(bool from_assistant) {
  84. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  85. from_assistant_ = from_assistant;
  86. }
  87. void set_assistant_debug_info_allowed(bool assistant_debug_info_allowed) {
  88. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  89. assistant_debug_info_allowed_ = assistant_debug_info_allowed;
  90. }
  91. private:
  92. ~FeedbackData() override;
  93. // Called once a compression operation is complete.
  94. void OnCompressComplete();
  95. void OnGetTraceData(int trace_id,
  96. scoped_refptr<base::RefCountedString> trace_data);
  97. SEQUENCE_CHECKER(sequence_checker_);
  98. // The uploader_ is tied to a profile. When the profile is deleted, the
  99. // uploader_ will be destroyed.
  100. base::WeakPtr<feedback::FeedbackUploader> uploader_;
  101. std::string attached_filename_ GUARDED_BY_CONTEXT(sequence_checker_);
  102. std::string attached_file_uuid_ GUARDED_BY_CONTEXT(sequence_checker_);
  103. std::string screenshot_uuid_ GUARDED_BY_CONTEXT(sequence_checker_);
  104. const raw_ptr<TracingManager> tracing_manager_ = nullptr; // Not owned.
  105. int trace_id_ GUARDED_BY_CONTEXT(sequence_checker_) = 0;
  106. int pending_op_count_ GUARDED_BY_CONTEXT(sequence_checker_) = 1;
  107. bool report_sent_ GUARDED_BY_CONTEXT(sequence_checker_) = false;
  108. bool from_assistant_ GUARDED_BY_CONTEXT(sequence_checker_) = false;
  109. bool assistant_debug_info_allowed_ GUARDED_BY_CONTEXT(sequence_checker_) =
  110. false;
  111. };
  112. } // namespace feedback
  113. #endif // COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_