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 COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_ | 5 #ifndef COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_ |
6 #define COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_ | 6 #define COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_ |
7 | 7 |
8 #include <map> | |
9 #include <string> | 8 #include <string> |
10 #include <vector> | |
11 | 9 |
12 #include "base/memory/ref_counted.h" | 10 #include "base/callback.h" |
13 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "components/feedback/feedback_common.h" |
14 #include "url/gurl.h" | 13 #include "url/gurl.h" |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 class FilePath; | 16 class FilePath; |
18 class RefCountedString; | 17 class RefCountedString; |
19 } | 18 } |
20 namespace content { | 19 namespace content { |
21 class BrowserContext; | 20 class BrowserContext; |
22 } | 21 } |
23 | 22 |
24 namespace feedback { | 23 namespace feedback { |
25 | 24 |
26 class FeedbackData : public base::RefCountedThreadSafe<FeedbackData> { | 25 class FeedbackData : public FeedbackCommon { |
27 public: | 26 public: |
28 typedef std::map<std::string, std::string> SystemLogsMap; | |
29 | |
30 // Determine if the given feedback value is small enough to not need to | |
31 // be compressed. | |
32 static bool BelowCompressionThreshold(const std::string& content); | |
33 | |
34 FeedbackData(); | 27 FeedbackData(); |
35 | 28 |
36 // Called once we've updated all the data from the feedback page. | 29 // Called once we've updated all the data from the feedback page. |
37 void OnFeedbackPageDataComplete(); | 30 void OnFeedbackPageDataComplete(); |
38 | 31 |
39 // Sets the system information for this instance and kicks off its | 32 // Sets the system information for this instance and kicks off its |
40 // compression. | 33 // compression. |
41 void SetAndCompressSystemInfo(scoped_ptr<SystemLogsMap> sys_info); | 34 void SetAndCompressSystemInfo(scoped_ptr<SystemLogsMap> sys_info); |
42 | 35 |
43 // Sets the histograms for this instance and kicks off its | 36 // Sets the histograms for this instance and kicks off its |
44 // compression. | 37 // compression. |
45 void SetAndCompressHistograms(scoped_ptr<std::string> histograms); | 38 void SetAndCompressHistograms(scoped_ptr<std::string> histograms); |
46 | 39 |
47 // Sets the attached file data and kicks off its compression. | 40 // Sets the attached file data and kicks off its compression. |
48 void AttachAndCompressFileData(scoped_ptr<std::string> attached_filedata); | 41 void AttachAndCompressFileData(scoped_ptr<std::string> attached_filedata); |
49 | 42 |
50 // Called once we have compressed our system logs. | 43 // Called once we have compressed our system logs. |
51 void OnCompressLogsComplete(scoped_ptr<std::string> compressed_logs); | 44 void OnCompressLogsComplete(scoped_ptr<std::string> compressed_logs); |
52 | 45 |
53 // Called once we have compressed our histograms. | |
54 void OnCompressHistogramsComplete( | |
55 scoped_ptr<std::string> compressed_histograms); | |
56 | |
57 // Called once we have compressed our attached file. | 46 // Called once we have compressed our attached file. |
58 void OnCompressFileComplete(scoped_ptr<std::string> compressed_file); | 47 void OnCompressFileComplete(scoped_ptr<std::string> compressed_file); |
59 | 48 |
60 // Returns true if we've completed all the tasks needed before we can send | 49 // Returns true if we've completed all the tasks needed before we can send |
61 // feedback - at this time this is includes getting the feedback page data | 50 // feedback - at this time this is includes getting the feedback page data |
62 // and compressing the system logs. | 51 // and compressing the system logs. |
63 bool IsDataComplete(); | 52 bool IsDataComplete(); |
64 | 53 |
65 // Sends the feedback report if we have all our data complete. | 54 // Sends the feedback report if we have all our data complete. |
66 void SendReport(); | 55 void SendReport(); |
67 | 56 |
68 // Getters | 57 // Getters |
69 content::BrowserContext* context() const { return context_; } | 58 content::BrowserContext* context() const { return context_; } |
70 const std::string& category_tag() const { return category_tag_; } | |
71 const std::string& page_url() const { return page_url_; } | |
72 const std::string& description() const { return description_; } | |
73 const std::string& user_email() const { return user_email_; } | |
74 std::string* image() const { return image_.get(); } | |
75 const std::string attached_filename() const { return attached_filename_; } | 59 const std::string attached_filename() const { return attached_filename_; } |
76 const std::string attached_file_uuid() const { return attached_file_uuid_; } | 60 const std::string attached_file_uuid() const { return attached_file_uuid_; } |
77 std::string* attached_filedata() const { return attached_filedata_.get(); } | |
78 const std::string screenshot_uuid() const { return screenshot_uuid_; } | 61 const std::string screenshot_uuid() const { return screenshot_uuid_; } |
79 int trace_id() const { return trace_id_; } | 62 int trace_id() const { return trace_id_; } |
80 SystemLogsMap* sys_info() const { return sys_info_.get(); } | |
81 std::string* compressed_logs() const { return compressed_logs_.get(); } | |
82 std::string* histograms() const { return histograms_.get(); } | |
83 std::string* compressed_histograms() const { | |
84 return compressed_histograms_.get(); | |
85 } | |
86 std::string user_agent() const { return user_agent_; } | |
87 std::string locale() const { return locale_; } | |
88 | 63 |
89 // Setters | 64 // Setters |
90 void set_context(content::BrowserContext* context) { context_ = context; } | 65 void set_context(content::BrowserContext* context) { context_ = context; } |
91 void set_category_tag(const std::string& category_tag) { | |
92 category_tag_ = category_tag; | |
93 } | |
94 void set_page_url(const std::string& page_url) { page_url_ = page_url; } | |
95 void set_description(const std::string& description) { | |
96 description_ = description; | |
97 } | |
98 void set_user_email(const std::string& user_email) { | |
99 user_email_ = user_email; | |
100 } | |
101 void set_image(scoped_ptr<std::string> image) { image_ = image.Pass(); } | |
102 void set_attached_filename(const std::string& attached_filename) { | 66 void set_attached_filename(const std::string& attached_filename) { |
103 attached_filename_ = attached_filename; | 67 attached_filename_ = attached_filename; |
104 } | 68 } |
105 void set_attached_file_uuid(const std::string& uuid) { | 69 void set_attached_file_uuid(const std::string& uuid) { |
106 attached_file_uuid_ = uuid; | 70 attached_file_uuid_ = uuid; |
107 } | 71 } |
108 void set_screenshot_uuid(const std::string& uuid) { | 72 void set_screenshot_uuid(const std::string& uuid) { |
109 screenshot_uuid_ = uuid; | 73 screenshot_uuid_ = uuid; |
110 } | 74 } |
111 void set_trace_id(int trace_id) { trace_id_ = trace_id; } | 75 void set_trace_id(int trace_id) { trace_id_ = trace_id; } |
112 void set_user_agent(const std::string& user_agent) { | 76 void set_send_report_callback( |
113 user_agent_ = user_agent; | 77 const base::Callback<void(scoped_refptr<FeedbackData>)>& send_report) { |
| 78 send_report_ = send_report; |
114 } | 79 } |
115 void set_locale(const std::string& locale) { locale_ = locale; } | |
116 | 80 |
117 private: | 81 private: |
118 friend class base::RefCountedThreadSafe<FeedbackData>; | 82 virtual ~FeedbackData(); |
119 | 83 |
120 virtual ~FeedbackData(); | 84 // Called once a compression operation is complete. |
| 85 void OnCompressComplete(); |
121 | 86 |
122 void OnGetTraceData(int trace_id, | 87 void OnGetTraceData(int trace_id, |
123 scoped_refptr<base::RefCountedString> trace_data); | 88 scoped_refptr<base::RefCountedString> trace_data); |
124 | 89 |
| 90 base::Callback<void(scoped_refptr<FeedbackData>)> send_report_; |
| 91 |
125 content::BrowserContext* context_; | 92 content::BrowserContext* context_; |
126 | 93 |
127 std::string category_tag_; | |
128 std::string page_url_; | |
129 std::string description_; | |
130 std::string user_email_; | |
131 scoped_ptr<std::string> image_; | |
132 std::string attached_filename_; | 94 std::string attached_filename_; |
133 scoped_ptr<std::string> attached_filedata_; | |
134 std::string user_agent_; | |
135 std::string locale_; | |
136 | |
137 std::string attached_file_uuid_; | 95 std::string attached_file_uuid_; |
138 std::string screenshot_uuid_; | 96 std::string screenshot_uuid_; |
139 | 97 |
140 int trace_id_; | 98 int trace_id_; |
141 | 99 |
142 scoped_ptr<SystemLogsMap> sys_info_; | 100 int pending_op_count_; |
143 scoped_ptr<std::string> compressed_logs_; | |
144 | |
145 scoped_ptr<std::string> histograms_; | |
146 scoped_ptr<std::string> compressed_histograms_; | |
147 | |
148 // TODO(rkc): Refactor compressing logic into a simpler common implementation. | |
149 bool feedback_page_data_complete_; | |
150 bool syslogs_compression_complete_; | |
151 bool histograms_compression_complete_; | |
152 bool attached_file_compression_complete_; | |
153 bool report_sent_; | 101 bool report_sent_; |
154 | 102 |
155 DISALLOW_COPY_AND_ASSIGN(FeedbackData); | 103 DISALLOW_COPY_AND_ASSIGN(FeedbackData); |
156 }; | 104 }; |
157 | 105 |
158 } // namespace feedback | 106 } // namespace feedback |
159 | 107 |
160 #endif // COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_ | 108 #endif // COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_ |
OLD | NEW |