OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 | 713 |
714 const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const { | 714 const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const { |
715 Values::const_iterator it = values_.find(name); | 715 Values::const_iterator it = values_.find(name); |
716 return it == values_.end() ? nullptr : it->second.get(); | 716 return it == values_.end() ? nullptr : it->second.get(); |
717 } | 717 } |
718 | 718 |
719 StatsCollection::StatsCollection() { | 719 StatsCollection::StatsCollection() { |
720 } | 720 } |
721 | 721 |
722 StatsCollection::~StatsCollection() { | 722 StatsCollection::~StatsCollection() { |
| 723 DCHECK(thread_checker_.CalledOnValidThread()); |
723 for (auto* r : list_) | 724 for (auto* r : list_) |
724 delete r; | 725 delete r; |
725 } | 726 } |
726 | 727 |
727 StatsCollection::const_iterator StatsCollection::begin() const { | 728 StatsCollection::const_iterator StatsCollection::begin() const { |
| 729 DCHECK(thread_checker_.CalledOnValidThread()); |
728 return list_.begin(); | 730 return list_.begin(); |
729 } | 731 } |
730 | 732 |
731 StatsCollection::const_iterator StatsCollection::end() const { | 733 StatsCollection::const_iterator StatsCollection::end() const { |
| 734 DCHECK(thread_checker_.CalledOnValidThread()); |
732 return list_.end(); | 735 return list_.end(); |
733 } | 736 } |
734 | 737 |
735 size_t StatsCollection::size() const { | 738 size_t StatsCollection::size() const { |
| 739 DCHECK(thread_checker_.CalledOnValidThread()); |
736 return list_.size(); | 740 return list_.size(); |
737 } | 741 } |
738 | 742 |
739 StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) { | 743 StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) { |
| 744 DCHECK(thread_checker_.CalledOnValidThread()); |
740 DCHECK(Find(id) == nullptr); | 745 DCHECK(Find(id) == nullptr); |
741 StatsReport* report = new StatsReport(id); | 746 StatsReport* report = new StatsReport(id); |
742 list_.push_back(report); | 747 list_.push_back(report); |
743 return report; | 748 return report; |
744 } | 749 } |
745 | 750 |
746 StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) { | 751 StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) { |
| 752 DCHECK(thread_checker_.CalledOnValidThread()); |
747 StatsReport* ret = Find(id); | 753 StatsReport* ret = Find(id); |
748 return ret ? ret : InsertNew(id); | 754 return ret ? ret : InsertNew(id); |
749 } | 755 } |
750 | 756 |
751 StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) { | 757 StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) { |
| 758 DCHECK(thread_checker_.CalledOnValidThread()); |
752 DCHECK(id.get()); | 759 DCHECK(id.get()); |
753 Container::iterator it = std::find_if(list_.begin(), list_.end(), | 760 Container::iterator it = std::find_if(list_.begin(), list_.end(), |
754 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); | 761 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); |
755 if (it != end()) { | 762 if (it != end()) { |
756 StatsReport* report = new StatsReport((*it)->id()); | 763 StatsReport* report = new StatsReport((*it)->id()); |
757 delete *it; | 764 delete *it; |
758 *it = report; | 765 *it = report; |
759 return report; | 766 return report; |
760 } | 767 } |
761 return InsertNew(id); | 768 return InsertNew(id); |
762 } | 769 } |
763 | 770 |
764 // Looks for a report with the given |id|. If one is not found, NULL | 771 // Looks for a report with the given |id|. If one is not found, NULL |
765 // will be returned. | 772 // will be returned. |
766 StatsReport* StatsCollection::Find(const StatsReport::Id& id) { | 773 StatsReport* StatsCollection::Find(const StatsReport::Id& id) { |
| 774 DCHECK(thread_checker_.CalledOnValidThread()); |
767 Container::iterator it = std::find_if(list_.begin(), list_.end(), | 775 Container::iterator it = std::find_if(list_.begin(), list_.end(), |
768 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); | 776 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); |
769 return it == list_.end() ? nullptr : *it; | 777 return it == list_.end() ? nullptr : *it; |
770 } | 778 } |
771 | 779 |
772 } // namespace webrtc | 780 } // namespace webrtc |
OLD | NEW |