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

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: Merge with existing WebRtcEventLogHandler. Created 4 years, 7 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/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/content_browser_client.h" 14 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/power_save_blocker.h" 15 #include "content/public/browser/power_save_blocker.h"
16 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "ipc/ipc_platform_file.h"
19
20 #if defined(OS_WIN)
21 #define IntToStringType base::IntToString16
22 #else
23 #define IntToStringType base::IntToString
24 #endif
18 25
19 using base::ProcessId; 26 using base::ProcessId;
20 using std::string; 27 using std::string;
21 28
22 namespace content { 29 namespace content {
23 30
24 namespace { 31 namespace {
25 32
26 static base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = 33 static base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals =
27 LAZY_INSTANCE_INITIALIZER; 34 LAZY_INSTANCE_INITIALIZER;
28 35
29 // Makes sure that |dict| has a ListValue under path "log". 36 // Makes sure that |dict| has a ListValue under path "log".
30 static base::ListValue* EnsureLogList(base::DictionaryValue* dict) { 37 static base::ListValue* EnsureLogList(base::DictionaryValue* dict) {
31 base::ListValue* log = NULL; 38 base::ListValue* log = NULL;
32 if (!dict->GetList("log", &log)) { 39 if (!dict->GetList("log", &log)) {
33 log = new base::ListValue(); 40 log = new base::ListValue();
34 if (log) 41 if (log)
35 dict->Set("log", log); 42 dict->Set("log", log);
36 } 43 }
37 return log; 44 return log;
38 } 45 }
39
Henrik Grunell 2016/05/10 08:44:56 Keep empty line.
Ivo-OOO until feb 6 2016/05/12 13:23:23 Done.
40 } // namespace 46 } // namespace
41 47
42 WebRTCInternals::PendingUpdate::PendingUpdate( 48 WebRTCInternals::PendingUpdate::PendingUpdate(
43 const std::string& command, 49 const std::string& command,
44 std::unique_ptr<base::Value> value) 50 std::unique_ptr<base::Value> value)
45 : command_(command), value_(std::move(value)) {} 51 : command_(command), value_(std::move(value)) {}
46 52
47 WebRTCInternals::PendingUpdate::PendingUpdate(PendingUpdate&& other) 53 WebRTCInternals::PendingUpdate::PendingUpdate(PendingUpdate&& other)
48 : command_(std::move(other.command_)), 54 : command_(std::move(other.command_)),
49 value_(std::move(other.value_)) {} 55 value_(std::move(other.value_)) {}
(...skipping 11 matching lines...) Expand all
61 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK(thread_checker_.CalledOnValidThread());
62 return value_.get(); 68 return value_.get();
63 } 69 }
64 70
65 WebRTCInternals::WebRTCInternals() : WebRTCInternals(500) {} 71 WebRTCInternals::WebRTCInternals() : WebRTCInternals(500) {}
66 72
67 WebRTCInternals::WebRTCInternals(int aggregate_updates_ms) 73 WebRTCInternals::WebRTCInternals(int aggregate_updates_ms)
68 : audio_debug_recordings_(false), 74 : audio_debug_recordings_(false),
69 event_log_recordings_(false), 75 event_log_recordings_(false),
70 selecting_event_log_(false), 76 selecting_event_log_(false),
77 number_event_log_files_(0),
71 aggregate_updates_ms_(aggregate_updates_ms), 78 aggregate_updates_ms_(aggregate_updates_ms),
72 weak_factory_(this) { 79 weak_factory_(this) {
73 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the 80 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the
74 // build if WebRTC is disabled? 81 // build if WebRTC is disabled?
75 #if defined(ENABLE_WEBRTC) 82 #if defined(ENABLE_WEBRTC)
76 audio_debug_recordings_file_path_ = 83 audio_debug_recordings_file_path_ =
77 GetContentClient()->browser()->GetDefaultDownloadDirectory(); 84 GetContentClient()->browser()->GetDefaultDownloadDirectory();
78 event_log_recordings_file_path_ = audio_debug_recordings_file_path_; 85 event_log_recordings_file_path_ = audio_debug_recordings_file_path_;
79 86
80 if (audio_debug_recordings_file_path_.empty()) { 87 if (audio_debug_recordings_file_path_.empty()) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr); 342 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr);
336 select_file_dialog_->SelectFile( 343 select_file_dialog_->SelectFile(
337 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), 344 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(),
338 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""), 345 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""),
339 web_contents->GetTopLevelNativeWindow(), nullptr); 346 web_contents->GetTopLevelNativeWindow(), nullptr);
340 #endif 347 #endif
341 } else { 348 } else {
342 event_log_recordings_ = false; 349 event_log_recordings_ = false;
343 // Tear down the dialog since the user has unchecked the audio debug 350 // Tear down the dialog since the user has unchecked the audio debug
344 // recordings box. 351 // recordings box.
352 DCHECK(select_file_dialog_->HasOneRef());
345 select_file_dialog_ = nullptr; 353 select_file_dialog_ = nullptr;
346 DCHECK(select_file_dialog_->HasOneRef());
347 354
348 for (RenderProcessHost::iterator i( 355 for (RenderProcessHost::iterator i(
349 content::RenderProcessHost::AllHostsIterator()); 356 content::RenderProcessHost::AllHostsIterator());
350 !i.IsAtEnd(); i.Advance()) { 357 !i.IsAtEnd(); i.Advance()) {
351 i.GetCurrentValue()->DisableEventLogRecordings(); 358 int rid = i.GetCurrentValue()->GetID();
Henrik Grunell 2016/05/10 08:44:56 I'd prefer to have some other component keep track
Ivo-OOO until feb 6 2016/05/12 13:23:23 I have moved this into a new class: WebRTCCallback
359 if (event_log_handlers.count(rid)) {
360 event_log_handlers[rid].second.Run();
361 }
352 } 362 }
353 } 363 }
354 #endif 364 #endif
355 } 365 }
356 366
357 bool WebRTCInternals::IsEventLogRecordingsEnabled() const { 367 bool WebRTCInternals::IsEventLogRecordingsEnabled() const {
358 DCHECK_CURRENTLY_ON(BrowserThread::UI); 368 DCHECK_CURRENTLY_ON(BrowserThread::UI);
359 return event_log_recordings_; 369 return event_log_recordings_;
360 } 370 }
361 371
362 const base::FilePath& WebRTCInternals::GetEventLogRecordingsFilePath() const { 372 void WebRTCInternals::RegisterEventLogHandler(
363 DCHECK_CURRENTLY_ON(BrowserThread::UI); 373 int render_process_id,
364 return event_log_recordings_file_path_; 374 event_log_start_func start_logging_callback,
375 event_log_stop_func stop_logging_callback) {
376 event_log_handlers[render_process_id] =
377 std::make_pair(start_logging_callback, stop_logging_callback);
365 } 378 }
366 379
367 void WebRTCInternals::SendUpdate(const string& command, 380 void WebRTCInternals::SendUpdate(const string& command,
368 std::unique_ptr<base::Value> value) { 381 std::unique_ptr<base::Value> value) {
369 DCHECK_CURRENTLY_ON(BrowserThread::UI); 382 DCHECK_CURRENTLY_ON(BrowserThread::UI);
370 DCHECK(observers_.might_have_observers()); 383 DCHECK(observers_.might_have_observers());
371 384
372 bool queue_was_empty = pending_updates_.empty(); 385 bool queue_was_empty = pending_updates_.empty();
373 pending_updates_.push(PendingUpdate(command, std::move(value))); 386 pending_updates_.push(PendingUpdate(command, std::move(value)));
374 387
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 492 }
480 } 493 }
481 494
482 void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() { 495 void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() {
483 DCHECK_CURRENTLY_ON(BrowserThread::UI); 496 DCHECK_CURRENTLY_ON(BrowserThread::UI);
484 497
485 event_log_recordings_ = true; 498 event_log_recordings_ = true;
486 for (RenderProcessHost::iterator i( 499 for (RenderProcessHost::iterator i(
487 content::RenderProcessHost::AllHostsIterator()); 500 content::RenderProcessHost::AllHostsIterator());
488 !i.IsAtEnd(); i.Advance()) { 501 !i.IsAtEnd(); i.Advance()) {
489 i.GetCurrentValue()->EnableEventLogRecordings( 502 int rid = i.GetCurrentValue()->GetID();
490 event_log_recordings_file_path_); 503 if (event_log_handlers.count(rid)) {
504 event_log_handlers[rid].first.Run(event_log_recordings_file_path_);
505 }
491 } 506 }
492 } 507 }
493 #endif 508 #endif
494 509
495 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { 510 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() {
496 DCHECK_CURRENTLY_ON(BrowserThread::UI); 511 DCHECK_CURRENTLY_ON(BrowserThread::UI);
497 512
498 if (peer_connection_data_.empty() && power_save_blocker_) { 513 if (peer_connection_data_.empty() && power_save_blocker_) {
499 DVLOG(1) << ("Releasing the block on application suspension since no " 514 DVLOG(1) << ("Releasing the block on application suspension since no "
500 "PeerConnections are active anymore."); 515 "PeerConnections are active anymore.");
(...skipping 12 matching lines...) Expand all
513 while (!pending_updates_.empty()) { 528 while (!pending_updates_.empty()) {
514 const auto& update = pending_updates_.front(); 529 const auto& update = pending_updates_.front();
515 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, 530 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver,
516 observers_, 531 observers_,
517 OnUpdate(update.command(), update.value())); 532 OnUpdate(update.command(), update.value()));
518 pending_updates_.pop(); 533 pending_updates_.pop();
519 } 534 }
520 } 535 }
521 536
522 } // namespace content 537 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698