| Index: chrome/browser/media/webrtc/rtc_stats_dictionary.cc
|
| diff --git a/chrome/browser/media/webrtc/rtc_stats_dictionary.cc b/chrome/browser/media/webrtc/rtc_stats_dictionary.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7281445e0871f4f0e86795db4525df008cee3801
|
| --- /dev/null
|
| +++ b/chrome/browser/media/webrtc/rtc_stats_dictionary.cc
|
| @@ -0,0 +1,189 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/media/webrtc/rtc_stats_dictionary.h"
|
| +
|
| +namespace content {
|
| +
|
| +RTCStatsReportDictionary::RTCStatsReportDictionary(
|
| + std::unique_ptr<base::DictionaryValue> report)
|
| + : report_(std::move(report)) {
|
| + DCHECK(report_);
|
| +}
|
| +
|
| +RTCStatsReportDictionary::~RTCStatsReportDictionary() {
|
| +}
|
| +
|
| +std::unique_ptr<RTCStatsDictionary> RTCStatsReportDictionary::Get(
|
| + const std::string id) {
|
| + const base::DictionaryValue* dictionary;
|
| + if (!report_->GetDictionary(id, &dictionary))
|
| + return nullptr;
|
| + return std::unique_ptr<RTCStatsDictionary>(
|
| + new RTCStatsDictionary(this, dictionary));
|
| +}
|
| +
|
| +std::vector<RTCStatsDictionary> RTCStatsReportDictionary::Filter(
|
| + bool(*filter)(const RTCStatsDictionary& dictionary)) {
|
| + std::vector<RTCStatsDictionary> result;
|
| + for (base::DictionaryValue::Iterator it(*report_); !it.IsAtEnd();
|
| + it.Advance()) {
|
| + const base::DictionaryValue* it_value;
|
| + DCHECK(it.value().GetAsDictionary(&it_value));
|
| + RTCStatsDictionary stats(this, it_value);
|
| + if (filter(stats))
|
| + result.push_back(stats);
|
| + }
|
| + return result;
|
| +}
|
| +
|
| +RTCStatsDictionary::RTCStatsDictionary(
|
| + RTCStatsReportDictionary* report, const base::DictionaryValue* stats)
|
| + : report_(report), stats_(stats) {
|
| + DCHECK(report_);
|
| + DCHECK(stats_);
|
| +}
|
| +
|
| +RTCStatsDictionary::RTCStatsDictionary(
|
| + const RTCStatsDictionary& other) = default;
|
| +
|
| +RTCStatsDictionary::~RTCStatsDictionary() {
|
| +}
|
| +
|
| +bool RTCStatsDictionary::IsBoolean(const std::string& key) const {
|
| + bool value;
|
| + return GetBoolean(key, &value);
|
| +}
|
| +
|
| +bool RTCStatsDictionary::GetBoolean(const std::string& key) const {
|
| + bool value;
|
| + DCHECK(GetBoolean(key, &value));
|
| + return value;
|
| +}
|
| +
|
| +bool RTCStatsDictionary::IsNumber(const std::string& key) const {
|
| + double value;
|
| + return GetNumber(key, &value);
|
| +}
|
| +
|
| +double RTCStatsDictionary::GetNumber(const std::string& key) const {
|
| + double value;
|
| + DCHECK(GetNumber(key, &value));
|
| + return value;
|
| +}
|
| +
|
| +bool RTCStatsDictionary::IsString(const std::string& key) const {
|
| + std::string value;
|
| + return GetString(key, &value);
|
| +}
|
| +
|
| +std::string RTCStatsDictionary::GetString(const std::string& key) const {
|
| + std::string value;
|
| + DCHECK(GetString(key, &value));
|
| + return value;
|
| +}
|
| +
|
| +bool RTCStatsDictionary::IsSequenceBoolean(const std::string& key) const {
|
| + std::vector<bool> value;
|
| + return GetSequenceBoolean(key, &value);
|
| +}
|
| +
|
| +std::vector<bool> RTCStatsDictionary::GetSequenceBoolean(
|
| + const std::string& key) const {
|
| + std::vector<bool> value;
|
| + DCHECK(GetSequenceBoolean(key, &value));
|
| + return value;
|
| +}
|
| +
|
| +bool RTCStatsDictionary::IsSequenceNumber(const std::string& key) const {
|
| + std::vector<double> value;
|
| + return GetSequenceNumber(key, &value);
|
| +}
|
| +
|
| +std::vector<double> RTCStatsDictionary::GetSequenceNumber(
|
| + const std::string& key) const {
|
| + std::vector<double> value;
|
| + DCHECK(GetSequenceNumber(key, &value));
|
| + return value;
|
| +}
|
| +
|
| +bool RTCStatsDictionary::IsSequenceString(const std::string& key) const {
|
| + std::vector<std::string> value;
|
| + return GetSequenceString(key, &value);
|
| +}
|
| +
|
| +std::vector<std::string> RTCStatsDictionary::GetSequenceString(
|
| + const std::string& key) const {
|
| + std::vector<std::string> value;
|
| + DCHECK(GetSequenceString(key, &value));
|
| + return value;
|
| +}
|
| +
|
| +bool RTCStatsDictionary::GetBoolean(
|
| + const std::string& key, bool* out) const {
|
| + return stats_->GetBoolean(key, out);
|
| +}
|
| +
|
| +bool RTCStatsDictionary::GetNumber(
|
| + const std::string& key, double* out) const {
|
| + return stats_->GetDouble(key, out);
|
| +}
|
| +
|
| +bool RTCStatsDictionary::GetString(
|
| + const std::string& key, std::string* out) const {
|
| + return stats_->GetString(key, out);
|
| +}
|
| +
|
| +bool RTCStatsDictionary::GetSequenceBoolean(
|
| + const std::string& key,
|
| + std::vector<bool>* out) const {
|
| + const base::ListValue* list;
|
| + if (!stats_->GetList(key, &list))
|
| + return false;
|
| + std::vector<bool> sequence;
|
| + bool element;
|
| + for (size_t i = 0; i < list->GetSize(); ++i) {
|
| + if (!list->GetBoolean(i, &element))
|
| + return false;
|
| + sequence.push_back(element);
|
| + }
|
| + *out = std::move(sequence);
|
| + return true;
|
| +}
|
| +
|
| +bool RTCStatsDictionary::GetSequenceNumber(
|
| + const std::string& key,
|
| + std::vector<double>* out) const {
|
| + const base::ListValue* list;
|
| + if (!stats_->GetList(key, &list))
|
| + return false;
|
| + std::vector<double> sequence;
|
| + double element;
|
| + for (size_t i = 0; i < list->GetSize(); ++i) {
|
| + if (!list->GetDouble(i, &element))
|
| + return false;
|
| + sequence.push_back(element);
|
| + }
|
| + *out = std::move(sequence);
|
| + return true;
|
| +}
|
| +
|
| +bool RTCStatsDictionary::GetSequenceString(
|
| + const std::string& key,
|
| + std::vector<std::string>* out) const {
|
| + const base::ListValue* list;
|
| + if (!stats_->GetList(key, &list))
|
| + return false;
|
| + std::vector<std::string> sequence;
|
| + std::string element;
|
| + for (size_t i = 0; i < list->GetSize(); ++i) {
|
| + if (!list->GetString(i, &element))
|
| + return false;
|
| + sequence.push_back(element);
|
| + }
|
| + *out = std::move(sequence);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace content
|
|
|