Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/browser/media/webrtc_log_uploader.cc

Issue 299903002: Convert WebRtcLoggingHandlerHost to use the blocking thread pool. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 28 matching lines...) Expand all
39 } // namespace 39 } // namespace
40 40
41 WebRtcLogUploadDoneData::WebRtcLogUploadDoneData() {} 41 WebRtcLogUploadDoneData::WebRtcLogUploadDoneData() {}
42 42
43 WebRtcLogUploadDoneData::~WebRtcLogUploadDoneData() {} 43 WebRtcLogUploadDoneData::~WebRtcLogUploadDoneData() {}
44 44
45 WebRtcLogUploader::WebRtcLogUploader() 45 WebRtcLogUploader::WebRtcLogUploader()
46 : log_count_(0), 46 : log_count_(0),
47 post_data_(NULL), 47 post_data_(NULL),
48 shutting_down_(false) { 48 shutting_down_(false) {
49 file_thread_checker_.DetachFromThread(); 49 blocking_sequence_checker_.DetachFromSequence();
50 } 50 }
51 51
52 WebRtcLogUploader::~WebRtcLogUploader() { 52 WebRtcLogUploader::~WebRtcLogUploader() {
53 DCHECK(create_thread_checker_.CalledOnValidThread()); 53 DCHECK(create_thread_checker_.CalledOnValidThread());
54 DCHECK(upload_done_data_.empty()); 54 DCHECK(upload_done_data_.empty());
55 DCHECK(shutting_down_); 55 DCHECK(shutting_down_);
56 } 56 }
57 57
58 void WebRtcLogUploader::OnURLFetchComplete( 58 void WebRtcLogUploader::OnURLFetchComplete(
59 const net::URLFetcher* source) { 59 const net::URLFetcher* source) {
60 DCHECK(create_thread_checker_.CalledOnValidThread()); 60 DCHECK(create_thread_checker_.CalledOnValidThread());
61 DCHECK(upload_done_data_.find(source) != upload_done_data_.end()); 61 DCHECK(upload_done_data_.find(source) != upload_done_data_.end());
62 DCHECK(!shutting_down_); 62 DCHECK(!shutting_down_);
63 int response_code = source->GetResponseCode(); 63 int response_code = source->GetResponseCode();
64 UploadDoneDataMap::iterator it = upload_done_data_.find(source); 64 UploadDoneDataMap::iterator it = upload_done_data_.find(source);
65 if (it != upload_done_data_.end()) { 65 if (it != upload_done_data_.end()) {
66 // The log path can be empty here if we failed getting it before. We still 66 // The log path can be empty here if we failed getting it before. We still
67 // upload the log if that's the case. 67 // upload the log if that's the case.
68 std::string report_id; 68 std::string report_id;
69 if (response_code == kHttpResponseOk && 69 if (response_code == kHttpResponseOk &&
70 source->GetResponseAsString(&report_id) && 70 source->GetResponseAsString(&report_id) &&
71 !it->second.log_path.empty()) { 71 !it->second.log_path.empty()) {
72 base::FilePath log_list_path = 72 base::FilePath log_list_path =
73 WebRtcLogList::GetWebRtcLogListFileForDirectory(it->second.log_path); 73 WebRtcLogList::GetWebRtcLogListFileForDirectory(it->second.log_path);
74 content::BrowserThread::PostTask( 74 content::BrowserThread::PostBlockingPoolTask(
75 content::BrowserThread::FILE,
76 FROM_HERE, 75 FROM_HERE,
77 base::Bind(&WebRtcLogUploader::AddUploadedLogInfoToUploadListFile, 76 base::Bind(&WebRtcLogUploader::AddUploadedLogInfoToUploadListFile,
78 base::Unretained(this), 77 base::Unretained(this),
79 log_list_path, 78 log_list_path,
80 it->second.local_log_id, 79 it->second.local_log_id,
81 report_id)); 80 report_id));
82 } 81 }
83 NotifyUploadDone(response_code, report_id, it->second); 82 NotifyUploadDone(response_code, report_id, it->second);
84 upload_done_data_.erase(it); 83 upload_done_data_.erase(it);
85 } 84 }
(...skipping 17 matching lines...) Expand all
103 void WebRtcLogUploader::LoggingStoppedDontUpload() { 102 void WebRtcLogUploader::LoggingStoppedDontUpload() {
104 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 103 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
105 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); 104 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this)));
106 } 105 }
107 106
108 void WebRtcLogUploader::LoggingStoppedDoUpload( 107 void WebRtcLogUploader::LoggingStoppedDoUpload(
109 scoped_ptr<unsigned char[]> log_buffer, 108 scoped_ptr<unsigned char[]> log_buffer,
110 uint32 length, 109 uint32 length,
111 const std::map<std::string, std::string>& meta_data, 110 const std::map<std::string, std::string>& meta_data,
112 const WebRtcLogUploadDoneData& upload_done_data) { 111 const WebRtcLogUploadDoneData& upload_done_data) {
113 DCHECK(file_thread_checker_.CalledOnValidThread()); 112 DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread());
114 DCHECK(log_buffer.get()); 113 DCHECK(log_buffer.get());
115 DCHECK(!upload_done_data.log_path.empty()); 114 DCHECK(!upload_done_data.log_path.empty());
116 115
117 std::vector<uint8> compressed_log; 116 std::vector<uint8> compressed_log;
118 CompressLog( 117 CompressLog(
119 &compressed_log, reinterpret_cast<uint8*>(&log_buffer[0]), length); 118 &compressed_log, reinterpret_cast<uint8*>(&log_buffer[0]), length);
120 119
121 std::string local_log_id; 120 std::string local_log_id;
122 121
123 if (base::PathExists(upload_done_data.log_path)) { 122 if (base::PathExists(upload_done_data.log_path)) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 307 }
309 308
310 void WebRtcLogUploader::DecreaseLogCount() { 309 void WebRtcLogUploader::DecreaseLogCount() {
311 DCHECK(create_thread_checker_.CalledOnValidThread()); 310 DCHECK(create_thread_checker_.CalledOnValidThread());
312 --log_count_; 311 --log_count_;
313 } 312 }
314 313
315 void WebRtcLogUploader::WriteCompressedLogToFile( 314 void WebRtcLogUploader::WriteCompressedLogToFile(
316 const std::vector<uint8>& compressed_log, 315 const std::vector<uint8>& compressed_log,
317 const base::FilePath& log_file_path) { 316 const base::FilePath& log_file_path) {
318 DCHECK(file_thread_checker_.CalledOnValidThread()); 317 DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread());
319 DCHECK(!compressed_log.empty()); 318 DCHECK(!compressed_log.empty());
320 base::WriteFile(log_file_path, 319 base::WriteFile(log_file_path,
321 reinterpret_cast<const char*>(&compressed_log[0]), 320 reinterpret_cast<const char*>(&compressed_log[0]),
322 compressed_log.size()); 321 compressed_log.size());
323 } 322 }
324 323
325 void WebRtcLogUploader::AddLocallyStoredLogInfoToUploadListFile( 324 void WebRtcLogUploader::AddLocallyStoredLogInfoToUploadListFile(
326 const base::FilePath& upload_list_path, 325 const base::FilePath& upload_list_path,
327 const std::string& local_log_id) { 326 const std::string& local_log_id) {
328 DCHECK(file_thread_checker_.CalledOnValidThread()); 327 DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread());
329 DCHECK(!upload_list_path.empty()); 328 DCHECK(!upload_list_path.empty());
330 DCHECK(!local_log_id.empty()); 329 DCHECK(!local_log_id.empty());
331 330
332 std::string contents; 331 std::string contents;
333 332
334 if (base::PathExists(upload_list_path)) { 333 if (base::PathExists(upload_list_path)) {
335 if (!base::ReadFileToString(upload_list_path, &contents)) { 334 if (!base::ReadFileToString(upload_list_path, &contents)) {
336 DPLOG(WARNING) << "Could not read WebRTC log list file."; 335 DPLOG(WARNING) << "Could not read WebRTC log list file.";
337 return; 336 return;
338 } 337 }
(...skipping 23 matching lines...) Expand all
362 if (written != static_cast<int>(contents.size())) { 361 if (written != static_cast<int>(contents.size())) {
363 DPLOG(WARNING) << "Could not write all data to WebRTC log list file: " 362 DPLOG(WARNING) << "Could not write all data to WebRTC log list file: "
364 << written; 363 << written;
365 } 364 }
366 } 365 }
367 366
368 void WebRtcLogUploader::AddUploadedLogInfoToUploadListFile( 367 void WebRtcLogUploader::AddUploadedLogInfoToUploadListFile(
369 const base::FilePath& upload_list_path, 368 const base::FilePath& upload_list_path,
370 const std::string& local_log_id, 369 const std::string& local_log_id,
371 const std::string& report_id) { 370 const std::string& report_id) {
372 DCHECK(file_thread_checker_.CalledOnValidThread()); 371 DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread());
373 DCHECK(!upload_list_path.empty()); 372 DCHECK(!upload_list_path.empty());
374 DCHECK(!local_log_id.empty()); 373 DCHECK(!local_log_id.empty());
375 DCHECK(!report_id.empty()); 374 DCHECK(!report_id.empty());
376 375
377 std::string contents; 376 std::string contents;
378 377
379 if (base::PathExists(upload_list_path)) { 378 if (base::PathExists(upload_list_path)) {
380 if (!base::ReadFileToString(upload_list_path, &contents)) { 379 if (!base::ReadFileToString(upload_list_path, &contents)) {
381 DPLOG(WARNING) << "Could not read WebRTC log list file."; 380 DPLOG(WARNING) << "Could not read WebRTC log list file.";
382 return; 381 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (!success) { 416 if (!success) {
418 error_message = "Uploading failed, response code: " + 417 error_message = "Uploading failed, response code: " +
419 base::IntToString(response_code); 418 base::IntToString(response_code);
420 } 419 }
421 content::BrowserThread::PostTask( 420 content::BrowserThread::PostTask(
422 content::BrowserThread::UI, FROM_HERE, 421 content::BrowserThread::UI, FROM_HERE,
423 base::Bind(upload_done_data.callback, success, report_id, 422 base::Bind(upload_done_data.callback, success, report_id,
424 error_message)); 423 error_message));
425 } 424 }
426 } 425 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698