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

Side by Side Diff: content/browser/media/webrtc/webrtc_eventlog_host.cc

Issue 1855193002: Move the call to enable the WebRTC event log from PeerConnectionFactory to PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from Henrik and enabled logging for newly created render processes. Created 4 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
OLDNEW
(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 <algorithm>
8 #include <string>
9
10 #include "base/files/file_util.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "content/browser/media/webrtc/webrtc_internals.h"
13 #include "content/common/media/peer_connection_tracker_messages.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_process_host.h"
16
17 namespace content {
18
19 int WebRTCEventLogHost::number_active_log_files_ = 0;
20
21 namespace {
22
23 #if defined(OS_ANDROID)
24 const int kMaxNumberLogFiles = 3;
25 #else
26 const int kMaxNumberLogFiles = 5;
27 #endif
28
29 // Appends the IDs to the RTC event log file name.
30 base::FilePath GetWebRtcEventLogPath(const base::FilePath& base_file,
31 int render_process_id,
32 int connection_id) {
33 return base_file.AddExtension(base::IntToString(render_process_id))
34 .AddExtension(base::IntToString(connection_id));
35 }
36
37 // Opens a logfile to pass on to the renderer.
38 IPC::PlatformFileForTransit CreateFileForProcess(
39 const base::FilePath& base_path,
40 int render_process_id,
41 int connection_id) {
42 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
43 base::FilePath file_path =
44 GetWebRtcEventLogPath(base_path, render_process_id, connection_id);
45 base::File event_log_file(
46 file_path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
47 if (!event_log_file.IsValid()) {
48 PLOG(ERROR) << "Could not open WebRTC event log file, error="
49 << event_log_file.error_details();
50 return IPC::InvalidPlatformFileForTransit();
51 }
52 return IPC::TakePlatformFileForTransit(std::move(event_log_file));
53 }
54
55 } // namespace
56
57 WebRTCEventLogHost::WebRTCEventLogHost(int render_process_id)
58 : render_process_id_(render_process_id),
59 rtc_event_logging_enabled_(false),
60 weak_ptr_factory_(this) {
61 DCHECK_CURRENTLY_ON(BrowserThread::UI);
62 auto webrtc_internals = WebRTCInternals::GetInstance();
63 if (webrtc_internals->IsEventLogRecordingsEnabled())
64 StartWebRTCEventLog(webrtc_internals->GetEventLogFilePath());
65 }
66
67 WebRTCEventLogHost::~WebRTCEventLogHost() {}
68
69 void WebRTCEventLogHost::PeerConnectionAdded(int peer_connection_local_id) {
70 DCHECK_CURRENTLY_ON(BrowserThread::UI);
71 DCHECK(std::find(active_peer_connection_local_ids_.begin(),
72 active_peer_connection_local_ids_.end(),
73 peer_connection_local_id) ==
74 active_peer_connection_local_ids_.end());
75 active_peer_connection_local_ids_.push_back(peer_connection_local_id);
76 if (rtc_event_logging_enabled_ &&
77 number_active_log_files_ < kMaxNumberLogFiles) {
78 DoStartEventLog(peer_connection_local_id);
79 }
80 }
81
82 void WebRTCEventLogHost::PeerConnectionRemoved(int peer_connection_local_id) {
83 DCHECK_CURRENTLY_ON(BrowserThread::UI);
84 const auto found = std::find(active_peer_connection_local_ids_.begin(),
85 active_peer_connection_local_ids_.end(),
86 peer_connection_local_id);
87 DCHECK(found != active_peer_connection_local_ids_.end());
88 active_peer_connection_local_ids_.erase(found);
89 }
90
91 bool WebRTCEventLogHost::StartWebRTCEventLog(const base::FilePath& file_path) {
Henrik Grunell 2016/06/03 07:40:52 Why did the thread check go away? You should have
Ivo-OOO until feb 6 2016/06/03 16:07:01 Done.
92 if (rtc_event_logging_enabled_)
93 return false;
94 rtc_event_logging_enabled_ = true;
95 base_file_path_ = file_path;
96 for (int local_id : active_peer_connection_local_ids_) {
97 DoStartEventLog(local_id);
Henrik Grunell 2016/06/03 07:40:52 Nit: Name function "StartEventLogForPeerConnection
Ivo-OOO until feb 6 2016/06/03 16:07:02 Done.
98 }
99 return true;
100 }
101
102 bool WebRTCEventLogHost::StopWebRTCEventLog() {
103 if (!rtc_event_logging_enabled_)
104 return false;
105 rtc_event_logging_enabled_ = false;
106 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_);
107 if (host) {
108 for (int local_id : active_peer_connection_local_ids_)
109 host->Send(new PeerConnectionTracker_StopEventLog(local_id));
110 }
111 return true;
112 }
113
114 bool WebRTCEventLogHost::DoStartEventLog(int peer_connection_local_id) {
115 if (number_active_log_files_ < kMaxNumberLogFiles) {
Henrik Grunell 2016/06/03 07:40:52 OK, moving the counter increase causes a problem w
Ivo-OOO until feb 6 2016/06/03 16:07:01 Good catch, thanks.
116 BrowserThread::PostTaskAndReplyWithResult(
117 BrowserThread::FILE, FROM_HERE,
118 base::Bind(&CreateFileForProcess, base_file_path_, render_process_id_,
119 peer_connection_local_id),
120 base::Bind(&WebRTCEventLogHost::SendEventLogFileToRenderer,
121 weak_ptr_factory_.GetWeakPtr(), peer_connection_local_id));
122 }
123 return true;
124 }
125
126 void WebRTCEventLogHost::SendEventLogFileToRenderer(
127 int peer_connection_local_id,
128 IPC::PlatformFileForTransit file_for_transit) {
129 if (file_for_transit == IPC::InvalidPlatformFileForTransit())
130 return;
131 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id_);
132 if (rph) {
133 rph->Send(new PeerConnectionTracker_StartEventLog(peer_connection_local_id,
134 file_for_transit));
135 ++number_active_log_files_;
136 } else {
137 IPC::PlatformFileForTransitToFile(file_for_transit).Close();
Henrik Grunell 2016/06/03 07:40:52 Great that you're closing it here.
138 }
139 }
140
141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698