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

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: 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 LogToCircularBuffer("Discovered " + base::SizeTToString(network_list.size()) + 634 LogToCircularBuffer("Discovered " + base::SizeTToString(network_list.size()) +
626 " network interfaces:"); 635 " network interfaces:");
627 for (net::NetworkInterfaceList::const_iterator it = network_list.begin(); 636 for (net::NetworkInterfaceList::const_iterator it = network_list.begin();
628 it != network_list.end(); ++it) { 637 it != network_list.end(); ++it) {
629 LogToCircularBuffer( 638 LogToCircularBuffer(
630 "Name: " + it->friendly_name + ", Address: " + 639 "Name: " + it->friendly_name + ", Address: " +
631 IPAddressToSensitiveString(it->address) + ", Type: " + 640 IPAddressToSensitiveString(it->address) + ", Type: " +
632 net::NetworkChangeNotifier::ConnectionTypeToString(it->type)); 641 net::NetworkChangeNotifier::ConnectionTypeToString(it->type));
633 } 642 }
634 643
644 BrowserThread::PostTask(
o1ka 2016/04/07 13:00:11 Probably move it to the top to have less chances t
tommi (sloooow) - chröme 2016/04/07 13:52:19 Won't that introduce a potential race with writing
Henrik Grunell 2016/04/07 14:32:59 It won't race, since this function and LogMessage(
645 BrowserThread::UI, FROM_HERE,
646 base::Bind(
647 &WebRtcLoggingHandlerHost::EnableBrowserProcessLoggingOnUIThread,
648 this));
649
635 Send(new WebRtcLoggingMsg_StartLogging()); 650 Send(new WebRtcLoggingMsg_StartLogging());
636 logging_started_time_ = base::Time::Now(); 651 logging_started_time_ = base::Time::Now();
637 logging_state_ = STARTED; 652 logging_state_ = STARTED;
638 FireGenericDoneCallback(callback, true, ""); 653 FireGenericDoneCallback(callback, true, "");
639 } 654 }
640 655
656 void WebRtcLoggingHandlerHost::EnableBrowserProcessLoggingOnUIThread() {
657 DCHECK_CURRENTLY_ON(BrowserThread::UI);
658 content::RenderProcessHost* host =
659 content::RenderProcessHost::FromID(render_process_id_);
660 if (host) {
661 host->SetWebRtcLogMessageCallback(
o1ka 2016/04/07 13:00:11 What guarantees that |host| is still alive here (i
tommi (sloooow) - chröme 2016/04/07 13:52:19 FromID() must be called on the UI thread, it retur
Henrik Grunell 2016/04/07 14:32:59 Yes. Actually, I don't think we should spam with a
662 base::Bind(&WebRtcLoggingHandlerHost::LogMessage, this));
663 }
664 }
665
666 void WebRtcLoggingHandlerHost::DisableBrowserProcessLoggingOnUIThread() {
667 DCHECK_CURRENTLY_ON(BrowserThread::UI);
668 content::RenderProcessHost* host =
669 content::RenderProcessHost::FromID(render_process_id_);
670 if (host)
671 host->UnsetWebRtcLogMessageCallback();
tommi (sloooow) - chröme 2016/04/07 12:51:44 could this possibly 'unset' a callback that was no
o1ka 2016/04/07 13:00:11 What guarantees that |host| is still alive here (i
Henrik Grunell 2016/04/07 13:34:53 This can't happen. These two functions are only ca
tommi (sloooow) - chröme 2016/04/07 13:52:19 From the code, it looks like it's at least theorat
tommi (sloooow) - chröme 2016/04/07 13:52:19 On 2016/04/07 13:34:53, Henrik Grunell wrote: http
Henrik Grunell 2016/04/07 14:32:59 No it's no applicable. In fact, the callback will
Henrik Grunell 2016/04/07 14:32:59 Hmm, in MSM it's OK to call several times, as a co
672 }
673
641 void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) { 674 void WebRtcLoggingHandlerHost::LogToCircularBuffer(const std::string& message) {
642 DCHECK_CURRENTLY_ON(BrowserThread::IO); 675 DCHECK_CURRENTLY_ON(BrowserThread::IO);
643 DCHECK_NE(logging_state_, CLOSED); 676 DCHECK_NE(logging_state_, CLOSED);
644 log_buffer_->Log(message); 677 log_buffer_->Log(message);
645 } 678 }
646 679
647 base::FilePath WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists() { 680 base::FilePath WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists() {
648 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 681 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
649 base::FilePath log_dir_path = 682 base::FilePath log_dir_path =
650 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()); 683 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 896
864 if (!is_audio_debug_recordings_in_progress_) { 897 if (!is_audio_debug_recordings_in_progress_) {
865 error_callback.Run("No audio debug recording in progress"); 898 error_callback.Run("No audio debug recording in progress");
866 return; 899 return;
867 } 900 }
868 901
869 host->DisableAudioDebugRecordings(); 902 host->DisableAudioDebugRecordings();
870 is_audio_debug_recordings_in_progress_ = false; 903 is_audio_debug_recordings_in_progress_ = false;
871 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop); 904 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop);
872 } 905 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698