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

Side by Side Diff: talk/app/webrtc/statstypes.cc

Issue 1335923002: Add RTC_ prefix to (D)CHECKs and related macros. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 5 years, 3 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 | « talk/app/webrtc/statscollector.cc ('k') | talk/app/webrtc/test/fakedtlsidentitystore.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/statstypes.h" 28 #include "talk/app/webrtc/statstypes.h"
29 29
30 #include <string.h> 30 #include <string.h>
31 31
32 #include "webrtc/base/checks.h" 32 #include "webrtc/base/checks.h"
33 33
34 // TODO(tommi): Could we have a static map of value name -> expected type 34 // TODO(tommi): Could we have a static map of value name -> expected type
35 // and use this to DCHECK on correct usage (somewhat strongly typed values)? 35 // and use this to RTC_DCHECK on correct usage (somewhat strongly typed values)?
36 // Alternatively, we could define the names+type in a separate document and 36 // Alternatively, we could define the names+type in a separate document and
37 // generate strongly typed inline C++ code that forces the correct type to be 37 // generate strongly typed inline C++ code that forces the correct type to be
38 // used for a given name at compile time. 38 // used for a given name at compile time.
39 39
40 using rtc::RefCountedObject; 40 using rtc::RefCountedObject;
41 41
42 namespace webrtc { 42 namespace webrtc {
43 namespace { 43 namespace {
44 44
45 // The id of StatsReport of type kStatsReportTypeBwe. 45 // The id of StatsReport of type kStatsReportTypeBwe.
(...skipping 21 matching lines...) Expand all
67 return "transport"; 67 return "transport";
68 case StatsReport::kStatsReportTypeComponent: 68 case StatsReport::kStatsReportTypeComponent:
69 return "googComponent"; 69 return "googComponent";
70 case StatsReport::kStatsReportTypeCandidatePair: 70 case StatsReport::kStatsReportTypeCandidatePair:
71 return "googCandidatePair"; 71 return "googCandidatePair";
72 case StatsReport::kStatsReportTypeCertificate: 72 case StatsReport::kStatsReportTypeCertificate:
73 return "googCertificate"; 73 return "googCertificate";
74 case StatsReport::kStatsReportTypeDataChannel: 74 case StatsReport::kStatsReportTypeDataChannel:
75 return "datachannel"; 75 return "datachannel";
76 } 76 }
77 DCHECK(false); 77 RTC_DCHECK(false);
78 return nullptr; 78 return nullptr;
79 } 79 }
80 80
81 class BandwidthEstimationId : public StatsReport::IdBase { 81 class BandwidthEstimationId : public StatsReport::IdBase {
82 public: 82 public:
83 BandwidthEstimationId() 83 BandwidthEstimationId()
84 : StatsReport::IdBase(StatsReport::kStatsReportTypeBwe) {} 84 : StatsReport::IdBase(StatsReport::kStatsReportTypeBwe) {}
85 std::string ToString() const override { return kStatsReportVideoBweId; } 85 std::string ToString() const override { return kStatsReportVideoBweId; }
86 }; 86 };
87 87
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 StatsReport::IdBase::~IdBase() {} 224 StatsReport::IdBase::~IdBase() {}
225 225
226 StatsReport::StatsType StatsReport::IdBase::type() const { return type_; } 226 StatsReport::StatsType StatsReport::IdBase::type() const { return type_; }
227 227
228 bool StatsReport::IdBase::Equals(const IdBase& other) const { 228 bool StatsReport::IdBase::Equals(const IdBase& other) const {
229 return other.type_ == type_; 229 return other.type_ == type_;
230 } 230 }
231 231
232 StatsReport::Value::Value(StatsValueName name, int64 value, Type int_type) 232 StatsReport::Value::Value(StatsValueName name, int64 value, Type int_type)
233 : name(name), type_(int_type) { 233 : name(name), type_(int_type) {
234 DCHECK(type_ == kInt || type_ == kInt64); 234 RTC_DCHECK(type_ == kInt || type_ == kInt64);
235 type_ == kInt ? value_.int_ = static_cast<int>(value) : value_.int64_ = value; 235 type_ == kInt ? value_.int_ = static_cast<int>(value) : value_.int64_ = value;
236 } 236 }
237 237
238 StatsReport::Value::Value(StatsValueName name, float f) 238 StatsReport::Value::Value(StatsValueName name, float f)
239 : name(name), type_(kFloat) { 239 : name(name), type_(kFloat) {
240 value_.float_ = f; 240 value_.float_ = f;
241 } 241 }
242 242
243 StatsReport::Value::Value(StatsValueName name, const std::string& value) 243 StatsReport::Value::Value(StatsValueName name, const std::string& value)
244 : name(name), type_(kString) { 244 : name(name), type_(kString) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 break; 276 break;
277 } 277 }
278 } 278 }
279 279
280 bool StatsReport::Value::Equals(const Value& other) const { 280 bool StatsReport::Value::Equals(const Value& other) const {
281 if (name != other.name) 281 if (name != other.name)
282 return false; 282 return false;
283 283
284 // There's a 1:1 relation between a name and a type, so we don't have to 284 // There's a 1:1 relation between a name and a type, so we don't have to
285 // check that. 285 // check that.
286 DCHECK_EQ(type_, other.type_); 286 RTC_DCHECK_EQ(type_, other.type_);
287 287
288 switch (type_) { 288 switch (type_) {
289 case kInt: 289 case kInt:
290 return value_.int_ == other.value_.int_; 290 return value_.int_ == other.value_.int_;
291 case kInt64: 291 case kInt64:
292 return value_.int64_ == other.value_.int64_; 292 return value_.int64_ == other.value_.int64_;
293 case kFloat: 293 case kFloat:
294 return value_.float_ == other.value_.float_; 294 return value_.float_ == other.value_.float_;
295 case kStaticString: { 295 case kStaticString: {
296 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) 296 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
297 if (value_.static_string_ != other.value_.static_string_) { 297 if (value_.static_string_ != other.value_.static_string_) {
298 DCHECK(strcmp(value_.static_string_, other.value_.static_string_) != 0) 298 RTC_DCHECK(strcmp(value_.static_string_, other.value_.static_string_) !=
299 0)
299 << "Duplicate global?"; 300 << "Duplicate global?";
300 } 301 }
301 #endif 302 #endif
302 return value_.static_string_ == other.value_.static_string_; 303 return value_.static_string_ == other.value_.static_string_;
303 } 304 }
304 case kString: 305 case kString:
305 return *value_.string_ == *other.value_.string_; 306 return *value_.string_ == *other.value_.string_;
306 case kBool: 307 case kBool:
307 return value_.bool_ == other.value_.bool_; 308 return value_.bool_ == other.value_.bool_;
308 case kId: 309 case kId:
309 return (*value_.id_)->Equals(*other.value_.id_); 310 return (*value_.id_)->Equals(*other.value_.id_);
310 } 311 }
311 RTC_NOTREACHED(); 312 RTC_NOTREACHED();
312 return false; 313 return false;
313 } 314 }
314 315
315 bool StatsReport::Value::operator==(const std::string& value) const { 316 bool StatsReport::Value::operator==(const std::string& value) const {
316 return (type_ == kString && value_.string_->compare(value) == 0) || 317 return (type_ == kString && value_.string_->compare(value) == 0) ||
317 (type_ == kStaticString && value.compare(value_.static_string_) == 0); 318 (type_ == kStaticString && value.compare(value_.static_string_) == 0);
318 } 319 }
319 320
320 bool StatsReport::Value::operator==(const char* value) const { 321 bool StatsReport::Value::operator==(const char* value) const {
321 if (type_ == kString) 322 if (type_ == kString)
322 return value_.string_->compare(value) == 0; 323 return value_.string_->compare(value) == 0;
323 if (type_ != kStaticString) 324 if (type_ != kStaticString)
324 return false; 325 return false;
325 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) 326 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
326 if (value_.static_string_ != value) 327 if (value_.static_string_ != value)
327 DCHECK(strcmp(value_.static_string_, value) != 0) << "Duplicate global?"; 328 RTC_DCHECK(strcmp(value_.static_string_, value) != 0)
329 << "Duplicate global?";
328 #endif 330 #endif
329 return value == value_.static_string_; 331 return value == value_.static_string_;
330 } 332 }
331 333
332 bool StatsReport::Value::operator==(int64 value) const { 334 bool StatsReport::Value::operator==(int64 value) const {
333 return type_ == kInt ? value_.int_ == static_cast<int>(value) : 335 return type_ == kInt ? value_.int_ == static_cast<int>(value) :
334 (type_ == kInt64 ? value_.int64_ == value : false); 336 (type_ == kInt64 ? value_.int64_ == value : false);
335 } 337 }
336 338
337 bool StatsReport::Value::operator==(bool value) const { 339 bool StatsReport::Value::operator==(bool value) const {
338 return type_ == kBool && value_.bool_ == value; 340 return type_ == kBool && value_.bool_ == value;
339 } 341 }
340 342
341 bool StatsReport::Value::operator==(float value) const { 343 bool StatsReport::Value::operator==(float value) const {
342 return type_ == kFloat && value_.float_ == value; 344 return type_ == kFloat && value_.float_ == value;
343 } 345 }
344 346
345 bool StatsReport::Value::operator==(const Id& value) const { 347 bool StatsReport::Value::operator==(const Id& value) const {
346 return type_ == kId && (*value_.id_)->Equals(value); 348 return type_ == kId && (*value_.id_)->Equals(value);
347 } 349 }
348 350
349 int StatsReport::Value::int_val() const { 351 int StatsReport::Value::int_val() const {
350 DCHECK(type_ == kInt); 352 RTC_DCHECK(type_ == kInt);
351 return value_.int_; 353 return value_.int_;
352 } 354 }
353 355
354 int64 StatsReport::Value::int64_val() const { 356 int64 StatsReport::Value::int64_val() const {
355 DCHECK(type_ == kInt64); 357 RTC_DCHECK(type_ == kInt64);
356 return value_.int64_; 358 return value_.int64_;
357 } 359 }
358 360
359 float StatsReport::Value::float_val() const { 361 float StatsReport::Value::float_val() const {
360 DCHECK(type_ == kFloat); 362 RTC_DCHECK(type_ == kFloat);
361 return value_.float_; 363 return value_.float_;
362 } 364 }
363 365
364 const char* StatsReport::Value::static_string_val() const { 366 const char* StatsReport::Value::static_string_val() const {
365 DCHECK(type_ == kStaticString); 367 RTC_DCHECK(type_ == kStaticString);
366 return value_.static_string_; 368 return value_.static_string_;
367 } 369 }
368 370
369 const std::string& StatsReport::Value::string_val() const { 371 const std::string& StatsReport::Value::string_val() const {
370 DCHECK(type_ == kString); 372 RTC_DCHECK(type_ == kString);
371 return *value_.string_; 373 return *value_.string_;
372 } 374 }
373 375
374 bool StatsReport::Value::bool_val() const { 376 bool StatsReport::Value::bool_val() const {
375 DCHECK(type_ == kBool); 377 RTC_DCHECK(type_ == kBool);
376 return value_.bool_; 378 return value_.bool_;
377 } 379 }
378 380
379 const char* StatsReport::Value::display_name() const { 381 const char* StatsReport::Value::display_name() const {
380 switch (name) { 382 switch (name) {
381 case kStatsValueNameAudioOutputLevel: 383 case kStatsValueNameAudioOutputLevel:
382 return "audioOutputLevel"; 384 return "audioOutputLevel";
383 case kStatsValueNameAudioInputLevel: 385 case kStatsValueNameAudioInputLevel:
384 return "audioInputLevel"; 386 return "audioInputLevel";
385 case kStatsValueNameBytesSent: 387 case kStatsValueNameBytesSent:
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 return "googTransportType"; 586 return "googTransportType";
585 case kStatsValueNameTrackId: 587 case kStatsValueNameTrackId:
586 return "googTrackId"; 588 return "googTrackId";
587 case kStatsValueNameTypingNoiseState: 589 case kStatsValueNameTypingNoiseState:
588 return "googTypingNoiseState"; 590 return "googTypingNoiseState";
589 case kStatsValueNameViewLimitedResolution: 591 case kStatsValueNameViewLimitedResolution:
590 return "googViewLimitedResolution"; 592 return "googViewLimitedResolution";
591 case kStatsValueNameWritable: 593 case kStatsValueNameWritable:
592 return "googWritable"; 594 return "googWritable";
593 default: 595 default:
594 DCHECK(false); 596 RTC_DCHECK(false);
595 break; 597 break;
596 } 598 }
597 599
598 return nullptr; 600 return nullptr;
599 } 601 }
600 602
601 std::string StatsReport::Value::ToString() const { 603 std::string StatsReport::Value::ToString() const {
602 switch (type_) { 604 switch (type_) {
603 case kInt: 605 case kInt:
604 return rtc::ToString(value_.int_); 606 return rtc::ToString(value_.int_);
605 case kInt64: 607 case kInt64:
606 return rtc::ToString(value_.int64_); 608 return rtc::ToString(value_.int64_);
607 case kFloat: 609 case kFloat:
608 return rtc::ToString(value_.float_); 610 return rtc::ToString(value_.float_);
609 case kStaticString: 611 case kStaticString:
610 return std::string(value_.static_string_); 612 return std::string(value_.static_string_);
611 case kString: 613 case kString:
612 return *value_.string_; 614 return *value_.string_;
613 case kBool: 615 case kBool:
614 return value_.bool_ ? "true" : "false"; 616 return value_.bool_ ? "true" : "false";
615 case kId: 617 case kId:
616 return (*value_.id_)->ToString(); 618 return (*value_.id_)->ToString();
617 } 619 }
618 RTC_NOTREACHED(); 620 RTC_NOTREACHED();
619 return std::string(); 621 return std::string();
620 } 622 }
621 623
622 StatsReport::StatsReport(const Id& id) : id_(id), timestamp_(0.0) { 624 StatsReport::StatsReport(const Id& id) : id_(id), timestamp_(0.0) {
623 DCHECK(id_.get()); 625 RTC_DCHECK(id_.get());
624 } 626 }
625 627
626 // static 628 // static
627 StatsReport::Id StatsReport::NewBandwidthEstimationId() { 629 StatsReport::Id StatsReport::NewBandwidthEstimationId() {
628 return Id(new RefCountedObject<BandwidthEstimationId>()); 630 return Id(new RefCountedObject<BandwidthEstimationId>());
629 } 631 }
630 632
631 // static 633 // static
632 StatsReport::Id StatsReport::NewTypedId(StatsType type, const std::string& id) { 634 StatsReport::Id StatsReport::NewTypedId(StatsType type, const std::string& id) {
633 return Id(new RefCountedObject<TypedId>(type, id)); 635 return Id(new RefCountedObject<TypedId>(type, id));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 715
714 const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const { 716 const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const {
715 Values::const_iterator it = values_.find(name); 717 Values::const_iterator it = values_.find(name);
716 return it == values_.end() ? nullptr : it->second.get(); 718 return it == values_.end() ? nullptr : it->second.get();
717 } 719 }
718 720
719 StatsCollection::StatsCollection() { 721 StatsCollection::StatsCollection() {
720 } 722 }
721 723
722 StatsCollection::~StatsCollection() { 724 StatsCollection::~StatsCollection() {
723 DCHECK(thread_checker_.CalledOnValidThread()); 725 RTC_DCHECK(thread_checker_.CalledOnValidThread());
724 for (auto* r : list_) 726 for (auto* r : list_)
725 delete r; 727 delete r;
726 } 728 }
727 729
728 StatsCollection::const_iterator StatsCollection::begin() const { 730 StatsCollection::const_iterator StatsCollection::begin() const {
729 DCHECK(thread_checker_.CalledOnValidThread()); 731 RTC_DCHECK(thread_checker_.CalledOnValidThread());
730 return list_.begin(); 732 return list_.begin();
731 } 733 }
732 734
733 StatsCollection::const_iterator StatsCollection::end() const { 735 StatsCollection::const_iterator StatsCollection::end() const {
734 DCHECK(thread_checker_.CalledOnValidThread()); 736 RTC_DCHECK(thread_checker_.CalledOnValidThread());
735 return list_.end(); 737 return list_.end();
736 } 738 }
737 739
738 size_t StatsCollection::size() const { 740 size_t StatsCollection::size() const {
739 DCHECK(thread_checker_.CalledOnValidThread()); 741 RTC_DCHECK(thread_checker_.CalledOnValidThread());
740 return list_.size(); 742 return list_.size();
741 } 743 }
742 744
743 StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) { 745 StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) {
744 DCHECK(thread_checker_.CalledOnValidThread()); 746 RTC_DCHECK(thread_checker_.CalledOnValidThread());
745 DCHECK(Find(id) == nullptr); 747 RTC_DCHECK(Find(id) == nullptr);
746 StatsReport* report = new StatsReport(id); 748 StatsReport* report = new StatsReport(id);
747 list_.push_back(report); 749 list_.push_back(report);
748 return report; 750 return report;
749 } 751 }
750 752
751 StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) { 753 StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) {
752 DCHECK(thread_checker_.CalledOnValidThread()); 754 RTC_DCHECK(thread_checker_.CalledOnValidThread());
753 StatsReport* ret = Find(id); 755 StatsReport* ret = Find(id);
754 return ret ? ret : InsertNew(id); 756 return ret ? ret : InsertNew(id);
755 } 757 }
756 758
757 StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) { 759 StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) {
758 DCHECK(thread_checker_.CalledOnValidThread()); 760 RTC_DCHECK(thread_checker_.CalledOnValidThread());
759 DCHECK(id.get()); 761 RTC_DCHECK(id.get());
760 Container::iterator it = std::find_if(list_.begin(), list_.end(), 762 Container::iterator it = std::find_if(list_.begin(), list_.end(),
761 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); 763 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); });
762 if (it != end()) { 764 if (it != end()) {
763 StatsReport* report = new StatsReport((*it)->id()); 765 StatsReport* report = new StatsReport((*it)->id());
764 delete *it; 766 delete *it;
765 *it = report; 767 *it = report;
766 return report; 768 return report;
767 } 769 }
768 return InsertNew(id); 770 return InsertNew(id);
769 } 771 }
770 772
771 // Looks for a report with the given |id|. If one is not found, NULL 773 // Looks for a report with the given |id|. If one is not found, NULL
772 // will be returned. 774 // will be returned.
773 StatsReport* StatsCollection::Find(const StatsReport::Id& id) { 775 StatsReport* StatsCollection::Find(const StatsReport::Id& id) {
774 DCHECK(thread_checker_.CalledOnValidThread()); 776 RTC_DCHECK(thread_checker_.CalledOnValidThread());
775 Container::iterator it = std::find_if(list_.begin(), list_.end(), 777 Container::iterator it = std::find_if(list_.begin(), list_.end(),
776 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); 778 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); });
777 return it == list_.end() ? nullptr : *it; 779 return it == list_.end() ? nullptr : *it;
778 } 780 }
779 781
780 } // namespace webrtc 782 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/statscollector.cc ('k') | talk/app/webrtc/test/fakedtlsidentitystore.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698