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

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

Issue 1871533002: Change WebRTC log callback registration in browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review (olka) Created 4 years, 8 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
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_logging_handler_host.h" 5 #include "chrome/browser/media/webrtc_logging_handler_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 void WebRtcLogBuffer::SetComplete() { 141 void WebRtcLogBuffer::SetComplete() {
142 DCHECK(thread_checker_.CalledOnValidThread()); 142 DCHECK(thread_checker_.CalledOnValidThread());
143 DCHECK(!read_only_) << "Already set? (programmer error)"; 143 DCHECK(!read_only_) << "Already set? (programmer error)";
144 read_only_ = true; 144 read_only_ = true;
145 // Detach from the current thread so that we can check reads on a different 145 // Detach from the current thread so that we can check reads on a different
146 // thread. This is to make sure that Read()s still happen on one thread only. 146 // thread. This is to make sure that Read()s still happen on one thread only.
147 thread_checker_.DetachFromThread(); 147 thread_checker_.DetachFromThread();
148 } 148 }
149 149
150 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost( 150 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost(
151 int render_process_id,
151 Profile* profile, 152 Profile* profile,
152 WebRtcLogUploader* log_uploader) 153 WebRtcLogUploader* log_uploader)
153 : BrowserMessageFilter(WebRtcLoggingMsgStart), 154 : BrowserMessageFilter(WebRtcLoggingMsgStart),
154 profile_(profile), 155 profile_(profile),
155 logging_state_(CLOSED), 156 logging_state_(CLOSED),
156 upload_log_on_render_close_(false), 157 upload_log_on_render_close_(false),
157 log_uploader_(log_uploader), 158 log_uploader_(log_uploader),
158 is_audio_debug_recordings_in_progress_(false), 159 is_audio_debug_recordings_in_progress_(false),
159 current_audio_debug_recordings_id_(0) { 160 current_audio_debug_recordings_id_(0),
161 render_process_id_(render_process_id) {
160 DCHECK(profile_); 162 DCHECK(profile_);
161 DCHECK(log_uploader_); 163 DCHECK(log_uploader_);
162 } 164 }
163 165
164 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { 166 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() {
165 // If we hit this, then we might be leaking a log reference count (see 167 // If we hit this, then we might be leaking a log reference count (see
166 // ApplyForStartLogging). 168 // ApplyForStartLogging).
167 DCHECK_EQ(CLOSED, logging_state_); 169 DCHECK_EQ(CLOSED, logging_state_);
168 } 170 }
169 171
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DCHECK_CURRENTLY_ON(BrowserThread::IO); 229 DCHECK_CURRENTLY_ON(BrowserThread::IO);
228 DCHECK(!callback.is_null()); 230 DCHECK(!callback.is_null());
229 231
230 if (logging_state_ != STARTED) { 232 if (logging_state_ != STARTED) {
231 FireGenericDoneCallback(callback, false, "Logging not started."); 233 FireGenericDoneCallback(callback, false, "Logging not started.");
232 return; 234 return;
233 } 235 }
234 236
235 stop_callback_ = callback; 237 stop_callback_ = callback;
236 logging_state_ = STOPPING; 238 logging_state_ = STOPPING;
239
237 Send(new WebRtcLoggingMsg_StopLogging()); 240 Send(new WebRtcLoggingMsg_StopLogging());
241
242 BrowserThread::PostTask(
243 BrowserThread::UI, FROM_HERE,
244 base::Bind(
245 &WebRtcLoggingHandlerHost::DisableBrowserProcessLoggingOnUIThread,
246 this));
238 } 247 }
239 248
240 void WebRtcLoggingHandlerHost::UploadLog(const UploadDoneCallback& callback) { 249 void WebRtcLoggingHandlerHost::UploadLog(const UploadDoneCallback& callback) {
241 DCHECK_CURRENTLY_ON(BrowserThread::IO); 250 DCHECK_CURRENTLY_ON(BrowserThread::IO);
242 DCHECK(!callback.is_null()); 251 DCHECK(!callback.is_null());
243 252
244 if (logging_state_ != STOPPED) { 253 if (logging_state_ != STOPPED) {
245 if (!callback.is_null()) { 254 if (!callback.is_null()) {
246 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 255 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
247 base::Bind(callback, false, "", kLogNotStoppedOrNoLogOpen)); 256 base::Bind(callback, false, "", kLogNotStoppedOrNoLogOpen));
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 557
549 void WebRtcLoggingHandlerHost::LogInitialInfoOnIOThread( 558 void WebRtcLoggingHandlerHost::LogInitialInfoOnIOThread(
550 const net::NetworkInterfaceList& network_list, 559 const net::NetworkInterfaceList& network_list,
551 const GenericDoneCallback& callback) { 560 const GenericDoneCallback& callback) {
552 DCHECK_CURRENTLY_ON(BrowserThread::IO); 561 DCHECK_CURRENTLY_ON(BrowserThread::IO);
553 if (logging_state_ != STARTING) { 562 if (logging_state_ != STARTING) {
554 FireGenericDoneCallback(callback, false, "Logging cancelled."); 563 FireGenericDoneCallback(callback, false, "Logging cancelled.");
555 return; 564 return;
556 } 565 }
557 566
567 // Tell the renderer and the browser to enable logging. Log messages are
568 // recevied on the IO thread, so the initial info will finish to be written
569 // first.
570 Send(new WebRtcLoggingMsg_StartLogging());
571 BrowserThread::PostTask(
572 BrowserThread::UI, FROM_HERE,
573 base::Bind(
574 &WebRtcLoggingHandlerHost::EnableBrowserProcessLoggingOnUIThread,
575 this));
576
558 // Log start time (current time). We don't use base/i18n/time_formatting.h 577 // Log start time (current time). We don't use base/i18n/time_formatting.h
559 // here because we don't want the format of the current locale. 578 // here because we don't want the format of the current locale.
560 base::Time::Exploded now = {0}; 579 base::Time::Exploded now = {0};
561 base::Time::Now().LocalExplode(&now); 580 base::Time::Now().LocalExplode(&now);
562 LogToCircularBuffer(base::StringPrintf( 581 LogToCircularBuffer(base::StringPrintf(
563 "Start %d-%02d-%02d %02d:%02d:%02d", now.year, now.month, 582 "Start %d-%02d-%02d %02d:%02d:%02d", now.year, now.month,
564 now.day_of_month, now.hour, now.minute, now.second)); 583 now.day_of_month, now.hour, now.minute, now.second));
565 584
566 // Write metadata if received before logging started. 585 // Write metadata if received before logging started.
567 if (meta_data_.get() && !meta_data_->empty()) { 586 if (meta_data_.get() && !meta_data_->empty()) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 LogToCircularBuffer("Discovered " + base::SizeTToString(network_list.size()) + 644 LogToCircularBuffer("Discovered " + base::SizeTToString(network_list.size()) +
626 " network interfaces:"); 645 " network interfaces:");
627 for (net::NetworkInterfaceList::const_iterator it = network_list.begin(); 646 for (net::NetworkInterfaceList::const_iterator it = network_list.begin();
628 it != network_list.end(); ++it) { 647 it != network_list.end(); ++it) {
629 LogToCircularBuffer( 648 LogToCircularBuffer(
630 "Name: " + it->friendly_name + ", Address: " + 649 "Name: " + it->friendly_name + ", Address: " +
631 IPAddressToSensitiveString(it->address) + ", Type: " + 650 IPAddressToSensitiveString(it->address) + ", Type: " +
632 net::NetworkChangeNotifier::ConnectionTypeToString(it->type)); 651 net::NetworkChangeNotifier::ConnectionTypeToString(it->type));
633 } 652 }
634 653
635 Send(new WebRtcLoggingMsg_StartLogging());
636 logging_started_time_ = base::Time::Now(); 654 logging_started_time_ = base::Time::Now();
637 logging_state_ = STARTED; 655 logging_state_ = STARTED;
638 FireGenericDoneCallback(callback, true, ""); 656 FireGenericDoneCallback(callback, true, "");
639 } 657 }
640 658
659 void WebRtcLoggingHandlerHost::EnableBrowserProcessLoggingOnUIThread() {
660 DCHECK_CURRENTLY_ON(BrowserThread::UI);
661 content::RenderProcessHost* host =
662 content::RenderProcessHost::FromID(render_process_id_);
663 if (host) {
664 host->SetWebRtcLogMessageCallback(
665 base::Bind(&WebRtcLoggingHandlerHost::LogMessage, this));
666 }
667 }
668
669 void WebRtcLoggingHandlerHost::DisableBrowserProcessLoggingOnUIThread() {
670 DCHECK_CURRENTLY_ON(BrowserThread::UI);
671 content::RenderProcessHost* host =
672 content::RenderProcessHost::FromID(render_process_id_);
673 if (host)
674 host->ClearWebRtcLogMessageCallback();
675 }
676
641 void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) { 677 void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) {
642 DCHECK_CURRENTLY_ON(BrowserThread::IO); 678 DCHECK_CURRENTLY_ON(BrowserThread::IO);
643 DCHECK_NE(logging_state_, CLOSED); 679 DCHECK_NE(logging_state_, CLOSED);
644 log_buffer_->Log(message); 680 log_buffer_->Log(message);
645 } 681 }
646 682
647 base::FilePath WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists() { 683 base::FilePath WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists() {
648 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 684 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
649 base::FilePath log_dir_path = 685 base::FilePath log_dir_path =
650 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()); 686 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 899
864 if (!is_audio_debug_recordings_in_progress_) { 900 if (!is_audio_debug_recordings_in_progress_) {
865 error_callback.Run("No audio debug recording in progress"); 901 error_callback.Run("No audio debug recording in progress");
866 return; 902 return;
867 } 903 }
868 904
869 host->DisableAudioDebugRecordings(); 905 host->DisableAudioDebugRecordings();
870 is_audio_debug_recordings_in_progress_ = false; 906 is_audio_debug_recordings_in_progress_ = false;
871 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop); 907 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop);
872 } 908 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_logging_handler_host.h ('k') | content/browser/renderer_host/media/media_stream_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698