OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/rappor/test_rappor_service.h" | 5 #include "components/rappor/test_rappor_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "components/rappor/byte_vector_utils.h" | 11 #include "components/rappor/byte_vector_utils.h" |
12 #include "components/rappor/proto/rappor_metric.pb.h" | 12 #include "components/rappor/proto/rappor_metric.pb.h" |
13 #include "components/rappor/rappor_parameters.h" | 13 #include "components/rappor/public/rappor_parameters.h" |
14 #include "components/rappor/rappor_prefs.h" | 14 #include "components/rappor/rappor_prefs.h" |
15 #include "components/rappor/test_log_uploader.h" | 15 #include "components/rappor/test_log_uploader.h" |
16 | 16 |
17 namespace rappor { | 17 namespace rappor { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 bool MockIsIncognito(bool* is_incognito) { | 21 bool MockIsIncognito(bool* is_incognito) { |
22 return *is_incognito; | 22 return *is_incognito; |
23 } | 23 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 TestRapporService::~TestRapporService() {} | 66 TestRapporService::~TestRapporService() {} |
67 | 67 |
68 std::unique_ptr<Sample> TestRapporService::CreateSample(RapporType type) { | 68 std::unique_ptr<Sample> TestRapporService::CreateSample(RapporType type) { |
69 std::unique_ptr<TestSample> test_sample(new TestSample(type)); | 69 std::unique_ptr<TestSample> test_sample(new TestSample(type)); |
70 return std::move(test_sample); | 70 return std::move(test_sample); |
71 } | 71 } |
72 | 72 |
73 // Intercepts the sample being recorded and saves it in a test structure. | 73 // Intercepts the sample being recorded and saves it in a test structure. |
74 void TestRapporService::RecordSampleObj(const std::string& metric_name, | 74 void TestRapporService::RecordSample(const std::string& metric_name, |
75 std::unique_ptr<Sample> sample) { | 75 std::unique_ptr<Sample> sample) { |
76 TestSample* test_sample = static_cast<TestSample*>(sample.get()); | 76 TestSample* test_sample = static_cast<TestSample*>(sample.get()); |
77 // Erase the previous sample if we logged one. | 77 // Erase the previous sample if we logged one. |
78 shadows_.erase(metric_name); | 78 shadows_.erase(metric_name); |
79 shadows_.insert(std::pair<std::string, TestSample::Shadow>( | 79 shadows_.insert(std::pair<std::string, TestSample::Shadow>( |
80 metric_name, test_sample->GetShadow())); | 80 metric_name, test_sample->GetShadow())); |
81 // Original version is still called. | 81 // Original version is still called. |
82 RapporService::RecordSampleObj(metric_name, std::move(sample)); | 82 RapporService::RecordSample(metric_name, std::move(sample)); |
83 } | 83 } |
84 | 84 |
85 void TestRapporService::RecordSample(const std::string& metric_name, | 85 void TestRapporService::RecordSampleString(const std::string& metric_name, |
86 RapporType type, | 86 RapporType type, |
87 const std::string& sample) { | 87 const std::string& sample) { |
88 // Save the recorded sample to the local structure. | 88 // Save the recorded sample to the local structure. |
89 RapporSample rappor_sample; | 89 RapporSample rappor_sample; |
90 rappor_sample.type = type; | 90 rappor_sample.type = type; |
91 rappor_sample.value = sample; | 91 rappor_sample.value = sample; |
92 samples_[metric_name] = rappor_sample; | 92 samples_[metric_name] = rappor_sample; |
93 // Original version is still called. | 93 // Original version is still called. |
94 RapporService::RecordSample(metric_name, type, sample); | 94 RapporService::RecordSampleString(metric_name, type, sample); |
95 } | 95 } |
96 | 96 |
97 int TestRapporService::GetReportsCount() { | 97 int TestRapporService::GetReportsCount() { |
98 RapporReports reports; | 98 RapporReports reports; |
99 ExportMetrics(&reports); | 99 ExportMetrics(&reports); |
100 return reports.report_size(); | 100 return reports.report_size(); |
101 } | 101 } |
102 | 102 |
103 void TestRapporService::GetReports(RapporReports* reports) { | 103 void TestRapporService::GetReports(RapporReports* reports) { |
104 ExportMetrics(reports); | 104 ExportMetrics(reports); |
(...skipping 23 matching lines...) Expand all Loading... |
128 void TestRapporService::CancelNextLogRotation() { | 128 void TestRapporService::CancelNextLogRotation() { |
129 next_rotation_ = base::TimeDelta(); | 129 next_rotation_ = base::TimeDelta(); |
130 } | 130 } |
131 | 131 |
132 // Schedule the next call to OnLogInterval. | 132 // Schedule the next call to OnLogInterval. |
133 void TestRapporService::ScheduleNextLogRotation(base::TimeDelta interval) { | 133 void TestRapporService::ScheduleNextLogRotation(base::TimeDelta interval) { |
134 next_rotation_ = interval; | 134 next_rotation_ = interval; |
135 } | 135 } |
136 | 136 |
137 } // namespace rappor | 137 } // namespace rappor |
OLD | NEW |