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

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 review comments by ncarter and grunell. 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 <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
18 namespace {
19
20 #if defined(OS_ANDROID)
21 const int kMaxNumberLogFiles = 3;
22 #else
23 const int kMaxNumberLogFiles = 10;
24 #endif
25
26 // Appends the IDs to the RTC event log file name.
27 base::FilePath GetWebRtcEventLogPath(const base::FilePath& base_file,
28 int render_process_id,
29 int connection_id) {
30 return base_file.AddExtension(base::IntToString(render_process_id))
31 .AddExtension(base::IntToString(connection_id));
32 }
33
34 // Opens a logfile to pass on to the renderer.
35 IPC::PlatformFileForTransit CreateFileForProcess(
36 const base::FilePath& base_path,
37 int render_process_id,
38 int connection_id) {
39 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
40 base::FilePath file_path =
41 GetWebRtcEventLogPath(base_path, render_process_id, connection_id);
42 base::File event_log_file(
43 file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND);
44 if (!event_log_file.IsValid()) {
45 VLOG(1) << "Could not open WebRTC event log file, error="
tommi (sloooow) - chröme 2016/05/25 15:16:20 LOGP(ERROR)?
Ivo-OOO until feb 6 2016/05/30 15:04:14 Done.
46 << event_log_file.error_details();
47 return IPC::InvalidPlatformFileForTransit();
48 }
49 return IPC::TakePlatformFileForTransit(std::move(event_log_file));
50 }
51
52 void SendEventLogFileToRenderer(content::RenderProcessHost* rph,
53 int local_id,
54 IPC::PlatformFileForTransit file_for_transit) {
55 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) {
tommi (sloooow) - chröme 2016/05/25 15:16:20 nit: skip {} in these cases. it makes the code sli
Ivo-OOO until feb 6 2016/05/30 15:04:14 Done.
56 return;
57 }
58 rph->Send(
59 new PeerConnectionTracker_StartEventLog(local_id, file_for_transit));
60 }
61
62 } // namespace
63
64 WebRTCEventLogHost::WebRTCEventLogHost(int render_process_id)
65 : render_process_id_(render_process_id),
66 number_active_log_files_(0),
67 is_rtc_event_logging_in_progress_(false) {
68 thread_checker_.DetachFromThread();
69 }
70
71 WebRTCEventLogHost::~WebRTCEventLogHost() {}
72
73 void WebRTCEventLogHost::PeerConnectionAdded(int connection_id) {
74 DCHECK(thread_checker_.CalledOnValidThread());
75 DCHECK(active_peer_connection_local_id_.count(connection_id) == 0);
76 active_peer_connection_local_id_.insert(connection_id);
77 if (is_rtc_event_logging_in_progress_ &&
78 number_active_log_files_ < kMaxNumberLogFiles) {
79 content::RenderProcessHost* host =
80 content::RenderProcessHost::FromID(render_process_id_);
81 if (host) {
82 BrowserThread::PostTaskAndReplyWithResult(
83 BrowserThread::FILE, FROM_HERE,
84 base::Bind(&CreateFileForProcess, base_file_path_, render_process_id_,
85 connection_id),
86 base::Bind(&SendEventLogFileToRenderer, host, connection_id));
87 ++number_active_log_files_;
88 }
89 }
90 }
91
92 void WebRTCEventLogHost::PeerConnectionRemoved(int connection_id) {
93 DCHECK(thread_checker_.CalledOnValidThread());
94 DCHECK(active_peer_connection_local_id_.count(connection_id) == 1);
95 active_peer_connection_local_id_.erase(connection_id);
96 }
97
98 bool WebRTCEventLogHost::StartWebRTCEventLog(const base::FilePath& file_path) {
99 DCHECK(thread_checker_.CalledOnValidThread());
100 if (is_rtc_event_logging_in_progress_)
101 return false;
102 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_);
103 if (host) {
104 is_rtc_event_logging_in_progress_ = true;
105 base_file_path_ = file_path;
106 number_active_log_files_ = 0;
107 for (int local_id : active_peer_connection_local_id_) {
108 if (number_active_log_files_ < kMaxNumberLogFiles) {
109 BrowserThread::PostTaskAndReplyWithResult(
110 BrowserThread::FILE, FROM_HERE,
111 base::Bind(&CreateFileForProcess, file_path, render_process_id_,
112 local_id),
113 base::Bind(&SendEventLogFileToRenderer, host, local_id));
114 number_active_log_files_++;
tommi (sloooow) - chröme 2016/05/25 15:16:20 ++foo
Ivo-OOO until feb 6 2016/05/30 15:04:14 Done.
115 }
116 }
117 }
118 return true;
119 }
120
121 bool WebRTCEventLogHost::StopWebRTCEventLog() {
122 DCHECK(thread_checker_.CalledOnValidThread());
123 if (!is_rtc_event_logging_in_progress_)
124 return false;
125 is_rtc_event_logging_in_progress_ = false;
126 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id_);
127 if (host) {
128 for (int local_id : active_peer_connection_local_id_) {
tommi (sloooow) - chröme 2016/05/25 15:16:20 nit: can skip {}
Ivo-OOO until feb 6 2016/05/30 15:04:14 Done.
129 host->Send(new PeerConnectionTracker_StopEventLog(local_id));
130 }
131 }
132 return true;
133 }
134
135 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698