Chromium Code Reviews| Index: content/browser/renderer_host/media/media_stream_manager.cc |
| diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc |
| index 6ed73ca48f62b6973c1cdf275b9c355ac32fce38..a93ce4c48056eb368294a09de65a22512756ebc6 100644 |
| --- a/content/browser/renderer_host/media/media_stream_manager.cc |
| +++ b/content/browser/renderer_host/media/media_stream_manager.cc |
| @@ -14,17 +14,20 @@ |
| #include "base/rand_util.h" |
| #include "base/run_loop.h" |
| #include "base/threading/thread.h" |
| +#include "content/browser/browser_main_loop.h" |
| #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| #include "content/browser/renderer_host/media/device_request_message_filter.h" |
| #include "content/browser/renderer_host/media/media_stream_requester.h" |
| #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| #include "content/browser/renderer_host/media/video_capture_manager.h" |
| #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
| +#include "content/browser/renderer_host/render_process_host_impl.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/media_device_id.h" |
| #include "content/public/browser/media_observer.h" |
| #include "content/public/browser/media_request_state.h" |
| +#include "content/public/browser/render_process_host.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/public/common/media_stream_request.h" |
| #include "media/audio/audio_manager_base.h" |
| @@ -36,6 +39,19 @@ |
| #include "base/win/scoped_com_initializer.h" |
| #endif |
| +static void DoAddLogMessage(const std::string& message) { |
|
tommi (sloooow) - chröme
2014/01/24 12:34:54
I think //content prefers anonymous namespaces (ev
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Done.
|
| + // Must be on the UI thread to access BrowserMainLoop. |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + // May be null in tests. |
| + // TODO(vrk): Handle this more elegantly by having native log messages become |
| + // no-ops until MediaStreamManager is aware that a renderer process has |
| + // started logging. crbug.com/333894 |
| + if (content::BrowserMainLoop::GetInstance()) { |
| + content::BrowserMainLoop::GetInstance()-> |
| + media_stream_manager()->AddLogMessageOnUIThread(message); |
| + } |
| +} |
| + |
| namespace content { |
| namespace { |
| @@ -846,6 +862,24 @@ bool MediaStreamManager::TranslateSourceIdToDeviceId( |
| return false; |
| } |
| +void MediaStreamManager::LogDevicesToNativeLogs( |
| + MediaStreamType stream_type, |
| + const StreamDeviceInfoArray& devices) { |
| + std::stringstream devices_msg; |
| + devices_msg << "Devices found for stream type " << stream_type << ":" |
| + << std::endl; |
| + for (StreamDeviceInfoArray::const_iterator it = devices.begin(); |
| + it != devices.end(); ++it) { |
| + devices_msg << " " << it->device.name << " (" |
| + << it->device.id << ")" << std::endl; |
|
no longer working on chromium
2014/01/24 09:54:38
btw, are you supposed to log the device_id? has th
tommi (sloooow) - chröme
2014/01/24 12:34:54
Agreed. To be safe we should either skip logging t
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Removed. (Fwiw I also sent a mail to kaichou@ with
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Done, just omitted.
|
| + } |
| + if (devices.empty()) |
|
no longer working on chromium
2014/01/24 09:54:38
nit, I think it is cleaner to do:
if (devices.empt
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Done.
|
| + devices_msg << "No devices found."; |
| + |
| + DVLOG(1) << devices_msg; |
| + SendMessageToNativeLog(devices_msg.str()); |
| +} |
| + |
| void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { |
| DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
| cache->valid = false; |
| @@ -1014,6 +1048,11 @@ void MediaStreamManager::SetupRequest(const std::string& label) { |
| // Enumerate the devices if there is no valid device lists to be used. |
| StartEnumeration(request); |
| return; |
| + } else { |
| + // Cache is valid, so log the cached devices. |
|
no longer working on chromium
2014/01/24 09:54:38
are you sure you want to log the cache for each Se
no longer working on chromium
2014/01/24 10:36:17
Per pointed out that only media stream requests we
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Thanks for letting me know. I don't think there wi
|
| + SendMessageToNativeLog("Using cached devices for request."); |
|
tommi (sloooow) - chröme
2014/01/24 12:34:54
Would it make sense to aggregate all these message
|
| + LogDevicesToNativeLogs(audio_type, audio_enumeration_cache_.devices); |
| + LogDevicesToNativeLogs(video_type, video_enumeration_cache_.devices); |
|
no longer working on chromium
2014/01/24 09:54:38
what do you log if the type is MEDIA_NO_SERVICE ?
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
See LogDevicesToNativeLogs - it would log the MEDI
|
| } |
| if (!SetupDeviceCaptureRequest(request)) { |
| @@ -1403,7 +1442,10 @@ void MediaStreamManager::DevicesEnumerated( |
| MediaStreamType stream_type, const StreamDeviceInfoArray& devices) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| DVLOG(1) << "DevicesEnumerated(" |
| - << ", {stream_type = " << stream_type << "})"; |
| + << "{stream_type = " << stream_type << "})" << std::endl; |
| + |
| + SendMessageToNativeLog("New device enumeration result:"); |
| + LogDevicesToNativeLogs(stream_type, devices); |
| // Only cache the device list when the device list has been changed. |
| bool need_update_clients = false; |
| @@ -1476,6 +1518,35 @@ void MediaStreamManager::DevicesEnumerated( |
| DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); |
| } |
| +// static |
| +void MediaStreamManager::SendMessageToNativeLog(const std::string& message) { |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
|
no longer working on chromium
2014/01/24 09:54:38
I have some concern on the thread safety here. Pre
tommi (sloooow) - chröme
2014/01/24 12:34:54
Actually, this method is static and the task that
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
I believe so as well, so leaving as is.
|
| + base::Bind(::DoAddLogMessage, message)); |
| +} |
| + |
| +void MediaStreamManager::AddLogMessageOnUIThread(const std::string& message) { |
| + // Must be on the UI thread to access RenderProcessHost from process ID. |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + // Add logs for each pending request. |
| + for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); |
| + ++it) { |
| + DeviceRequest* request = it->second; |
| + // Log the message to all renderers that are requesting a MediaStream or |
|
perkj_chrome
2014/01/24 09:15:10
Can you expand the comment : that are requesting a
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Done.
|
| + // device enumeration. |
| + if (request->request_type == MEDIA_GENERATE_STREAM || |
| + request->request_type == MEDIA_ENUMERATE_DEVICES) { |
|
perkj_chrome
2014/01/24 09:15:10
Fyi- MEDIA_ENUMERATE_DEVICES is called by flash fo
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Pepper flash? I don't understand why MediaStreamMa
|
| + content::RenderProcessHostImpl* render_process_host_impl = |
| + static_cast<content::RenderProcessHostImpl*>( |
| + content::RenderProcessHost::FromID( |
| + request->requesting_process_id)); |
| + if (render_process_host_impl) |
| + render_process_host_impl->WebRtcLogMessage(message); |
| + } |
| + } |
| +} |
| + |
| void MediaStreamManager::HandleAccessRequestResponse( |
| const std::string& label, |
| const MediaStreamDevices& devices) { |