| 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 #include "components/feedback/feedback_common.h" | 5 #include "components/feedback/feedback_common.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "components/feedback/proto/common.pb.h" | 11 #include "components/feedback/proto/common.pb.h" |
| 12 #include "components/feedback/proto/dom.pb.h" | 12 #include "components/feedback/proto/dom.pb.h" |
| 13 #include "components/feedback/proto/extension.pb.h" | 13 #include "components/feedback/proto/extension.pb.h" |
| 14 #include "components/feedback/proto/math.pb.h" | 14 #include "components/feedback/proto/math.pb.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 #if defined(OS_CHROMEOS) |
| 19 constexpr int kChromeOSProductId = 208; |
| 20 #else |
| 21 constexpr int kChromeBrowserProductId = 237; |
| 22 #endif |
| 23 |
| 18 const char kMultilineIndicatorString[] = "<multiline>\n"; | 24 const char kMultilineIndicatorString[] = "<multiline>\n"; |
| 19 const char kMultilineStartString[] = "---------- START ----------\n"; | 25 const char kMultilineStartString[] = "---------- START ----------\n"; |
| 20 const char kMultilineEndString[] = "---------- END ----------\n\n"; | 26 const char kMultilineEndString[] = "---------- END ----------\n\n"; |
| 21 | 27 |
| 22 const size_t kFeedbackMaxLength = 4 * 1024; | 28 const size_t kFeedbackMaxLength = 4 * 1024; |
| 23 const size_t kFeedbackMaxLineCount = 40; | 29 const size_t kFeedbackMaxLineCount = 40; |
| 24 | 30 |
| 25 const base::FilePath::CharType kLogsFilename[] = | 31 const base::FilePath::CharType kLogsFilename[] = |
| 26 FILE_PATH_LITERAL("system_logs.txt"); | 32 FILE_PATH_LITERAL("system_logs.txt"); |
| 27 const char kLogsAttachmentName[] = "system_logs.zip"; | 33 const char kLogsAttachmentName[] = "system_logs.zip"; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 98 } |
| 93 | 99 |
| 94 } // namespace | 100 } // namespace |
| 95 | 101 |
| 96 FeedbackCommon::AttachedFile::AttachedFile(const std::string& filename, | 102 FeedbackCommon::AttachedFile::AttachedFile(const std::string& filename, |
| 97 std::unique_ptr<std::string> data) | 103 std::unique_ptr<std::string> data) |
| 98 : name(filename), data(std::move(data)) {} | 104 : name(filename), data(std::move(data)) {} |
| 99 | 105 |
| 100 FeedbackCommon::AttachedFile::~AttachedFile() {} | 106 FeedbackCommon::AttachedFile::~AttachedFile() {} |
| 101 | 107 |
| 102 | 108 FeedbackCommon::FeedbackCommon() : product_id_(-1) {} |
| 103 FeedbackCommon::FeedbackCommon() : product_id_(0) {} | |
| 104 | 109 |
| 105 FeedbackCommon::~FeedbackCommon() {} | 110 FeedbackCommon::~FeedbackCommon() {} |
| 106 | 111 |
| 107 // static | 112 // static |
| 108 bool FeedbackCommon::BelowCompressionThreshold(const std::string& content) { | 113 bool FeedbackCommon::BelowCompressionThreshold(const std::string& content) { |
| 109 if (content.length() > kFeedbackMaxLength) | 114 if (content.length() > kFeedbackMaxLength) |
| 110 return false; | 115 return false; |
| 111 const size_t line_count = std::count(content.begin(), content.end(), '\n'); | 116 const size_t line_count = std::count(content.begin(), content.end(), '\n'); |
| 112 if (line_count > kFeedbackMaxLineCount) | 117 if (line_count > kFeedbackMaxLineCount) |
| 113 return false; | 118 return false; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 for (size_t i = 0; i < attachments(); i++) { | 180 for (size_t i = 0; i < attachments(); i++) { |
| 176 const AttachedFile* file = attachment(i); | 181 const AttachedFile* file = attachment(i); |
| 177 AddAttachment(feedback_data, file->name.c_str(), *file->data.get()); | 182 AddAttachment(feedback_data, file->name.c_str(), *file->data.get()); |
| 178 } | 183 } |
| 179 } | 184 } |
| 180 | 185 |
| 181 void FeedbackCommon::PrepareReport( | 186 void FeedbackCommon::PrepareReport( |
| 182 userfeedback::ExtensionSubmit* feedback_data) const { | 187 userfeedback::ExtensionSubmit* feedback_data) const { |
| 183 // Unused field, needs to be 0 though. | 188 // Unused field, needs to be 0 though. |
| 184 feedback_data->set_type_id(0); | 189 feedback_data->set_type_id(0); |
| 185 feedback_data->set_product_id(product_id_); | 190 |
| 191 // Set whether we're reporting from ChromeOS or Chrome on another platform. |
| 192 userfeedback::ChromeData chrome_data; |
| 193 #if defined(OS_CHROMEOS) |
| 194 const userfeedback::ChromeData_ChromePlatform chrome_platform = |
| 195 userfeedback::ChromeData_ChromePlatform_CHROME_OS; |
| 196 const int default_product_id = kChromeOSProductId; |
| 197 userfeedback::ChromeOsData chrome_os_data; |
| 198 chrome_os_data.set_category( |
| 199 userfeedback::ChromeOsData_ChromeOsCategory_OTHER); |
| 200 *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; |
| 201 #else |
| 202 const userfeedback::ChromeData_ChromePlatform chrome_platform = |
| 203 userfeedback::ChromeData_ChromePlatform_CHROME_BROWSER; |
| 204 const int default_product_id = kChromeBrowserProductId; |
| 205 userfeedback::ChromeBrowserData chrome_browser_data; |
| 206 chrome_browser_data.set_category( |
| 207 userfeedback::ChromeBrowserData_ChromeBrowserCategory_OTHER); |
| 208 *(chrome_data.mutable_chrome_browser_data()) = chrome_browser_data; |
| 209 #endif // defined(OS_CHROMEOS) |
| 210 chrome_data.set_chrome_platform(chrome_platform); |
| 211 *(feedback_data->mutable_chrome_data()) = chrome_data; |
| 212 |
| 213 feedback_data->set_product_id(HasProductId() ? product_id_ |
| 214 : default_product_id); |
| 186 | 215 |
| 187 userfeedback::CommonData* common_data = feedback_data->mutable_common_data(); | 216 userfeedback::CommonData* common_data = feedback_data->mutable_common_data(); |
| 188 // We're not using gaia ids, we're using the e-mail field instead. | 217 // We're not using gaia ids, we're using the e-mail field instead. |
| 189 common_data->set_gaia_id(0); | 218 common_data->set_gaia_id(0); |
| 190 common_data->set_user_email(user_email()); | 219 common_data->set_user_email(user_email()); |
| 191 common_data->set_description(description()); | 220 common_data->set_description(description()); |
| 192 common_data->set_source_description_language(locale()); | 221 common_data->set_source_description_language(locale()); |
| 193 | 222 |
| 194 userfeedback::WebData* web_data = feedback_data->mutable_web_data(); | 223 userfeedback::WebData* web_data = feedback_data->mutable_web_data(); |
| 195 web_data->set_url(page_url()); | 224 web_data->set_url(page_url()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 209 | 238 |
| 210 *(screenshot.mutable_dimensions()) = dimensions; | 239 *(screenshot.mutable_dimensions()) = dimensions; |
| 211 screenshot.set_binary_content(*image()); | 240 screenshot.set_binary_content(*image()); |
| 212 | 241 |
| 213 *(feedback_data->mutable_screenshot()) = screenshot; | 242 *(feedback_data->mutable_screenshot()) = screenshot; |
| 214 } | 243 } |
| 215 | 244 |
| 216 if (category_tag().size()) | 245 if (category_tag().size()) |
| 217 feedback_data->set_bucket(category_tag()); | 246 feedback_data->set_bucket(category_tag()); |
| 218 } | 247 } |
| OLD | NEW |