Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // This file contains structures used for retrieving statistics from an ongoing | 11 // This file contains structures used for retrieving statistics from an ongoing |
| 12 // libjingle session. | 12 // libjingle session. |
| 13 | 13 |
| 14 #ifndef WEBRTC_API_STATSTYPES_H_ | 14 #ifndef WEBRTC_API_STATSTYPES_H_ |
| 15 #define WEBRTC_API_STATSTYPES_H_ | 15 #define WEBRTC_API_STATSTYPES_H_ |
| 16 | 16 |
| 17 #include <algorithm> | 17 #include <algorithm> |
| 18 #include <list> | 18 #include <list> |
| 19 #include <map> | 19 #include <map> |
| 20 #include <string> | 20 #include <string> |
| 21 | 21 |
| 22 #include "webrtc/base/basictypes.h" | 22 #include "webrtc/base/basictypes.h" |
| 23 #include "webrtc/base/common.h" | 23 #include "webrtc/base/common.h" |
| 24 #include "webrtc/base/constructormagic.h" | 24 #include "webrtc/base/constructormagic.h" |
| 25 #include "webrtc/base/linked_ptr.h" | |
| 26 #include "webrtc/base/refcount.h" | 25 #include "webrtc/base/refcount.h" |
| 27 #include "webrtc/base/scoped_ref_ptr.h" | 26 #include "webrtc/base/scoped_ref_ptr.h" |
| 28 #include "webrtc/base/stringencode.h" | 27 #include "webrtc/base/stringencode.h" |
| 29 #include "webrtc/base/thread_checker.h" | 28 #include "webrtc/base/thread_checker.h" |
| 30 | 29 |
| 31 namespace webrtc { | 30 namespace webrtc { |
| 32 | 31 |
| 33 class StatsReport { | 32 class StatsReport { |
| 34 public: | 33 public: |
| 35 // Indicates whether a track is for sending or receiving. | 34 // Indicates whether a track is for sending or receiving. |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 | 256 |
| 258 Value(StatsValueName name, int64_t value, Type int_type); | 257 Value(StatsValueName name, int64_t value, Type int_type); |
| 259 Value(StatsValueName name, float f); | 258 Value(StatsValueName name, float f); |
| 260 Value(StatsValueName name, const std::string& value); | 259 Value(StatsValueName name, const std::string& value); |
| 261 Value(StatsValueName name, const char* value); | 260 Value(StatsValueName name, const char* value); |
| 262 Value(StatsValueName name, bool b); | 261 Value(StatsValueName name, bool b); |
| 263 Value(StatsValueName name, const Id& value); | 262 Value(StatsValueName name, const Id& value); |
| 264 | 263 |
| 265 ~Value(); | 264 ~Value(); |
| 266 | 265 |
| 266 // Support ref counting. Note that for performance reasons, we | |
| 267 // don't use thread safe operations. Therefore, all operations | |
| 268 // affecting the ref count (in practice, creation and copying of | |
| 269 // the Values mapping) must occur on webrtc's signalling thread. | |
|
tommi
2017/01/18 11:59:22
can we use a thread or sequence checker in DCHECK
nisse-webrtc
2017/01/18 12:16:32
Sure, adding a ThreadChecker should be possible. A
| |
| 270 int AddRef() const { return ++ref_count_; } | |
| 271 int Release() const { | |
| 272 int count = --ref_count_; | |
| 273 if (!count) | |
| 274 delete this; | |
| 275 return count; | |
| 276 } | |
| 277 | |
| 267 // TODO(tommi): This compares name as well as value... | 278 // TODO(tommi): This compares name as well as value... |
| 268 // I think we should only need to compare the value part and | 279 // I think we should only need to compare the value part and |
| 269 // move the name part into a hash map. | 280 // move the name part into a hash map. |
| 270 bool Equals(const Value& other) const; | 281 bool Equals(const Value& other) const; |
| 271 | 282 |
| 272 // Comparison operators. Return true iff the current instance is of the | 283 // Comparison operators. Return true iff the current instance is of the |
| 273 // correct type and holds the same value. No conversion is performed so | 284 // correct type and holds the same value. No conversion is performed so |
| 274 // a string value of "123" is not equal to an int value of 123 and an int | 285 // a string value of "123" is not equal to an int value of 123 and an int |
| 275 // value of 123 is not equal to a float value of 123.0f. | 286 // value of 123 is not equal to a float value of 123.0f. |
| 276 // One exception to this is that types kInt and kInt64 can be compared and | 287 // One exception to this is that types kInt and kInt64 can be compared and |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 297 | 308 |
| 298 // Converts the native value to a string representation of the value. | 309 // Converts the native value to a string representation of the value. |
| 299 std::string ToString() const; | 310 std::string ToString() const; |
| 300 | 311 |
| 301 Type type() const { return type_; } | 312 Type type() const { return type_; } |
| 302 | 313 |
| 303 // TODO(tommi): Move |name| and |display_name| out of the Value struct. | 314 // TODO(tommi): Move |name| and |display_name| out of the Value struct. |
| 304 const StatsValueName name; | 315 const StatsValueName name; |
| 305 | 316 |
| 306 private: | 317 private: |
| 318 mutable int ref_count_ = 0; | |
| 319 | |
| 307 const Type type_; | 320 const Type type_; |
| 308 // TODO(tommi): Use C++ 11 union and make value_ const. | 321 // TODO(tommi): Use C++ 11 union and make value_ const. |
| 309 union InternalType { | 322 union InternalType { |
| 310 int int_; | 323 int int_; |
| 311 int64_t int64_; | 324 int64_t int64_; |
| 312 float float_; | 325 float float_; |
| 313 bool bool_; | 326 bool bool_; |
| 314 std::string* string_; | 327 std::string* string_; |
| 315 const char* static_string_; | 328 const char* static_string_; |
| 316 Id* id_; | 329 Id* id_; |
| 317 } value_; | 330 } value_; |
| 318 | 331 |
| 319 private: | |
| 320 RTC_DISALLOW_COPY_AND_ASSIGN(Value); | 332 RTC_DISALLOW_COPY_AND_ASSIGN(Value); |
| 321 }; | 333 }; |
| 322 | 334 |
| 323 // TODO(tommi): Consider using a similar approach to how we store Ids using | 335 typedef rtc::scoped_refptr<Value> ValuePtr; |
| 324 // scoped_refptr for values. | |
| 325 typedef rtc::linked_ptr<Value> ValuePtr; | |
| 326 typedef std::map<StatsValueName, ValuePtr> Values; | 336 typedef std::map<StatsValueName, ValuePtr> Values; |
| 327 | 337 |
| 328 // Ownership of |id| is passed to |this|. | 338 // Ownership of |id| is passed to |this|. |
| 329 explicit StatsReport(const Id& id); | 339 explicit StatsReport(const Id& id); |
| 330 | 340 |
| 331 // Factory functions for various types of stats IDs. | 341 // Factory functions for various types of stats IDs. |
| 332 static Id NewBandwidthEstimationId(); | 342 static Id NewBandwidthEstimationId(); |
| 333 static Id NewTypedId(StatsType type, const std::string& id); | 343 static Id NewTypedId(StatsType type, const std::string& id); |
| 334 static Id NewTypedIntId(StatsType type, int id); | 344 static Id NewTypedIntId(StatsType type, int id); |
| 335 static Id NewIdWithDirection( | 345 static Id NewIdWithDirection( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 StatsReport* Find(const StatsReport::Id& id); | 414 StatsReport* Find(const StatsReport::Id& id); |
| 405 | 415 |
| 406 private: | 416 private: |
| 407 Container list_; | 417 Container list_; |
| 408 rtc::ThreadChecker thread_checker_; | 418 rtc::ThreadChecker thread_checker_; |
| 409 }; | 419 }; |
| 410 | 420 |
| 411 } // namespace webrtc | 421 } // namespace webrtc |
| 412 | 422 |
| 413 #endif // WEBRTC_API_STATSTYPES_H_ | 423 #endif // WEBRTC_API_STATSTYPES_H_ |
| OLD | NEW |