Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 5 #ifndef COMPONENTS_FEEDBACK_FEEDBACK_COMMON_H_ | |
| 6 #define COMPONENTS_FEEDBACK_FEEDBACK_COMMON_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/file_util.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/scoped_vector.h" | |
| 15 #include "base/synchronization/lock.h" | |
| 16 | |
| 17 namespace userfeedback { | |
| 18 class ExtensionSubmit; | |
| 19 } | |
| 20 | |
| 21 namespace feedback_util { | |
| 22 bool ZipString(const base::FilePath& filename, | |
| 23 const std::string& data, | |
| 24 std::string* compressed_data); | |
| 25 } | |
| 26 | |
| 27 // This is the base class for FeedbackData. It primarily knows about | |
| 28 // data common to all feedback reports and how to zip things. | |
| 29 class FeedbackCommon : public base::RefCountedThreadSafe<FeedbackCommon> { | |
| 30 public: | |
| 31 typedef std::map<std::string, std::string> SystemLogsMap; | |
| 32 | |
| 33 struct AttachedFile { | |
| 34 explicit AttachedFile(const std::string& filename); | |
| 35 | |
| 36 std::string name; | |
| 37 std::string data; | |
| 38 }; | |
| 39 | |
| 40 // Determine if the given feedback value is small enough to not need to | |
| 41 // be compressed. | |
| 42 static bool BelowCompressionThreshold(const std::string& content); | |
| 43 | |
| 44 FeedbackCommon(); | |
| 45 | |
| 46 void CompressFile(const base::FilePath& filename, | |
| 47 const std::string& zipname, | |
| 48 scoped_ptr<std::string> data); | |
| 49 void AddFile(const std::string& filename, scoped_ptr<std::string> data); | |
| 50 | |
| 51 void AddLog(const std::string& name, const std::string& value); | |
| 52 void AddLogs(scoped_ptr<SystemLogsMap> logs); | |
| 53 void CompressLogs(); | |
| 54 | |
| 55 void AddFilesAndLogsToReport( | |
| 56 userfeedback::ExtensionSubmit* feedback_data) const; | |
| 57 | |
| 58 // Fill in |feedback_data| with all the data that we have collected. | |
| 59 // CompressLogs() must have already been called. | |
| 60 void PrepareReport(userfeedback::ExtensionSubmit* feedback_data) const; | |
| 61 | |
| 62 // Getters | |
| 63 const std::string& category_tag() const { return category_tag_; } | |
| 64 const std::string& page_url() const { return page_url_; } | |
| 65 const std::string& description() const { return description_; } | |
| 66 const std::string& user_email() const { return user_email_; } | |
| 67 std::string* image() const { return image_.get(); } | |
|
Zachary Kuznia
2014/05/28 21:39:36
const?
achaulk
2014/05/29 17:22:29
Done.
| |
| 68 SystemLogsMap* sys_info() const { return logs_.get(); } | |
|
Zachary Kuznia
2014/05/28 21:39:36
const?
achaulk
2014/05/29 17:22:29
Done.
| |
| 69 int32_t product_id() const { return product_id_; } | |
| 70 std::string user_agent() const { return user_agent_; } | |
| 71 std::string locale() const { return locale_; } | |
| 72 | |
| 73 const AttachedFile* attachment(size_t i) const { return attachments_[i]; } | |
| 74 size_t attachments() const { return attachments_.size(); } | |
| 75 | |
| 76 // Setters | |
| 77 void set_category_tag(const std::string& category_tag) { | |
| 78 category_tag_ = category_tag; | |
| 79 } | |
| 80 void set_page_url(const std::string& page_url) { page_url_ = page_url; } | |
| 81 void set_description(const std::string& description) { | |
| 82 description_ = description; | |
| 83 } | |
| 84 void set_user_email(const std::string& user_email) { | |
| 85 user_email_ = user_email; | |
| 86 } | |
| 87 void set_image(scoped_ptr<std::string> image) { image_ = image.Pass(); } | |
| 88 void set_product_id(int32_t product_id) { product_id_ = product_id; } | |
| 89 void set_user_agent(const std::string& user_agent) { | |
| 90 user_agent_ = user_agent; | |
| 91 } | |
| 92 void set_locale(const std::string& locale) { locale_ = locale; } | |
| 93 | |
| 94 protected: | |
| 95 friend class base::RefCountedThreadSafe<FeedbackCommon>; | |
| 96 friend class FeedbackCommonTest; | |
| 97 | |
| 98 virtual ~FeedbackCommon(); | |
| 99 | |
| 100 private: | |
| 101 std::string category_tag_; | |
| 102 std::string page_url_; | |
| 103 std::string description_; | |
| 104 std::string user_email_; | |
| 105 int32_t product_id_; | |
| 106 std::string user_agent_; | |
| 107 std::string locale_; | |
| 108 | |
| 109 scoped_ptr<std::string> image_; | |
| 110 | |
| 111 // It is possible that multiple attachment add calls are running in | |
| 112 // parallel, so synchronize access. | |
| 113 base::Lock attachments_lock_; | |
| 114 ScopedVector<AttachedFile> attachments_; | |
| 115 | |
| 116 scoped_ptr<SystemLogsMap> logs_; | |
| 117 }; | |
| 118 | |
| 119 #endif // COMPONENTS_FEEDBACK_FEEDBACK_COMMON_H_ | |
| OLD | NEW |