OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_TEST_STATS_DICTIONARY_H_ | |
6 #define CHROME_BROWSER_MEDIA_WEBRTC_TEST_STATS_DICTIONARY_H_ | |
7 | |
8 #include <functional> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/values.h" | |
14 | |
15 namespace content { | |
16 | |
17 class TestStatsDictionary; | |
18 | |
19 class TestStatsReportDictionary | |
20 : public base::RefCounted<TestStatsReportDictionary> { | |
21 public: | |
22 explicit TestStatsReportDictionary( | |
23 std::unique_ptr<base::DictionaryValue> report); | |
24 | |
25 void ForEach(std::function<void(const TestStatsDictionary&)> iteration); | |
26 std::vector<TestStatsDictionary> Filter( | |
27 std::function<bool(const TestStatsDictionary&)> filter); | |
28 | |
29 std::unique_ptr<TestStatsDictionary> Get(const std::string& id); | |
30 std::vector<TestStatsDictionary> GetAll(); | |
31 std::vector<TestStatsDictionary> GetByType(const std::string& type); | |
32 | |
33 private: | |
34 friend class base::RefCounted<TestStatsReportDictionary>; | |
35 ~TestStatsReportDictionary(); | |
36 | |
37 std::unique_ptr<base::DictionaryValue> report_; | |
38 }; | |
39 | |
40 class TestStatsDictionary { | |
41 public: | |
42 TestStatsDictionary(TestStatsReportDictionary* report, | |
43 const base::DictionaryValue* stats); | |
44 TestStatsDictionary(const TestStatsDictionary& other); | |
45 ~TestStatsDictionary(); | |
46 | |
47 bool IsBoolean(const std::string& key) const; | |
48 bool GetBoolean(const std::string& key) const; | |
49 | |
50 bool IsNumber(const std::string& key) const; | |
51 double GetNumber(const std::string& key) const; | |
52 | |
53 bool IsString(const std::string& key) const; | |
54 std::string GetString(const std::string& key) const; | |
55 | |
56 bool IsSequenceBoolean(const std::string& key) const; | |
57 std::vector<bool> GetSequenceBoolean(const std::string& key) const; | |
58 | |
59 bool IsSequenceNumber(const std::string& key) const; | |
60 std::vector<double> GetSequenceNumber(const std::string& key) const; | |
61 | |
62 bool IsSequenceString(const std::string& key) const; | |
63 std::vector<std::string> GetSequenceString(const std::string& key) const; | |
64 | |
65 std::string ToString() const; | |
66 | |
67 private: | |
68 bool GetBoolean(const std::string& key, bool* out) const; | |
69 bool GetNumber(const std::string& key, double* out) const; | |
70 bool GetString(const std::string& key, std::string* out) const; | |
71 bool GetSequenceBoolean( | |
72 const std::string& key, std::vector<bool>* out) const; | |
73 bool GetSequenceNumber( | |
74 const std::string& key, std::vector<double>* out) const; | |
75 bool GetSequenceString( | |
76 const std::string& key, std::vector<std::string>* out) const; | |
77 | |
78 // The reference keeps the report alive which indirectly owns |stats_|. | |
79 scoped_refptr<TestStatsReportDictionary> report_; | |
80 const base::DictionaryValue* stats_; | |
81 }; | |
82 | |
83 } // namespace content | |
84 | |
85 #endif // CHROME_BROWSER_MEDIA_WEBRTC_TEST_STATS_DICTIONARY_H_ | |
OLD | NEW |