| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/feedback/feedback_data.h" | 5 #include "chrome/browser/feedback/feedback_data.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 const size_t kFeedbackMaxLength = 4 * 1024; | 32 const size_t kFeedbackMaxLength = 4 * 1024; |
| 33 const size_t kFeedbackMaxLineCount = 40; | 33 const size_t kFeedbackMaxLineCount = 40; |
| 34 | 34 |
| 35 const char kTraceFilename[] = "tracing.zip\n"; | 35 const char kTraceFilename[] = "tracing.zip\n"; |
| 36 const char kPerformanceCategoryTag[] = "Performance"; | 36 const char kPerformanceCategoryTag[] = "Performance"; |
| 37 | 37 |
| 38 const char kZipExt[] = ".zip"; | 38 const char kZipExt[] = ".zip"; |
| 39 | 39 |
| 40 const base::FilePath::CharType kLogsFilename[] = | 40 const base::FilePath::CharType kLogsFilename[] = |
| 41 FILE_PATH_LITERAL("system_logs.txt"); | 41 FILE_PATH_LITERAL("system_logs.txt"); |
| 42 const base::FilePath::CharType kHistogramsFilename[] = |
| 43 FILE_PATH_LITERAL("histograms.txt"); |
| 42 | 44 |
| 43 // Converts the system logs into a string that we can compress and send | 45 // Converts the system logs into a string that we can compress and send |
| 44 // with the report. This method only converts those logs that we want in | 46 // with the report. This method only converts those logs that we want in |
| 45 // the compressed zip file sent with the report, hence it ignores any logs | 47 // the compressed zip file sent with the report, hence it ignores any logs |
| 46 // below the size threshold of what we want compressed. | 48 // below the size threshold of what we want compressed. |
| 47 std::string LogsToString(FeedbackData::SystemLogsMap* sys_info) { | 49 std::string LogsToString(FeedbackData::SystemLogsMap* sys_info) { |
| 48 std::string syslogs_string; | 50 std::string syslogs_string; |
| 49 for (FeedbackData::SystemLogsMap::const_iterator it = sys_info->begin(); | 51 for (FeedbackData::SystemLogsMap::const_iterator it = sys_info->begin(); |
| 50 it != sys_info->end(); ++it) { | 52 it != sys_info->end(); ++it) { |
| 51 std::string key = it->first; | 53 std::string key = it->first; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 80 std::string* compressed_logs) { | 82 std::string* compressed_logs) { |
| 81 DCHECK(compressed_logs); | 83 DCHECK(compressed_logs); |
| 82 std::string logs_string = LogsToString(sys_info); | 84 std::string logs_string = LogsToString(sys_info); |
| 83 if (logs_string.empty() || | 85 if (logs_string.empty() || |
| 84 !feedback_util::ZipString( | 86 !feedback_util::ZipString( |
| 85 base::FilePath(kLogsFilename), logs_string, compressed_logs)) { | 87 base::FilePath(kLogsFilename), logs_string, compressed_logs)) { |
| 86 compressed_logs->clear(); | 88 compressed_logs->clear(); |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 | 91 |
| 92 void ZipHistograms(const std::string& histograms, |
| 93 std::string* compressed_histograms) { |
| 94 DCHECK(compressed_histograms); |
| 95 if (histograms.empty() || |
| 96 !feedback_util::ZipString( |
| 97 base::FilePath(kHistogramsFilename), |
| 98 histograms, |
| 99 compressed_histograms)) { |
| 100 compressed_histograms->clear(); |
| 101 } |
| 102 } |
| 103 |
| 90 } // namespace | 104 } // namespace |
| 91 | 105 |
| 92 // static | 106 // static |
| 93 bool FeedbackData::BelowCompressionThreshold(const std::string& content) { | 107 bool FeedbackData::BelowCompressionThreshold(const std::string& content) { |
| 94 if (content.length() > kFeedbackMaxLength) | 108 if (content.length() > kFeedbackMaxLength) |
| 95 return false; | 109 return false; |
| 96 const size_t line_count = std::count(content.begin(), content.end(), '\n'); | 110 const size_t line_count = std::count(content.begin(), content.end(), '\n'); |
| 97 if (line_count > kFeedbackMaxLineCount) | 111 if (line_count > kFeedbackMaxLineCount) |
| 98 return false; | 112 return false; |
| 99 return true; | 113 return true; |
| 100 } | 114 } |
| 101 | 115 |
| 102 FeedbackData::FeedbackData() : profile_(NULL), | 116 FeedbackData::FeedbackData() : profile_(NULL), |
| 103 trace_id_(0), | 117 trace_id_(0), |
| 104 feedback_page_data_complete_(false), | 118 feedback_page_data_complete_(false), |
| 105 syslogs_compression_complete_(false), | 119 syslogs_compression_complete_(false), |
| 120 histograms_compression_complete_(false), |
| 106 attached_file_compression_complete_(false), | 121 attached_file_compression_complete_(false), |
| 107 report_sent_(false) { | 122 report_sent_(false) { |
| 108 } | 123 } |
| 109 | 124 |
| 110 FeedbackData::~FeedbackData() { | 125 FeedbackData::~FeedbackData() { |
| 111 } | 126 } |
| 112 | 127 |
| 113 void FeedbackData::OnFeedbackPageDataComplete() { | 128 void FeedbackData::OnFeedbackPageDataComplete() { |
| 114 feedback_page_data_complete_ = true; | 129 feedback_page_data_complete_ = true; |
| 115 SendReport(); | 130 SendReport(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 137 FROM_HERE, | 152 FROM_HERE, |
| 138 base::Bind(&ZipLogs, | 153 base::Bind(&ZipLogs, |
| 139 sys_info_.get(), | 154 sys_info_.get(), |
| 140 compressed_logs_ptr), | 155 compressed_logs_ptr), |
| 141 base::Bind(&FeedbackData::OnCompressLogsComplete, | 156 base::Bind(&FeedbackData::OnCompressLogsComplete, |
| 142 this, | 157 this, |
| 143 base::Passed(&compressed_logs))); | 158 base::Passed(&compressed_logs))); |
| 144 } | 159 } |
| 145 } | 160 } |
| 146 | 161 |
| 162 void FeedbackData::SetAndCompressHistograms( |
| 163 const std::string& histograms) { |
| 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 165 |
| 166 histograms_ = histograms; |
| 167 if (!histograms_.empty()) { |
| 168 std::string* compressed_histograms_ptr = new std::string; |
| 169 scoped_ptr<std::string> compressed_histograms(compressed_histograms_ptr); |
| 170 BrowserThread::PostBlockingPoolTaskAndReply( |
| 171 FROM_HERE, |
| 172 base::Bind(&ZipHistograms, |
| 173 histograms_, |
| 174 compressed_histograms_ptr), |
| 175 base::Bind(&FeedbackData::OnCompressHistogramsComplete, |
| 176 this, |
| 177 base::Passed(&compressed_histograms))); |
| 178 } |
| 179 } |
| 180 |
| 147 void FeedbackData::AttachAndCompressFileData( | 181 void FeedbackData::AttachAndCompressFileData( |
| 148 scoped_ptr<std::string> attached_filedata) { | 182 scoped_ptr<std::string> attached_filedata) { |
| 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 150 | 184 |
| 151 attached_filedata_ = attached_filedata.Pass(); | 185 attached_filedata_ = attached_filedata.Pass(); |
| 152 | 186 |
| 153 if (!attached_filename_.empty() && attached_filedata_.get()) { | 187 if (!attached_filename_.empty() && attached_filedata_.get()) { |
| 154 std::string* compressed_file_ptr = new std::string; | 188 std::string* compressed_file_ptr = new std::string; |
| 155 scoped_ptr<std::string> compressed_file(compressed_file_ptr); | 189 scoped_ptr<std::string> compressed_file(compressed_file_ptr); |
| 156 #if defined(OS_WIN) | 190 #if defined(OS_WIN) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 void FeedbackData::OnCompressLogsComplete( | 226 void FeedbackData::OnCompressLogsComplete( |
| 193 scoped_ptr<std::string> compressed_logs) { | 227 scoped_ptr<std::string> compressed_logs) { |
| 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 195 | 229 |
| 196 compressed_logs_ = compressed_logs.Pass(); | 230 compressed_logs_ = compressed_logs.Pass(); |
| 197 syslogs_compression_complete_ = true; | 231 syslogs_compression_complete_ = true; |
| 198 | 232 |
| 199 SendReport(); | 233 SendReport(); |
| 200 } | 234 } |
| 201 | 235 |
| 236 void FeedbackData::OnCompressHistogramsComplete( |
| 237 scoped_ptr<std::string> compressed_histograms) { |
| 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 239 |
| 240 compressed_histograms_ = compressed_histograms.Pass(); |
| 241 histograms_compression_complete_ = true; |
| 242 |
| 243 SendReport(); |
| 244 } |
| 245 |
| 202 void FeedbackData::OnCompressFileComplete( | 246 void FeedbackData::OnCompressFileComplete( |
| 203 scoped_ptr<std::string> compressed_file) { | 247 scoped_ptr<std::string> compressed_file) { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 205 | 249 |
| 206 if (compressed_file.get()) { | 250 if (compressed_file.get()) { |
| 207 attached_filedata_ = compressed_file.Pass(); | 251 attached_filedata_ = compressed_file.Pass(); |
| 208 attached_filename_.append(kZipExt); | 252 attached_filename_.append(kZipExt); |
| 209 attached_file_compression_complete_ = true; | 253 attached_file_compression_complete_ = true; |
| 210 } else { | 254 } else { |
| 211 attached_filename_.clear(); | 255 attached_filename_.clear(); |
| 212 attached_filedata_.reset(NULL); | 256 attached_filedata_.reset(NULL); |
| 213 } | 257 } |
| 214 | 258 |
| 215 SendReport(); | 259 SendReport(); |
| 216 } | 260 } |
| 217 | 261 |
| 218 bool FeedbackData::IsDataComplete() { | 262 bool FeedbackData::IsDataComplete() { |
| 219 return (!sys_info_.get() || syslogs_compression_complete_) && | 263 return (!sys_info_.get() || syslogs_compression_complete_) && |
| 264 (histograms_.empty() || histograms_compression_complete_) && |
| 220 (!attached_filedata_.get() || attached_file_compression_complete_) && | 265 (!attached_filedata_.get() || attached_file_compression_complete_) && |
| 221 !trace_id_ && | 266 !trace_id_ && |
| 222 feedback_page_data_complete_; | 267 feedback_page_data_complete_; |
| 223 } | 268 } |
| 224 | 269 |
| 225 void FeedbackData::SendReport() { | 270 void FeedbackData::SendReport() { |
| 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 227 if (IsDataComplete() && !report_sent_) { | 272 if (IsDataComplete() && !report_sent_) { |
| 228 report_sent_ = true; | 273 report_sent_ = true; |
| 229 feedback_util::SendReport(this); | 274 feedback_util::SendReport(this); |
| 230 } | 275 } |
| 231 } | 276 } |
| OLD | NEW |