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

Side by Side Diff: content/browser/media/media_internals.cc

Issue 1169983003: media-internals: Store updates when cannot update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « content/browser/media/media_internals.h ('k') | content/browser/media/media_internals_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/media_internals.h" 5 #include "content/browser/media/media_internals.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 const NotificationSource& source, 314 const NotificationSource& source,
315 const NotificationDetails& details) { 315 const NotificationDetails& details) {
316 DCHECK_CURRENTLY_ON(BrowserThread::UI); 316 DCHECK_CURRENTLY_ON(BrowserThread::UI);
317 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED); 317 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED);
318 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); 318 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
319 319
320 // Post the task to the IO thread to avoid race in updating renderer_info_ map 320 // Post the task to the IO thread to avoid race in updating renderer_info_ map
321 // by both SavePlayerState & LogAndClearPlayersInRenderer from different 321 // by both SavePlayerState & LogAndClearPlayersInRenderer from different
322 // threads. 322 // threads.
323 // Using base::Unretained() on MediaInternalsUMAHandler is safe since 323 // Using base::Unretained() on MediaInternalsUMAHandler is safe since
324 // it is owned by MediaInternals and share the same lifetime 324 // it is owned by MediaInternals and shares the same lifetime.
325 BrowserThread::PostTask( 325 BrowserThread::PostTask(
326 BrowserThread::IO, FROM_HERE, 326 BrowserThread::IO, FROM_HERE,
327 base::Bind(&MediaInternalsUMAHandler::LogAndClearPlayersInRenderer, 327 base::Bind(&MediaInternalsUMAHandler::LogAndClearPlayersInRenderer,
328 base::Unretained(this), process->GetID())); 328 base::Unretained(this), process->GetID()));
329 } 329 }
330 330
331 void MediaInternals::MediaInternalsUMAHandler::SavePlayerState( 331 void MediaInternals::MediaInternalsUMAHandler::SavePlayerState(
332 const media::MediaLogEvent& event, 332 const media::MediaLogEvent& event,
333 int render_process_id) { 333 int render_process_id) {
334 DCHECK_CURRENTLY_ON(BrowserThread::IO); 334 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 int render_process_id) { 443 int render_process_id) {
444 DCHECK_CURRENTLY_ON(BrowserThread::IO); 444 DCHECK_CURRENTLY_ON(BrowserThread::IO);
445 auto players_it = renderer_info_.find(render_process_id); 445 auto players_it = renderer_info_.find(render_process_id);
446 if (players_it == renderer_info_.end()) 446 if (players_it == renderer_info_.end())
447 return; 447 return;
448 auto it = players_it->second.begin(); 448 auto it = players_it->second.begin();
449 while (it != players_it->second.end()) { 449 while (it != players_it->second.end()) {
450 ReportUMAForPipelineStatus(it->second); 450 ReportUMAForPipelineStatus(it->second);
451 players_it->second.erase(it++); 451 players_it->second.erase(it++);
452 } 452 }
453 renderer_info_.erase(players_it);
453 } 454 }
454 455
455 MediaInternals* MediaInternals::GetInstance() { 456 MediaInternals* MediaInternals::GetInstance() {
456 return g_media_internals.Pointer(); 457 return g_media_internals.Pointer();
457 } 458 }
458 459
459 MediaInternals::MediaInternals() 460 MediaInternals::MediaInternals()
460 : can_update_(false), 461 : can_update_(false),
461 owner_ids_(), 462 owner_ids_(),
462 uma_handler_(new MediaInternalsUMAHandler()) { 463 uma_handler_(new MediaInternalsUMAHandler()) {
(...skipping 27 matching lines...) Expand all
490 } 491 }
491 media::PipelineStatus error = static_cast<media::PipelineStatus>(status); 492 media::PipelineStatus error = static_cast<media::PipelineStatus>(status);
492 dict.SetString("params.pipeline_error", 493 dict.SetString("params.pipeline_error",
493 media::MediaLog::PipelineStatusToString(error)); 494 media::MediaLog::PipelineStatusToString(error));
494 } else { 495 } else {
495 dict.Set("params", event->params.DeepCopy()); 496 dict.Set("params", event->params.DeepCopy());
496 } 497 }
497 498
498 if (CanUpdate()) 499 if (CanUpdate())
499 SendUpdate(SerializeUpdate("media.onMediaEvent", &dict)); 500 SendUpdate(SerializeUpdate("media.onMediaEvent", &dict));
501 else
502 SaveUpdate(SerializeUpdate("media.onMediaEvent", &dict));
503
500 uma_handler_->SavePlayerState(*event, render_process_id); 504 uma_handler_->SavePlayerState(*event, render_process_id);
501 } 505 }
502 } 506 }
503 507
504 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) { 508 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) {
505 DCHECK_CURRENTLY_ON(BrowserThread::UI); 509 DCHECK_CURRENTLY_ON(BrowserThread::UI);
506 update_callbacks_.push_back(callback); 510 update_callbacks_.push_back(callback);
507 511
508 base::AutoLock auto_lock(lock_); 512 base::AutoLock auto_lock(lock_);
509 can_update_ = true; 513 can_update_ = true;
(...skipping 10 matching lines...) Expand all
520 524
521 base::AutoLock auto_lock(lock_); 525 base::AutoLock auto_lock(lock_);
522 can_update_ = !update_callbacks_.empty(); 526 can_update_ = !update_callbacks_.empty();
523 } 527 }
524 528
525 bool MediaInternals::CanUpdate() { 529 bool MediaInternals::CanUpdate() {
526 base::AutoLock auto_lock(lock_); 530 base::AutoLock auto_lock(lock_);
527 return can_update_; 531 return can_update_;
528 } 532 }
529 533
534 void MediaInternals::SendHistoricalMediaEvents() {
535 DCHECK_CURRENTLY_ON(BrowserThread::UI);
536 base::AutoLock auto_lock(lock_);
537 for (const auto& update : pending_updates_)
538 SendUpdate(update);
539 pending_updates_.clear();
540 }
541
530 void MediaInternals::SendAudioStreamData() { 542 void MediaInternals::SendAudioStreamData() {
531 base::string16 audio_stream_update; 543 base::string16 audio_stream_update;
532 { 544 {
533 base::AutoLock auto_lock(lock_); 545 base::AutoLock auto_lock(lock_);
534 audio_stream_update = SerializeUpdate( 546 audio_stream_update = SerializeUpdate(
535 "media.onReceiveAudioStreamData", &audio_streams_cached_data_); 547 "media.onReceiveAudioStreamData", &audio_streams_cached_data_);
536 } 548 }
537 SendUpdate(audio_stream_update); 549 SendUpdate(audio_stream_update);
538 } 550 }
539 551
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 606 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
595 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( 607 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
596 &MediaInternals::SendUpdate, base::Unretained(this), update)); 608 &MediaInternals::SendUpdate, base::Unretained(this), update));
597 return; 609 return;
598 } 610 }
599 611
600 for (size_t i = 0; i < update_callbacks_.size(); i++) 612 for (size_t i = 0; i < update_callbacks_.size(); i++)
601 update_callbacks_[i].Run(update); 613 update_callbacks_[i].Run(update);
602 } 614 }
603 615
616 void MediaInternals::SaveUpdate(const base::string16& update) {
617 DCHECK_CURRENTLY_ON(BrowserThread::IO);
618
619 static const size_t kMaxNumUpdates = 2048;
DaleCurtis 2015/06/09 16:41:32 Usually just const at function scope.
xhwang 2015/06/09 20:37:57 Done.
620
621 base::AutoLock auto_lock(lock_);
622 if (pending_updates_.size() >= kMaxNumUpdates)
623 pending_updates_.pop_front();
624 pending_updates_.push_back(update);
625 }
626
604 void MediaInternals::SendAudioLogUpdate(AudioLogUpdateType type, 627 void MediaInternals::SendAudioLogUpdate(AudioLogUpdateType type,
605 const std::string& cache_key, 628 const std::string& cache_key,
606 const std::string& function, 629 const std::string& function,
607 const base::DictionaryValue* value) { 630 const base::DictionaryValue* value) {
608 if (!CanUpdate()) 631 if (!CanUpdate())
609 return; 632 return;
610 633
611 { 634 {
612 base::AutoLock auto_lock(lock_); 635 base::AutoLock auto_lock(lock_);
613 const bool has_entry = audio_streams_cached_data_.HasKey(cache_key); 636 const bool has_entry = audio_streams_cached_data_.HasKey(cache_key);
(...skipping 10 matching lines...) Expand all
624 CHECK( 647 CHECK(
625 audio_streams_cached_data_.GetDictionary(cache_key, &existing_dict)); 648 audio_streams_cached_data_.GetDictionary(cache_key, &existing_dict));
626 existing_dict->MergeDictionary(value); 649 existing_dict->MergeDictionary(value);
627 } 650 }
628 } 651 }
629 652
630 SendUpdate(SerializeUpdate(function, value)); 653 SendUpdate(SerializeUpdate(function, value));
631 } 654 }
632 655
633 } // namespace content 656 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/media_internals.h ('k') | content/browser/media/media_internals_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698