Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/media/webrtc_log_uploader.h" | 5 #include "chrome/browser/media/webrtc_log_uploader.h" |
| 6 | 6 |
| 7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/pickle.h" | |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/media/webrtc_log_list.h" | 17 #include "chrome/browser/media/webrtc_log_list.h" |
| 17 #include "chrome/browser/media/webrtc_log_util.h" | 18 #include "chrome/browser/media/webrtc_log_util.h" |
| 18 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 19 #include "chrome/common/partial_circular_buffer.h" | 20 #include "chrome/common/partial_circular_buffer.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 42 post_data->append(kMultipartBoundary); | 43 post_data->append(kMultipartBoundary); |
| 43 post_data->append("\r\nContent-Disposition: form-data; name=\""); | 44 post_data->append("\r\nContent-Disposition: form-data; name=\""); |
| 44 post_data->append(content_name); | 45 post_data->append(content_name); |
| 45 post_data->append("\"; filename=\""); | 46 post_data->append("\"; filename=\""); |
| 46 post_data->append(content_name + ".gz"); | 47 post_data->append(content_name + ".gz"); |
| 47 post_data->append("\"\r\nContent-Type: application/gzip\r\n\r\n"); | 48 post_data->append("\"\r\nContent-Type: application/gzip\r\n\r\n"); |
| 48 } | 49 } |
| 49 | 50 |
| 50 // Adds |compressed_log| to |post_data|. | 51 // Adds |compressed_log| to |post_data|. |
| 51 void AddLogData(std::string* post_data, | 52 void AddLogData(std::string* post_data, |
| 52 const std::vector<uint8>& compressed_log) { | 53 const std::string& compressed_log) { |
| 53 AddMultipartFileContentHeader(post_data, "webrtc_log"); | 54 AddMultipartFileContentHeader(post_data, "webrtc_log"); |
| 54 post_data->append(reinterpret_cast<const char*>(&compressed_log[0]), | 55 post_data->append(compressed_log); |
| 55 compressed_log.size()); | |
| 56 post_data->append("\r\n"); | 56 post_data->append("\r\n"); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Adds the RTP dump data to |post_data|. | 59 // Adds the RTP dump data to |post_data|. |
| 60 void AddRtpDumpData(std::string* post_data, | 60 void AddRtpDumpData(std::string* post_data, |
| 61 const std::string& name, | 61 const std::string& name, |
| 62 const std::string& dump_data) { | 62 const std::string& dump_data) { |
| 63 AddMultipartFileContentHeader(post_data, name); | 63 AddMultipartFileContentHeader(post_data, name); |
| 64 post_data->append(dump_data.data(), dump_data.size()); | 64 post_data->append(dump_data.data(), dump_data.size()); |
| 65 post_data->append("\r\n"); | 65 post_data->append("\r\n"); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 } | 129 } |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void WebRtcLogUploader::LoggingStoppedDontUpload() { | 133 void WebRtcLogUploader::LoggingStoppedDontUpload() { |
| 134 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 134 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 135 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); | 135 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void WebRtcLogUploader::LoggingStoppedDoUpload( | 138 void WebRtcLogUploader::LoggingStoppedDoUpload( |
| 139 scoped_ptr<unsigned char[]> log_buffer, | 139 scoped_ptr<WebRtcLogBuffer> log_buffer, |
| 140 uint32 length, | 140 scoped_ptr<MetaDataMap> meta_data, |
| 141 const std::map<std::string, std::string>& meta_data, | |
| 142 const WebRtcLogUploadDoneData& upload_done_data) { | 141 const WebRtcLogUploadDoneData& upload_done_data) { |
| 143 DCHECK(file_thread_checker_.CalledOnValidThread()); | 142 DCHECK(file_thread_checker_.CalledOnValidThread()); |
| 144 DCHECK(log_buffer.get()); | 143 DCHECK(log_buffer.get()); |
| 144 DCHECK(meta_data.get()); | |
| 145 DCHECK(!upload_done_data.log_path.empty()); | 145 DCHECK(!upload_done_data.log_path.empty()); |
| 146 | 146 |
| 147 std::vector<uint8> compressed_log; | 147 std::string compressed_log; |
| 148 CompressLog( | 148 CompressLog(&compressed_log, log_buffer.get()); |
| 149 &compressed_log, reinterpret_cast<uint8*>(&log_buffer[0]), length); | |
| 150 | 149 |
| 151 std::string local_log_id; | 150 std::string local_log_id; |
| 152 | 151 |
| 153 if (base::PathExists(upload_done_data.log_path)) { | 152 if (base::PathExists(upload_done_data.log_path)) { |
| 154 WebRtcLogUtil::DeleteOldWebRtcLogFiles(upload_done_data.log_path); | 153 WebRtcLogUtil::DeleteOldWebRtcLogFiles(upload_done_data.log_path); |
| 155 | 154 |
| 156 local_log_id = base::DoubleToString(base::Time::Now().ToDoubleT()); | 155 local_log_id = base::DoubleToString(base::Time::Now().ToDoubleT()); |
| 157 base::FilePath log_file_path = | 156 base::FilePath log_file_path = |
| 158 upload_done_data.log_path.AppendASCII(local_log_id) | 157 upload_done_data.log_path.AppendASCII(local_log_id) |
| 159 .AddExtension(FILE_PATH_LITERAL(".gz")); | 158 .AddExtension(FILE_PATH_LITERAL(".gz")); |
| 160 WriteCompressedLogToFile(compressed_log, log_file_path); | 159 WriteCompressedLogToFile(compressed_log, log_file_path); |
| 161 | 160 |
| 162 base::FilePath log_list_path = | 161 base::FilePath log_list_path = |
| 163 WebRtcLogList::GetWebRtcLogListFileForDirectory( | 162 WebRtcLogList::GetWebRtcLogListFileForDirectory( |
| 164 upload_done_data.log_path); | 163 upload_done_data.log_path); |
| 165 AddLocallyStoredLogInfoToUploadListFile(log_list_path, local_log_id); | 164 AddLocallyStoredLogInfoToUploadListFile(log_list_path, local_log_id); |
| 166 } | 165 } |
| 167 | 166 |
| 168 WebRtcLogUploadDoneData upload_done_data_with_log_id = upload_done_data; | 167 WebRtcLogUploadDoneData upload_done_data_with_log_id = upload_done_data; |
| 169 upload_done_data_with_log_id.local_log_id = local_log_id; | 168 upload_done_data_with_log_id.local_log_id = local_log_id; |
| 169 UploadCompressedLog(compressed_log, meta_data.Pass(), | |
| 170 upload_done_data_with_log_id); | |
| 171 } | |
| 172 | |
| 173 void WebRtcLogUploader::UploadCompressedLog( | |
| 174 const std::string& compressed_log, | |
| 175 scoped_ptr<MetaDataMap> meta_data, | |
| 176 const WebRtcLogUploadDoneData& upload_done_data) { | |
| 177 DCHECK(file_thread_checker_.CalledOnValidThread()); | |
| 178 DCHECK(!compressed_log.empty()); | |
| 179 DCHECK(meta_data.get()); | |
| 170 | 180 |
| 171 scoped_ptr<std::string> post_data(new std::string()); | 181 scoped_ptr<std::string> post_data(new std::string()); |
| 172 SetupMultipart(post_data.get(), | 182 SetupMultipart(post_data.get(), |
| 173 compressed_log, | 183 compressed_log, |
| 174 upload_done_data.incoming_rtp_dump, | 184 upload_done_data.incoming_rtp_dump, |
| 175 upload_done_data.outgoing_rtp_dump, | 185 upload_done_data.outgoing_rtp_dump, |
| 176 meta_data); | 186 *meta_data.get()); |
| 177 | 187 |
| 178 // If a test has set the test string pointer, write to it and skip uploading. | 188 // If a test has set the test string pointer, write to it and skip uploading. |
| 179 // Still fire the upload callback so that we can run an extension API test | 189 // Still fire the upload callback so that we can run an extension API test |
| 180 // using the test framework for that without hanging. | 190 // using the test framework for that without hanging. |
| 181 // TODO(grunell): Remove this when the api test for this feature is fully | 191 // TODO(grunell): Remove this when the api test for this feature is fully |
| 182 // implemented according to the test plan. http://crbug.com/257329. | 192 // implemented according to the test plan. http://crbug.com/257329. |
| 183 if (post_data_) { | 193 if (post_data_) { |
| 184 *post_data_ = *post_data; | 194 *post_data_ = *post_data; |
| 185 NotifyUploadDone(kHttpResponseOk, "", upload_done_data_with_log_id); | 195 NotifyUploadDone(kHttpResponseOk, "", upload_done_data); |
| 186 return; | 196 return; |
| 187 } | 197 } |
| 188 | 198 |
| 189 content::BrowserThread::PostTask( | 199 content::BrowserThread::PostTask( |
| 190 content::BrowserThread::UI, | 200 content::BrowserThread::UI, |
| 191 FROM_HERE, | 201 FROM_HERE, |
| 192 base::Bind(&WebRtcLogUploader::CreateAndStartURLFetcher, | 202 base::Bind(&WebRtcLogUploader::CreateAndStartURLFetcher, |
| 193 base::Unretained(this), | 203 base::Unretained(this), |
| 194 upload_done_data_with_log_id, | 204 upload_done_data, |
| 195 Passed(&post_data))); | 205 Passed(&post_data))); |
| 196 | 206 |
| 197 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 207 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 198 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); | 208 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); |
| 199 } | 209 } |
| 200 | 210 |
| 211 void WebRtcLogUploader::UploadStoredLog( | |
| 212 const WebRtcLogUploadDoneData& upload_data) { | |
| 213 DCHECK(file_thread_checker_.CalledOnValidThread()); | |
| 214 DCHECK(!upload_data.local_log_id.empty()); | |
| 215 DCHECK(!upload_data.log_path.empty()); | |
| 216 | |
| 217 base::FilePath native_log_path = | |
| 218 upload_data.log_path.AppendASCII(upload_data.local_log_id) | |
| 219 .AddExtension(FILE_PATH_LITERAL(".gz")); | |
| 220 | |
| 221 std::string compressed_log; | |
| 222 if (!base::ReadFileToString(native_log_path, &compressed_log)) { | |
| 223 DPLOG(WARNING) << "Could not read WebRTC log file."; | |
| 224 content::BrowserThread::PostTask( | |
| 225 content::BrowserThread::UI, FROM_HERE, | |
| 226 base::Bind(upload_data.callback, false, "", "Log doesn't exist.")); | |
| 227 return; | |
| 228 } | |
| 229 | |
| 230 WebRtcLogUploadDoneData upload_data_with_rtp = upload_data; | |
| 231 | |
| 232 // Optimistically set the rtp paths to what they should be if they exist. | |
| 233 upload_data_with_rtp.incoming_rtp_dump = | |
| 234 upload_data.log_path.AppendASCII(upload_data.local_log_id) | |
| 235 .AddExtension(FILE_PATH_LITERAL(".rtp_in")); | |
| 236 | |
| 237 upload_data_with_rtp.outgoing_rtp_dump = | |
| 238 upload_data.log_path.AppendASCII(upload_data.local_log_id) | |
| 239 .AddExtension(FILE_PATH_LITERAL(".rtp_out")); | |
| 240 | |
| 241 scoped_ptr<MetaDataMap> meta_data(new MetaDataMap()); | |
| 242 { | |
| 243 std::string meta_data_contents; | |
| 244 base::FilePath meta_path = | |
| 245 upload_data.log_path.AppendASCII(upload_data.local_log_id) | |
| 246 .AddExtension(FILE_PATH_LITERAL(".meta")); | |
| 247 if (base::ReadFileToString(meta_path, &meta_data_contents) && | |
| 248 !meta_data_contents.empty()) { | |
| 249 Pickle pickle(&meta_data_contents[0], meta_data_contents.size()); | |
| 250 PickleIterator it(pickle); | |
| 251 std::string key, value; | |
| 252 while (it.ReadString(&key) && it.ReadString(&value)) | |
| 253 (*meta_data.get())[key] = value; | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 UploadCompressedLog(compressed_log, meta_data.Pass(), upload_data_with_rtp); | |
| 258 } | |
| 259 | |
| 260 void WebRtcLogUploader::LoggingStoppedDoStore( | |
| 261 const WebRtcLogPaths& log_paths, | |
| 262 const std::string& log_id, | |
| 263 scoped_ptr<WebRtcLogBuffer> log_buffer, | |
| 264 scoped_ptr<MetaDataMap> meta_data, | |
| 265 const WebRtcLoggingHandlerHost::GenericDoneCallback& done_callback) { | |
| 266 DCHECK(file_thread_checker_.CalledOnValidThread()); | |
| 267 DCHECK(!log_id.empty()); | |
| 268 DCHECK(log_buffer.get()); | |
| 269 DCHECK(!log_paths.log_path.empty()); | |
| 270 | |
| 271 WebRtcLogUtil::DeleteOldWebRtcLogFiles(log_paths.log_path); | |
| 272 | |
| 273 base::FilePath log_list_path = | |
| 274 WebRtcLogList::GetWebRtcLogListFileForDirectory(log_paths.log_path); | |
| 275 | |
| 276 // Store the native log with a ".gz" extension. | |
| 277 std::string compressed_log; | |
| 278 CompressLog(&compressed_log, log_buffer.get()); | |
| 279 base::FilePath native_log_path = log_paths.log_path.AppendASCII(log_id) | |
| 280 .AddExtension(FILE_PATH_LITERAL(".gz")); | |
| 281 WriteCompressedLogToFile(compressed_log, native_log_path); | |
| 282 AddLocallyStoredLogInfoToUploadListFile(log_list_path, log_id); | |
| 283 | |
| 284 // Move the rtp dump files to the log directory with a name of | |
| 285 // <log id>.rtp_[in|out]. | |
| 286 if (!log_paths.incoming_rtp_dump.empty()) { | |
| 287 base::FilePath rtp_path = log_paths.log_path.AppendASCII(log_id) | |
| 288 .AddExtension(FILE_PATH_LITERAL(".rtp_in")); | |
| 289 base::Move(log_paths.incoming_rtp_dump, rtp_path); | |
| 290 } | |
| 291 | |
| 292 if (!log_paths.outgoing_rtp_dump.empty()) { | |
| 293 base::FilePath rtp_path = log_paths.log_path.AppendASCII(log_id) | |
| 294 .AddExtension(FILE_PATH_LITERAL(".rtp_out")); | |
| 295 base::Move(log_paths.outgoing_rtp_dump, rtp_path); | |
| 296 } | |
| 297 | |
| 298 if (meta_data.get() && !meta_data->empty()) { | |
| 299 Pickle pickle; | |
| 300 for (const auto& it : *meta_data.get()) { | |
| 301 pickle.WriteString(it.first); | |
| 302 pickle.WriteString(it.second); | |
| 303 } | |
| 304 base::FilePath meta_path = log_paths.log_path.AppendASCII(log_id) | |
| 305 .AddExtension(FILE_PATH_LITERAL(".meta")); | |
| 306 base::WriteFile(meta_path, static_cast<const char*>(pickle.data()), | |
| 307 pickle.size()); | |
| 308 } | |
| 309 | |
| 310 content::BrowserThread::PostTask( | |
| 311 content::BrowserThread::UI, FROM_HERE, | |
| 312 base::Bind(done_callback, true, "")); | |
| 313 } | |
| 314 | |
| 201 void WebRtcLogUploader::StartShutdown() { | 315 void WebRtcLogUploader::StartShutdown() { |
| 202 DCHECK(create_thread_checker_.CalledOnValidThread()); | 316 DCHECK(create_thread_checker_.CalledOnValidThread()); |
| 203 DCHECK(!shutting_down_); | 317 DCHECK(!shutting_down_); |
| 204 | 318 |
| 205 // Delete all URLFetchers first and clear the upload done map. | 319 // Delete all URLFetchers first and clear the upload done map. |
| 206 for (UploadDoneDataMap::iterator it = upload_done_data_.begin(); | 320 for (UploadDoneDataMap::iterator it = upload_done_data_.begin(); |
| 207 it != upload_done_data_.end(); | 321 it != upload_done_data_.end(); |
| 208 ++it) { | 322 ++it) { |
| 209 delete it->first; | 323 delete it->first; |
| 210 } | 324 } |
| 211 upload_done_data_.clear(); | 325 upload_done_data_.clear(); |
| 212 shutting_down_ = true; | 326 shutting_down_ = true; |
| 213 } | 327 } |
| 214 | 328 |
| 215 void WebRtcLogUploader::SetupMultipart( | 329 void WebRtcLogUploader::SetupMultipart( |
| 216 std::string* post_data, | 330 std::string* post_data, |
| 217 const std::vector<uint8>& compressed_log, | 331 const std::string& compressed_log, |
| 218 const base::FilePath& incoming_rtp_dump, | 332 const base::FilePath& incoming_rtp_dump, |
| 219 const base::FilePath& outgoing_rtp_dump, | 333 const base::FilePath& outgoing_rtp_dump, |
| 220 const std::map<std::string, std::string>& meta_data) { | 334 const std::map<std::string, std::string>& meta_data) { |
| 221 #if defined(OS_WIN) | 335 #if defined(OS_WIN) |
| 222 const char product[] = "Chrome"; | 336 const char product[] = "Chrome"; |
| 223 #elif defined(OS_MACOSX) | 337 #elif defined(OS_MACOSX) |
| 224 const char product[] = "Chrome_Mac"; | 338 const char product[] = "Chrome_Mac"; |
| 225 #elif defined(OS_LINUX) | 339 #elif defined(OS_LINUX) |
| 226 #if !defined(ADDRESS_SANITIZER) | 340 #if !defined(ADDRESS_SANITIZER) |
| 227 const char product[] = "Chrome_Linux"; | 341 const char product[] = "Chrome_Linux"; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 if (!rtp_dumps[i].empty() && base::PathExists(rtp_dumps[i])) { | 376 if (!rtp_dumps[i].empty() && base::PathExists(rtp_dumps[i])) { |
| 263 std::string dump_data; | 377 std::string dump_data; |
| 264 if (base::ReadFileToString(rtp_dumps[i], &dump_data)) | 378 if (base::ReadFileToString(rtp_dumps[i], &dump_data)) |
| 265 AddRtpDumpData(post_data, kRtpDumpNames[i], dump_data); | 379 AddRtpDumpData(post_data, kRtpDumpNames[i], dump_data); |
| 266 } | 380 } |
| 267 } | 381 } |
| 268 | 382 |
| 269 net::AddMultipartFinalDelimiterForUpload(kMultipartBoundary, post_data); | 383 net::AddMultipartFinalDelimiterForUpload(kMultipartBoundary, post_data); |
| 270 } | 384 } |
| 271 | 385 |
| 272 void WebRtcLogUploader::CompressLog(std::vector<uint8>* compressed_log, | 386 void WebRtcLogUploader::CompressLog(std::string* compressed_log, |
| 273 uint8* input, | 387 WebRtcLogBuffer* buffer) { |
| 274 uint32 input_size) { | |
| 275 PartialCircularBuffer read_pcb(input, input_size); | |
| 276 | |
| 277 z_stream stream = {0}; | 388 z_stream stream = {0}; |
| 278 int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, | 389 int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, |
| 279 // windowBits = 15 is default, 16 is added to | 390 // windowBits = 15 is default, 16 is added to |
| 280 // produce a gzip header + trailer. | 391 // produce a gzip header + trailer. |
| 281 15 + 16, | 392 15 + 16, |
| 282 8, // memLevel = 8 is default. | 393 8, // memLevel = 8 is default. |
| 283 Z_DEFAULT_STRATEGY); | 394 Z_DEFAULT_STRATEGY); |
| 284 DCHECK_EQ(Z_OK, result); | 395 DCHECK_EQ(Z_OK, result); |
| 285 | 396 |
| 286 uint8 intermediate_buffer[kIntermediateCompressionBufferBytes] = {0}; | 397 uint8 intermediate_buffer[kIntermediateCompressionBufferBytes] = {0}; |
| 287 ResizeForNextOutput(compressed_log, &stream); | 398 ResizeForNextOutput(compressed_log, &stream); |
| 288 uint32 read = 0; | 399 uint32 read = 0; |
| 289 | 400 |
| 401 PartialCircularBuffer read_buffer = buffer->Read(); | |
|
perkj_chrome
2015/02/19 11:55:53
nit ()
tommi (sloooow) - chröme
2015/02/19 13:31:40
Done.
| |
| 290 do { | 402 do { |
| 291 if (stream.avail_in == 0) { | 403 if (stream.avail_in == 0) { |
| 292 read = read_pcb.Read(&intermediate_buffer[0], | 404 read = read_buffer.Read(&intermediate_buffer[0], |
| 293 kIntermediateCompressionBufferBytes); | 405 kIntermediateCompressionBufferBytes); |
|
perkj_chrome
2015/02/19 11:55:53
sizeof(intermediate_buffer)
tommi (sloooow) - chröme
2015/02/19 13:31:40
Done.
| |
| 294 stream.next_in = &intermediate_buffer[0]; | 406 stream.next_in = &intermediate_buffer[0]; |
| 295 stream.avail_in = read; | 407 stream.avail_in = read; |
| 296 if (read != kIntermediateCompressionBufferBytes) | 408 if (read != kIntermediateCompressionBufferBytes) |
| 297 break; | 409 break; |
| 298 } | 410 } |
| 299 result = deflate(&stream, Z_SYNC_FLUSH); | 411 result = deflate(&stream, Z_SYNC_FLUSH); |
| 300 DCHECK_EQ(Z_OK, result); | 412 DCHECK_EQ(Z_OK, result); |
| 301 if (stream.avail_out == 0) | 413 if (stream.avail_out == 0) |
| 302 ResizeForNextOutput(compressed_log, &stream); | 414 ResizeForNextOutput(compressed_log, &stream); |
| 303 } while (true); | 415 } while (true); |
| 304 | 416 |
| 305 // Ensure we have enough room in the output buffer. Easier to always just do a | 417 // Ensure we have enough room in the output buffer. Easier to always just do a |
| 306 // resize than looping around and resize if needed. | 418 // resize than looping around and resize if needed. |
| 307 if (stream.avail_out < kIntermediateCompressionBufferBytes) | 419 if (stream.avail_out < kIntermediateCompressionBufferBytes) |
| 308 ResizeForNextOutput(compressed_log, &stream); | 420 ResizeForNextOutput(compressed_log, &stream); |
| 309 | 421 |
| 310 result = deflate(&stream, Z_FINISH); | 422 result = deflate(&stream, Z_FINISH); |
| 311 DCHECK_EQ(Z_STREAM_END, result); | 423 DCHECK_EQ(Z_STREAM_END, result); |
| 312 result = deflateEnd(&stream); | 424 result = deflateEnd(&stream); |
| 313 DCHECK_EQ(Z_OK, result); | 425 DCHECK_EQ(Z_OK, result); |
| 314 | 426 |
| 315 compressed_log->resize(compressed_log->size() - stream.avail_out); | 427 compressed_log->resize(compressed_log->size() - stream.avail_out); |
| 316 } | 428 } |
| 317 | 429 |
| 318 void WebRtcLogUploader::ResizeForNextOutput(std::vector<uint8>* compressed_log, | 430 void WebRtcLogUploader::ResizeForNextOutput(std::string* compressed_log, |
| 319 z_stream* stream) { | 431 z_stream* stream) { |
| 320 size_t old_size = compressed_log->size() - stream->avail_out; | 432 size_t old_size = compressed_log->size() - stream->avail_out; |
| 321 compressed_log->resize(old_size + kIntermediateCompressionBufferBytes); | 433 compressed_log->resize(old_size + kIntermediateCompressionBufferBytes); |
| 322 stream->next_out = &(*compressed_log)[old_size]; | 434 stream->next_out = reinterpret_cast<unsigned char*>( |
| 435 &(*compressed_log)[old_size]); | |
| 323 stream->avail_out = kIntermediateCompressionBufferBytes; | 436 stream->avail_out = kIntermediateCompressionBufferBytes; |
| 324 } | 437 } |
| 325 | 438 |
| 326 void WebRtcLogUploader::CreateAndStartURLFetcher( | 439 void WebRtcLogUploader::CreateAndStartURLFetcher( |
| 327 const WebRtcLogUploadDoneData& upload_done_data, | 440 const WebRtcLogUploadDoneData& upload_done_data, |
| 328 scoped_ptr<std::string> post_data) { | 441 scoped_ptr<std::string> post_data) { |
| 329 DCHECK(create_thread_checker_.CalledOnValidThread()); | 442 DCHECK(create_thread_checker_.CalledOnValidThread()); |
| 330 | 443 |
| 331 if (shutting_down_) | 444 if (shutting_down_) |
| 332 return; | 445 return; |
| 333 | 446 |
| 334 std::string content_type = kUploadContentType; | 447 std::string content_type = kUploadContentType; |
| 335 content_type.append("; boundary="); | 448 content_type.append("; boundary="); |
| 336 content_type.append(kMultipartBoundary); | 449 content_type.append(kMultipartBoundary); |
| 337 | 450 |
| 338 net::URLFetcher* url_fetcher = | 451 net::URLFetcher* url_fetcher = |
| 339 net::URLFetcher::Create(GURL(kUploadURL), net::URLFetcher::POST, this); | 452 net::URLFetcher::Create(GURL(kUploadURL), net::URLFetcher::POST, this); |
| 340 url_fetcher->SetRequestContext(g_browser_process->system_request_context()); | 453 url_fetcher->SetRequestContext(g_browser_process->system_request_context()); |
| 341 url_fetcher->SetUploadData(content_type, *post_data); | 454 url_fetcher->SetUploadData(content_type, *post_data); |
| 342 url_fetcher->Start(); | 455 url_fetcher->Start(); |
| 343 upload_done_data_[url_fetcher] = upload_done_data; | 456 upload_done_data_[url_fetcher] = upload_done_data; |
| 344 } | 457 } |
| 345 | 458 |
| 346 void WebRtcLogUploader::DecreaseLogCount() { | 459 void WebRtcLogUploader::DecreaseLogCount() { |
| 347 DCHECK(create_thread_checker_.CalledOnValidThread()); | 460 DCHECK(create_thread_checker_.CalledOnValidThread()); |
| 348 --log_count_; | 461 --log_count_; |
| 349 } | 462 } |
| 350 | 463 |
| 351 void WebRtcLogUploader::WriteCompressedLogToFile( | 464 void WebRtcLogUploader::WriteCompressedLogToFile( |
| 352 const std::vector<uint8>& compressed_log, | 465 const std::string& compressed_log, |
| 353 const base::FilePath& log_file_path) { | 466 const base::FilePath& log_file_path) { |
| 354 DCHECK(file_thread_checker_.CalledOnValidThread()); | 467 DCHECK(file_thread_checker_.CalledOnValidThread()); |
| 355 DCHECK(!compressed_log.empty()); | 468 DCHECK(!compressed_log.empty()); |
| 356 base::WriteFile(log_file_path, | 469 base::WriteFile(log_file_path, &compressed_log[0], compressed_log.size()); |
| 357 reinterpret_cast<const char*>(&compressed_log[0]), | |
| 358 compressed_log.size()); | |
| 359 } | 470 } |
| 360 | 471 |
| 361 void WebRtcLogUploader::AddLocallyStoredLogInfoToUploadListFile( | 472 void WebRtcLogUploader::AddLocallyStoredLogInfoToUploadListFile( |
| 362 const base::FilePath& upload_list_path, | 473 const base::FilePath& upload_list_path, |
| 363 const std::string& local_log_id) { | 474 const std::string& local_log_id) { |
| 364 DCHECK(file_thread_checker_.CalledOnValidThread()); | 475 DCHECK(file_thread_checker_.CalledOnValidThread()); |
| 365 DCHECK(!upload_list_path.empty()); | 476 DCHECK(!upload_list_path.empty()); |
| 366 DCHECK(!local_log_id.empty()); | 477 DCHECK(!local_log_id.empty()); |
| 367 | 478 |
| 368 std::string contents; | 479 std::string contents; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 if (!success) { | 564 if (!success) { |
| 454 error_message = "Uploading failed, response code: " + | 565 error_message = "Uploading failed, response code: " + |
| 455 base::IntToString(response_code); | 566 base::IntToString(response_code); |
| 456 } | 567 } |
| 457 content::BrowserThread::PostTask( | 568 content::BrowserThread::PostTask( |
| 458 content::BrowserThread::UI, FROM_HERE, | 569 content::BrowserThread::UI, FROM_HERE, |
| 459 base::Bind(upload_done_data.callback, success, report_id, | 570 base::Bind(upload_done_data.callback, success, report_id, |
| 460 error_message)); | 571 error_message)); |
| 461 } | 572 } |
| 462 } | 573 } |
| OLD | NEW |