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