Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/media/webrtc/webrtc_eventlog_host.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/files/file_util.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "content/common/media/peer_connection_tracker_messages.h" | |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 #include "content/public/browser/render_process_host.h" | |
| 14 #include "ipc/ipc_platform_file.h" | |
| 15 | |
| 16 namespace content { | |
| 17 namespace { | |
|
Henrik Grunell
2016/05/24 13:31:59
Empty line above.
Ivo-OOO until feb 6
2016/05/25 14:57:00
Done.
| |
| 18 | |
| 19 #if defined(OS_ANDROID) | |
| 20 const int kMaxNumberLogFiles = 3; | |
| 21 #else | |
| 22 const int kMaxNumberLogFiles = 10; | |
| 23 #endif | |
| 24 | |
| 25 // Appends the IDs to the RTC event log file name. | |
| 26 base::FilePath GetWebRtcEventLogPath(const base::FilePath& base_file, | |
| 27 int render_process_id, | |
| 28 int connection_id) { | |
| 29 return base_file.AddExtension(base::IntToString(render_process_id)) | |
| 30 .AddExtension(base::IntToString(connection_id)); | |
| 31 } | |
| 32 | |
| 33 // Opens a logfile to pass on to the renderer. | |
| 34 IPC::PlatformFileForTransit CreateFileForProcess( | |
| 35 const base::FilePath& base_path, | |
| 36 int render_process_id, | |
| 37 int connection_id) { | |
| 38 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
| 39 base::FilePath file_path = | |
| 40 GetWebRtcEventLogPath(base_path, render_process_id, connection_id); | |
| 41 base::File event_log_file( | |
| 42 file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND); | |
| 43 if (!event_log_file.IsValid()) { | |
| 44 VLOG(1) << "Could not open WebRTC event log file, error=" | |
| 45 << event_log_file.error_details(); | |
| 46 return IPC::InvalidPlatformFileForTransit(); | |
| 47 } | |
| 48 return IPC::TakePlatformFileForTransit(std::move(event_log_file)); | |
| 49 } | |
| 50 | |
| 51 void SendEventLogFileToRenderer(content::RenderProcessHost* rph, | |
| 52 int local_id, | |
| 53 IPC::PlatformFileForTransit file_for_transit) { | |
| 54 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) { | |
| 55 return; | |
| 56 } | |
| 57 rph->Send( | |
| 58 new PeerConnectionTracker_StartEventLog(local_id, file_for_transit)); | |
| 59 } | |
| 60 } // namespace | |
|
Henrik Grunell
2016/05/24 13:31:59
Ditto.
Ivo-OOO until feb 6
2016/05/25 14:57:00
Done.
| |
| 61 | |
| 62 WebRTCEventLogHost::WebRTCEventLogHost(int render_process_id) | |
| 63 : render_process_id_(render_process_id), | |
| 64 number_active_log_files_(0), | |
| 65 is_rtc_event_logging_in_progress_(false) { | |
| 66 thread_checker_.DetachFromThread(); | |
| 67 } | |
| 68 | |
| 69 WebRTCEventLogHost::~WebRTCEventLogHost() {} | |
| 70 | |
| 71 void WebRTCEventLogHost::PeerConnectionAdded(int connection_id) { | |
|
Henrik Grunell
2016/05/24 13:31:59
Are these two functions be called on any thread? I
Ivo-OOO until feb 6
2016/05/25 14:57:00
Good point, added thread checker.
| |
| 72 active_peer_connection_local_id_.insert(connection_id); | |
|
Henrik Grunell
2016/05/24 13:31:59
DCHECK that the id isn't already in the set?
Ivo-OOO until feb 6
2016/05/25 14:57:00
std::set contains unique elements, so adding an el
| |
| 73 if (is_rtc_event_logging_in_progress_ && | |
| 74 number_active_log_files_ < kMaxNumberLogFiles) { | |
| 75 content::RenderProcessHost* host = | |
| 76 content::RenderProcessHost::FromID(render_process_id_); | |
| 77 if (host) { | |
| 78 BrowserThread::PostTaskAndReplyWithResult( | |
| 79 BrowserThread::FILE, FROM_HERE, | |
| 80 base::Bind(&CreateFileForProcess, base_file_path_, render_process_id_, | |
| 81 connection_id), | |
| 82 base::Bind(&SendEventLogFileToRenderer, host, connection_id)); | |
| 83 number_active_log_files_++; | |
|
Henrik Grunell
2016/05/24 13:31:59
I don't see this ever being decreased.
Henrik Grunell
2016/05/24 13:31:59
Nit: ++number_active_log_file_;
Ivo-OOO until feb 6
2016/05/25 14:57:00
It is set to zero when the logging is enabled (lin
| |
| 84 } | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 void WebRTCEventLogHost::PeerConnectionRemoved(int connection_id) { | |
| 89 active_peer_connection_local_id_.erase(connection_id); | |
|
Henrik Grunell
2016/05/24 13:31:59
DCHECK that it is actually in the set?
Ivo-OOO until feb 6
2016/05/25 14:57:00
Done.
| |
| 90 } | |
| 91 | |
| 92 bool WebRTCEventLogHost::StartWebRTCEventLog(const base::FilePath& file_path) { | |
| 93 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 94 if (is_rtc_event_logging_in_progress_) | |
| 95 return false; | |
| 96 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_); | |
| 97 if (host) { | |
| 98 is_rtc_event_logging_in_progress_ = true; | |
| 99 base_file_path_ = file_path; | |
| 100 number_active_log_files_ = 0; | |
| 101 for (int local_id : active_peer_connection_local_id_) { | |
| 102 if (number_active_log_files_ < kMaxNumberLogFiles) { | |
| 103 BrowserThread::PostTaskAndReplyWithResult( | |
| 104 BrowserThread::FILE, FROM_HERE, | |
| 105 base::Bind(&CreateFileForProcess, file_path, render_process_id_, | |
| 106 local_id), | |
| 107 base::Bind(&SendEventLogFileToRenderer, host, local_id)); | |
| 108 number_active_log_files_++; | |
| 109 } | |
| 110 } | |
| 111 } | |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 bool WebRTCEventLogHost::StopWebRTCEventLog() { | |
| 116 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 117 if (!is_rtc_event_logging_in_progress_) | |
| 118 return false; | |
| 119 is_rtc_event_logging_in_progress_ = false; | |
| 120 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_); | |
| 121 if (host) { | |
| 122 for (int local_id : active_peer_connection_local_id_) { | |
| 123 host->Send(new PeerConnectionTracker_StopEventLog(local_id)); | |
| 124 } | |
| 125 } | |
| 126 return true; | |
| 127 } | |
| 128 | |
| 129 } // namespace content | |
| OLD | NEW |