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

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: fix after r273980 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
« no previous file with comments | « chrome/browser/media/webrtc_log_uploader.h ('k') | chrome/browser/media/webrtc_log_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } // namespace 69 } // namespace
70 70
71 WebRtcLogUploadDoneData::WebRtcLogUploadDoneData() {} 71 WebRtcLogUploadDoneData::WebRtcLogUploadDoneData() {}
72 72
73 WebRtcLogUploadDoneData::~WebRtcLogUploadDoneData() {} 73 WebRtcLogUploadDoneData::~WebRtcLogUploadDoneData() {}
74 74
75 WebRtcLogUploader::WebRtcLogUploader() 75 WebRtcLogUploader::WebRtcLogUploader()
76 : log_count_(0), 76 : log_count_(0),
77 post_data_(NULL), 77 post_data_(NULL),
78 shutting_down_(false) { 78 shutting_down_(false) {
79 file_thread_checker_.DetachFromThread(); 79 blocking_sequence_checker_.DetachFromSequence();
80 } 80 }
81 81
82 WebRtcLogUploader::~WebRtcLogUploader() { 82 WebRtcLogUploader::~WebRtcLogUploader() {
83 DCHECK(create_thread_checker_.CalledOnValidThread()); 83 DCHECK(create_thread_checker_.CalledOnValidThread());
84 DCHECK(upload_done_data_.empty()); 84 DCHECK(upload_done_data_.empty());
85 DCHECK(shutting_down_); 85 DCHECK(shutting_down_);
86 } 86 }
87 87
88 void WebRtcLogUploader::OnURLFetchComplete( 88 void WebRtcLogUploader::OnURLFetchComplete(
89 const net::URLFetcher* source) { 89 const net::URLFetcher* source) {
90 DCHECK(create_thread_checker_.CalledOnValidThread()); 90 DCHECK(create_thread_checker_.CalledOnValidThread());
91 DCHECK(upload_done_data_.find(source) != upload_done_data_.end()); 91 DCHECK(upload_done_data_.find(source) != upload_done_data_.end());
92 DCHECK(!shutting_down_); 92 DCHECK(!shutting_down_);
93 int response_code = source->GetResponseCode(); 93 int response_code = source->GetResponseCode();
94 UploadDoneDataMap::iterator it = upload_done_data_.find(source); 94 UploadDoneDataMap::iterator it = upload_done_data_.find(source);
95 if (it != upload_done_data_.end()) { 95 if (it != upload_done_data_.end()) {
96 // The log path can be empty here if we failed getting it before. We still 96 // The log path can be empty here if we failed getting it before. We still
97 // upload the log if that's the case. 97 // upload the log if that's the case.
98 std::string report_id; 98 std::string report_id;
99 if (response_code == kHttpResponseOk && 99 if (response_code == kHttpResponseOk &&
100 source->GetResponseAsString(&report_id) && 100 source->GetResponseAsString(&report_id) &&
101 !it->second.log_path.empty()) { 101 !it->second.log_path.empty()) {
102 // TODO(jiayl): Add the RTP dump records to chrome://webrtc-logs. 102 // TODO(jiayl): Add the RTP dump records to chrome://webrtc-logs.
103 base::FilePath log_list_path = 103 base::FilePath log_list_path =
104 WebRtcLogList::GetWebRtcLogListFileForDirectory(it->second.log_path); 104 WebRtcLogList::GetWebRtcLogListFileForDirectory(it->second.log_path);
105 content::BrowserThread::PostTask( 105 content::BrowserThread::PostBlockingPoolTask(
106 content::BrowserThread::FILE,
107 FROM_HERE, 106 FROM_HERE,
108 base::Bind(&WebRtcLogUploader::AddUploadedLogInfoToUploadListFile, 107 base::Bind(&WebRtcLogUploader::AddUploadedLogInfoToUploadListFile,
109 base::Unretained(this), 108 base::Unretained(this),
110 log_list_path, 109 log_list_path,
111 it->second.local_log_id, 110 it->second.local_log_id,
112 report_id)); 111 report_id));
113 } 112 }
114 NotifyUploadDone(response_code, report_id, it->second); 113 NotifyUploadDone(response_code, report_id, it->second);
115 upload_done_data_.erase(it); 114 upload_done_data_.erase(it);
116 } 115 }
(...skipping 17 matching lines...) Expand all
134 void WebRtcLogUploader::LoggingStoppedDontUpload() { 133 void WebRtcLogUploader::LoggingStoppedDontUpload() {
135 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 134 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
136 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); 135 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this)));
137 } 136 }
138 137
139 void WebRtcLogUploader::LoggingStoppedDoUpload( 138 void WebRtcLogUploader::LoggingStoppedDoUpload(
140 scoped_ptr<unsigned char[]> log_buffer, 139 scoped_ptr<unsigned char[]> log_buffer,
141 uint32 length, 140 uint32 length,
142 const std::map<std::string, std::string>& meta_data, 141 const std::map<std::string, std::string>& meta_data,
143 const WebRtcLogUploadDoneData& upload_done_data) { 142 const WebRtcLogUploadDoneData& upload_done_data) {
144 DCHECK(file_thread_checker_.CalledOnValidThread()); 143 DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread());
145 DCHECK(log_buffer.get()); 144 DCHECK(log_buffer.get());
146 DCHECK(!upload_done_data.log_path.empty()); 145 DCHECK(!upload_done_data.log_path.empty());
147 146
148 std::vector<uint8> compressed_log; 147 std::vector<uint8> compressed_log;
149 CompressLog( 148 CompressLog(
150 &compressed_log, reinterpret_cast<uint8*>(&log_buffer[0]), length); 149 &compressed_log, reinterpret_cast<uint8*>(&log_buffer[0]), length);
151 150
152 std::string local_log_id; 151 std::string local_log_id;
153 152
154 if (base::PathExists(upload_done_data.log_path)) { 153 if (base::PathExists(upload_done_data.log_path)) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 344 }
346 345
347 void WebRtcLogUploader::DecreaseLogCount() { 346 void WebRtcLogUploader::DecreaseLogCount() {
348 DCHECK(create_thread_checker_.CalledOnValidThread()); 347 DCHECK(create_thread_checker_.CalledOnValidThread());
349 --log_count_; 348 --log_count_;
350 } 349 }
351 350
352 void WebRtcLogUploader::WriteCompressedLogToFile( 351 void WebRtcLogUploader::WriteCompressedLogToFile(
353 const std::vector<uint8>& compressed_log, 352 const std::vector<uint8>& compressed_log,
354 const base::FilePath& log_file_path) { 353 const base::FilePath& log_file_path) {
355 DCHECK(file_thread_checker_.CalledOnValidThread()); 354 DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread());
356 DCHECK(!compressed_log.empty()); 355 DCHECK(!compressed_log.empty());
357 base::WriteFile(log_file_path, 356 base::WriteFile(log_file_path,
358 reinterpret_cast<const char*>(&compressed_log[0]), 357 reinterpret_cast<const char*>(&compressed_log[0]),
359 compressed_log.size()); 358 compressed_log.size());
360 } 359 }
361 360
362 void WebRtcLogUploader::AddLocallyStoredLogInfoToUploadListFile( 361 void WebRtcLogUploader::AddLocallyStoredLogInfoToUploadListFile(
363 const base::FilePath& upload_list_path, 362 const base::FilePath& upload_list_path,
364 const std::string& local_log_id) { 363 const std::string& local_log_id) {
365 DCHECK(file_thread_checker_.CalledOnValidThread()); 364 DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread());
366 DCHECK(!upload_list_path.empty()); 365 DCHECK(!upload_list_path.empty());
367 DCHECK(!local_log_id.empty()); 366 DCHECK(!local_log_id.empty());
368 367
369 std::string contents; 368 std::string contents;
370 369
371 if (base::PathExists(upload_list_path)) { 370 if (base::PathExists(upload_list_path)) {
372 if (!base::ReadFileToString(upload_list_path, &contents)) { 371 if (!base::ReadFileToString(upload_list_path, &contents)) {
373 DPLOG(WARNING) << "Could not read WebRTC log list file."; 372 DPLOG(WARNING) << "Could not read WebRTC log list file.";
374 return; 373 return;
375 } 374 }
(...skipping 23 matching lines...) Expand all
399 if (written != static_cast<int>(contents.size())) { 398 if (written != static_cast<int>(contents.size())) {
400 DPLOG(WARNING) << "Could not write all data to WebRTC log list file: " 399 DPLOG(WARNING) << "Could not write all data to WebRTC log list file: "
401 << written; 400 << written;
402 } 401 }
403 } 402 }
404 403
405 void WebRtcLogUploader::AddUploadedLogInfoToUploadListFile( 404 void WebRtcLogUploader::AddUploadedLogInfoToUploadListFile(
406 const base::FilePath& upload_list_path, 405 const base::FilePath& upload_list_path,
407 const std::string& local_log_id, 406 const std::string& local_log_id,
408 const std::string& report_id) { 407 const std::string& report_id) {
409 DCHECK(file_thread_checker_.CalledOnValidThread()); 408 DCHECK(blocking_sequence_checker_.CalledOnValidSequencedThread());
410 DCHECK(!upload_list_path.empty()); 409 DCHECK(!upload_list_path.empty());
411 DCHECK(!local_log_id.empty()); 410 DCHECK(!local_log_id.empty());
412 DCHECK(!report_id.empty()); 411 DCHECK(!report_id.empty());
413 412
414 std::string contents; 413 std::string contents;
415 414
416 if (base::PathExists(upload_list_path)) { 415 if (base::PathExists(upload_list_path)) {
417 if (!base::ReadFileToString(upload_list_path, &contents)) { 416 if (!base::ReadFileToString(upload_list_path, &contents)) {
418 DPLOG(WARNING) << "Could not read WebRTC log list file."; 417 DPLOG(WARNING) << "Could not read WebRTC log list file.";
419 return; 418 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 if (!success) { 453 if (!success) {
455 error_message = "Uploading failed, response code: " + 454 error_message = "Uploading failed, response code: " +
456 base::IntToString(response_code); 455 base::IntToString(response_code);
457 } 456 }
458 content::BrowserThread::PostTask( 457 content::BrowserThread::PostTask(
459 content::BrowserThread::UI, FROM_HERE, 458 content::BrowserThread::UI, FROM_HERE,
460 base::Bind(upload_done_data.callback, success, report_id, 459 base::Bind(upload_done_data.callback, success, report_id,
461 error_message)); 460 error_message));
462 } 461 }
463 } 462 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_log_uploader.h ('k') | chrome/browser/media/webrtc_log_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698