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

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: Review comments from Tommi. 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/common/media/peer_connection_tracker_messages.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "ipc/ipc_platform_file.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_OPEN_ALWAYS | base::File::FLAG_APPEND);
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 void SendEventLogFileToRenderer(content::RenderProcessHost* rph,
56 int local_id,
57 IPC::PlatformFileForTransit file_for_transit) {
58 if (file_for_transit == IPC::InvalidPlatformFileForTransit())
59 return;
60
61 rph->Send(
62 new PeerConnectionTracker_StartEventLog(local_id, file_for_transit));
63 }
64
65 } // namespace
66
67 WebRTCEventLogHost::WebRTCEventLogHost(int render_process_id)
68 : render_process_id_(render_process_id), rtc_event_logging_enabled_(false) {
69 DCHECK_CURRENTLY_ON(BrowserThread::UI);
70 }
71
72 WebRTCEventLogHost::~WebRTCEventLogHost() {}
73
74 void WebRTCEventLogHost::PeerConnectionAdded(int peer_connection_local_id) {
75 DCHECK_CURRENTLY_ON(BrowserThread::UI);
76 DCHECK(std::find(active_peer_connection_local_id_.begin(),
77 active_peer_connection_local_id_.end(),
78 peer_connection_local_id) ==
79 active_peer_connection_local_id_.end());
80 active_peer_connection_local_id_.push_back(peer_connection_local_id);
81 if (rtc_event_logging_enabled_ &&
82 number_active_log_files_ < kMaxNumberLogFiles) {
83 content::RenderProcessHost* host =
84 content::RenderProcessHost::FromID(render_process_id_);
85 if (host) {
86 BrowserThread::PostTaskAndReplyWithResult(
87 BrowserThread::FILE, FROM_HERE,
88 base::Bind(&CreateFileForProcess, base_file_path_, render_process_id_,
89 peer_connection_local_id),
90 base::Bind(&SendEventLogFileToRenderer, host,
91 peer_connection_local_id));
92 ++number_active_log_files_;
93 }
94 }
95 }
96
97 void WebRTCEventLogHost::PeerConnectionRemoved(int peer_connection_local_id) {
98 DCHECK_CURRENTLY_ON(BrowserThread::UI);
99 DCHECK(std::find(active_peer_connection_local_id_.begin(),
100 active_peer_connection_local_id_.end(),
101 peer_connection_local_id) !=
102 active_peer_connection_local_id_.end());
103 active_peer_connection_local_id_.erase(std::find(
tommi (sloooow) - chröme 2016/05/31 09:11:22 nit: const auto found = std::find(...); DCHECK(fo
Ivo-OOO until feb 6 2016/06/02 14:43:38 Done.
104 active_peer_connection_local_id_.begin(),
105 active_peer_connection_local_id_.end(), peer_connection_local_id));
106 }
107
108 bool WebRTCEventLogHost::StartWebRTCEventLog(const base::FilePath& file_path) {
109 DCHECK_CURRENTLY_ON(BrowserThread::UI);
110 if (rtc_event_logging_enabled_)
111 return false;
112 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_);
113 if (host) {
114 rtc_event_logging_enabled_ = true;
115 base_file_path_ = file_path;
116 for (int local_id : active_peer_connection_local_id_) {
117 if (number_active_log_files_ < kMaxNumberLogFiles) {
118 BrowserThread::PostTaskAndReplyWithResult(
119 BrowserThread::FILE, FROM_HERE,
120 base::Bind(&CreateFileForProcess, file_path, render_process_id_,
121 local_id),
122 base::Bind(&SendEventLogFileToRenderer, host, local_id));
123 ++number_active_log_files_;
124 }
125 }
126 }
127 return true;
128 }
129
130 bool WebRTCEventLogHost::StopWebRTCEventLog() {
131 DCHECK_CURRENTLY_ON(BrowserThread::UI);
132 if (!rtc_event_logging_enabled_)
133 return false;
134 rtc_event_logging_enabled_ = false;
135 number_active_log_files_ = 0;
136 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_);
137 if (host) {
138 for (int local_id : active_peer_connection_local_id_)
139 host->Send(new PeerConnectionTracker_StopEventLog(local_id));
140 }
141 return true;
142 }
143
144 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/webrtc/webrtc_eventlog_host.h ('k') | content/browser/media/webrtc/webrtc_internals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698