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

Side by Side Diff: content/browser/media/webrtc/webrtc_internals.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 by dcheng. Created 4 years, 8 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/media/webrtc/webrtc_internals.h" 5 #include "content/browser/media/webrtc/webrtc_internals.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "content/browser/media/webrtc/webrtc_internals_ui_observer.h" 11 #include "content/browser/media/webrtc/webrtc_internals_ui_observer.h"
12 #include "content/browser/web_contents/web_contents_view.h" 12 #include "content/browser/web_contents/web_contents_view.h"
13 #include "content/common/media/peer_connection_tracker_messages.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/power_save_blocker.h" 16 #include "content/public/browser/power_save_blocker.h"
16 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "ipc/ipc_platform_file.h"
20
21 #if defined(OS_WIN)
22 #define IntToStringType base::IntToString16
23 #else
24 #define IntToStringType base::IntToString
25 #endif
18 26
19 using base::ProcessId; 27 using base::ProcessId;
20 using std::string; 28 using std::string;
21 29
22 namespace content { 30 namespace content {
23 31
24 namespace { 32 namespace {
25 33
26 static base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = 34 static base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals =
27 LAZY_INSTANCE_INITIALIZER; 35 LAZY_INSTANCE_INITIALIZER;
28 36
29 // Makes sure that |dict| has a ListValue under path "log". 37 // Makes sure that |dict| has a ListValue under path "log".
30 static base::ListValue* EnsureLogList(base::DictionaryValue* dict) { 38 static base::ListValue* EnsureLogList(base::DictionaryValue* dict) {
31 base::ListValue* log = NULL; 39 base::ListValue* log = NULL;
32 if (!dict->GetList("log", &log)) { 40 if (!dict->GetList("log", &log)) {
33 log = new base::ListValue(); 41 log = new base::ListValue();
34 if (log) 42 if (log)
35 dict->Set("log", log); 43 dict->Set("log", log);
36 } 44 }
37 return log; 45 return log;
38 } 46 }
39 47
48 #if defined(ENABLE_WEBRTC)
49 // Creates a file used for handing over to the renderer.
Henrik Grunell 2016/04/07 09:22:33 Webrtc internals is not the right place to handle
Ivo-OOO until feb 6 2016/04/07 12:10:50 Thanks for pointing that out, I was not aware of t
50 IPC::PlatformFileForTransit CreateFileForProcess(
51 const base::FilePath& file_path,
52 base::ProcessHandle process) {
53 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
54 base::File event_log_file(
55 file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND);
56 if (!event_log_file.IsValid()) {
57 VLOG(1) << "Could not open event log file, error="
58 << event_log_file.error_details();
59 return IPC::InvalidPlatformFileForTransit();
60 }
61 return IPC::TakeFileHandleForProcess(std::move(event_log_file), process);
62 }
63
64 void SendEventLogFileToRenderer(int render_process_id,
65 int local_id,
66 IPC::PlatformFileForTransit file_for_transit) {
67 #if defined(OS_ANDROID)
68 const int64_t max_file_size = 10000000;
69 #else
70 const int64_t max_file_size = 30000000;
71 #endif
72 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) {
73 return;
74 }
75 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
76 if (rph) {
77 rph->Send(new PeerConnectionTracker_StartEventLog(
78 local_id, file_for_transit, max_file_size));
79 }
80 }
81 #endif
40 } // namespace 82 } // namespace
41 83
42 WebRTCInternals::PendingUpdate::PendingUpdate( 84 WebRTCInternals::PendingUpdate::PendingUpdate(
43 const std::string& command, scoped_ptr<base::Value> value) 85 const std::string& command, scoped_ptr<base::Value> value)
44 : command_(command), value_(std::move(value)) {} 86 : command_(command), value_(std::move(value)) {}
45 87
46 WebRTCInternals::PendingUpdate::PendingUpdate(PendingUpdate&& other) 88 WebRTCInternals::PendingUpdate::PendingUpdate(PendingUpdate&& other)
47 : command_(std::move(other.command_)), 89 : command_(std::move(other.command_)),
48 value_(std::move(other.value_)) {} 90 value_(std::move(other.value_)) {}
49 91
(...skipping 10 matching lines...) Expand all
60 DCHECK(thread_checker_.CalledOnValidThread()); 102 DCHECK(thread_checker_.CalledOnValidThread());
61 return value_.get(); 103 return value_.get();
62 } 104 }
63 105
64 WebRTCInternals::WebRTCInternals() : WebRTCInternals(500) {} 106 WebRTCInternals::WebRTCInternals() : WebRTCInternals(500) {}
65 107
66 WebRTCInternals::WebRTCInternals(int aggregate_updates_ms) 108 WebRTCInternals::WebRTCInternals(int aggregate_updates_ms)
67 : audio_debug_recordings_(false), 109 : audio_debug_recordings_(false),
68 event_log_recordings_(false), 110 event_log_recordings_(false),
69 selecting_event_log_(false), 111 selecting_event_log_(false),
112 number_event_log_files_(0),
70 aggregate_updates_ms_(aggregate_updates_ms), 113 aggregate_updates_ms_(aggregate_updates_ms),
71 weak_factory_(this) { 114 weak_factory_(this) {
72 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the 115 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the
73 // build if WebRTC is disabled? 116 // build if WebRTC is disabled?
74 #if defined(ENABLE_WEBRTC) 117 #if defined(ENABLE_WEBRTC)
75 audio_debug_recordings_file_path_ = 118 audio_debug_recordings_file_path_ =
76 GetContentClient()->browser()->GetDefaultDownloadDirectory(); 119 GetContentClient()->browser()->GetDefaultDownloadDirectory();
77 event_log_recordings_file_path_ = audio_debug_recordings_file_path_; 120 event_log_recordings_file_path_ = audio_debug_recordings_file_path_;
78 121
79 if (audio_debug_recordings_file_path_.empty()) { 122 if (audio_debug_recordings_file_path_.empty()) {
(...skipping 30 matching lines...) Expand all
110 base::DictionaryValue* dict = new base::DictionaryValue(); 153 base::DictionaryValue* dict = new base::DictionaryValue();
111 dict->SetInteger("rid", render_process_id); 154 dict->SetInteger("rid", render_process_id);
112 dict->SetInteger("pid", static_cast<int>(pid)); 155 dict->SetInteger("pid", static_cast<int>(pid));
113 dict->SetInteger("lid", lid); 156 dict->SetInteger("lid", lid);
114 dict->SetString("rtcConfiguration", rtc_configuration); 157 dict->SetString("rtcConfiguration", rtc_configuration);
115 dict->SetString("constraints", constraints); 158 dict->SetString("constraints", constraints);
116 dict->SetString("url", url); 159 dict->SetString("url", url);
117 peer_connection_data_.Append(dict); 160 peer_connection_data_.Append(dict);
118 CreateOrReleasePowerSaveBlocker(); 161 CreateOrReleasePowerSaveBlocker();
119 162
163 if (event_log_recordings_ && number_event_log_files_ > 0) {
164 number_event_log_files_--;
165 base::FilePath file_path = event_log_recordings_file_path_;
166 file_path = file_path.AddExtension(IntToStringType(render_process_id));
167 file_path = file_path.AddExtension(IntToStringType(lid));
168
169 BrowserThread::PostTaskAndReplyWithResult(
170 BrowserThread::FILE, FROM_HERE,
171 base::Bind(&CreateFileForProcess, file_path,
172 base::GetCurrentProcessHandle()),
173 base::Bind(&SendEventLogFileToRenderer, render_process_id, lid));
174 }
175
120 if (observers_.might_have_observers()) 176 if (observers_.might_have_observers())
121 SendUpdate("addPeerConnection", dict->CreateDeepCopy()); 177 SendUpdate("addPeerConnection", dict->CreateDeepCopy());
122 178
123 if (render_process_id_set_.insert(render_process_id).second) { 179 if (render_process_id_set_.insert(render_process_id).second) {
124 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); 180 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id);
125 if (host) 181 if (host)
126 host->AddObserver(this); 182 host->AddObserver(this);
127 } 183 }
128 } 184 }
129 185
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 DCHECK(select_file_dialog_ == nullptr); 387 DCHECK(select_file_dialog_ == nullptr);
332 selecting_event_log_ = true; 388 selecting_event_log_ = true;
333 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr); 389 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr);
334 select_file_dialog_->SelectFile( 390 select_file_dialog_->SelectFile(
335 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), 391 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(),
336 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""), 392 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""),
337 web_contents->GetTopLevelNativeWindow(), nullptr); 393 web_contents->GetTopLevelNativeWindow(), nullptr);
338 #endif 394 #endif
339 } else { 395 } else {
340 event_log_recordings_ = false; 396 event_log_recordings_ = false;
397 number_event_log_files_ = 0;
341 // Tear down the dialog since the user has unchecked the audio debug 398 // Tear down the dialog since the user has unchecked the audio debug
342 // recordings box. 399 // recordings box.
400 DCHECK(select_file_dialog_->HasOneRef());
343 select_file_dialog_ = nullptr; 401 select_file_dialog_ = nullptr;
344 DCHECK(select_file_dialog_->HasOneRef());
345 402
346 for (RenderProcessHost::iterator i( 403 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) {
347 content::RenderProcessHost::AllHostsIterator()); 404 base::DictionaryValue* record = NULL;
348 !i.IsAtEnd(); i.Advance()) { 405 peer_connection_data_.GetDictionary(i, &record);
349 i.GetCurrentValue()->DisableEventLogRecordings(); 406
407 int rid, lid;
408 record->GetInteger("rid", &rid);
409 record->GetInteger("lid", &lid);
410 auto rph = RenderProcessHost::FromID(rid);
411 if (rph) {
412 rph->Send(new PeerConnectionTracker_StopEventLog(lid));
413 }
350 } 414 }
351 } 415 }
352 #endif 416 #endif
353 } 417 }
354 418
355 bool WebRTCInternals::IsEventLogRecordingsEnabled() const { 419 bool WebRTCInternals::IsEventLogRecordingsEnabled() const {
356 DCHECK_CURRENTLY_ON(BrowserThread::UI); 420 DCHECK_CURRENTLY_ON(BrowserThread::UI);
357 return event_log_recordings_; 421 return event_log_recordings_;
358 } 422 }
359 423
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 scoped_ptr<base::DictionaryValue> update(new base::DictionaryValue()); 524 scoped_ptr<base::DictionaryValue> update(new base::DictionaryValue());
461 update->SetInteger("rid", render_process_id); 525 update->SetInteger("rid", render_process_id);
462 SendUpdate("removeGetUserMediaForRenderer", std::move(update)); 526 SendUpdate("removeGetUserMediaForRenderer", std::move(update));
463 } 527 }
464 } 528 }
465 529
466 #if defined(ENABLE_WEBRTC) 530 #if defined(ENABLE_WEBRTC)
467 void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() { 531 void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() {
468 DCHECK_CURRENTLY_ON(BrowserThread::UI); 532 DCHECK_CURRENTLY_ON(BrowserThread::UI);
469 533
534 #if defined(OS_ANDROID)
535 number_event_log_files_ = 3;
536 #else
537 number_event_log_files_ = 10;
538 #endif
470 audio_debug_recordings_ = true; 539 audio_debug_recordings_ = true;
471 for (RenderProcessHost::iterator i( 540 for (RenderProcessHost::iterator i(
472 content::RenderProcessHost::AllHostsIterator()); 541 content::RenderProcessHost::AllHostsIterator());
473 !i.IsAtEnd(); i.Advance()) { 542 !i.IsAtEnd(); i.Advance()) {
474 i.GetCurrentValue()->EnableAudioDebugRecordings( 543 i.GetCurrentValue()->EnableAudioDebugRecordings(
475 audio_debug_recordings_file_path_); 544 audio_debug_recordings_file_path_);
476 } 545 }
477 } 546 }
478 547
479 void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() { 548 void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() {
480 DCHECK_CURRENTLY_ON(BrowserThread::UI); 549 DCHECK_CURRENTLY_ON(BrowserThread::UI);
481 550
482 event_log_recordings_ = true; 551 event_log_recordings_ = true;
483 for (RenderProcessHost::iterator i( 552 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) {
484 content::RenderProcessHost::AllHostsIterator()); 553 if (number_event_log_files_ <= 0) {
485 !i.IsAtEnd(); i.Advance()) { 554 VLOG(1) << "Maximum number of WebRTC event log files reached.";
486 i.GetCurrentValue()->EnableEventLogRecordings( 555 break;
487 event_log_recordings_file_path_); 556 }
557 number_event_log_files_--;
558 base::DictionaryValue* record = NULL;
559 peer_connection_data_.GetDictionary(i, &record);
560
561 int rid, lid;
562 record->GetInteger("rid", &rid);
563 record->GetInteger("lid", &lid);
564 base::FilePath file_path = event_log_recordings_file_path_;
565 file_path = file_path.AddExtension(IntToStringType(rid));
566 file_path = file_path.AddExtension(IntToStringType(lid));
567
568 BrowserThread::PostTaskAndReplyWithResult(
569 BrowserThread::FILE, FROM_HERE,
570 base::Bind(&CreateFileForProcess, file_path,
571 base::GetCurrentProcessHandle()),
572 base::Bind(&SendEventLogFileToRenderer, rid, lid));
488 } 573 }
489 } 574 }
490 #endif 575 #endif
491 576
492 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { 577 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() {
493 DCHECK_CURRENTLY_ON(BrowserThread::UI); 578 DCHECK_CURRENTLY_ON(BrowserThread::UI);
494 579
495 if (peer_connection_data_.empty() && power_save_blocker_) { 580 if (peer_connection_data_.empty() && power_save_blocker_) {
496 DVLOG(1) << ("Releasing the block on application suspension since no " 581 DVLOG(1) << ("Releasing the block on application suspension since no "
497 "PeerConnections are active anymore."); 582 "PeerConnections are active anymore.");
(...skipping 12 matching lines...) Expand all
510 while (!pending_updates_.empty()) { 595 while (!pending_updates_.empty()) {
511 const auto& update = pending_updates_.front(); 596 const auto& update = pending_updates_.front();
512 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, 597 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver,
513 observers_, 598 observers_,
514 OnUpdate(update.command(), update.value())); 599 OnUpdate(update.command(), update.value()));
515 pending_updates_.pop(); 600 pending_updates_.pop();
516 } 601 }
517 } 602 }
518 603
519 } // namespace content 604 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/webrtc/webrtc_internals.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698