Roll src/third_party/WebKit 5668f22:1929caf (svn 192731:192750)
[chromium-blink-merge.git] / components / rappor / test_rappor_service.cc
blobaa54a949c5a161982cedf5f88562f8979a5207e5
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
3 // found in the LICENSE file.
5 #include "components/rappor/test_rappor_service.h"
7 #include "components/rappor/byte_vector_utils.h"
8 #include "components/rappor/proto/rappor_metric.pb.h"
9 #include "components/rappor/rappor_parameters.h"
10 #include "components/rappor/rappor_prefs.h"
11 #include "components/rappor/test_log_uploader.h"
13 namespace rappor {
15 namespace {
17 bool MockIsIncognito(bool* is_incognito) {
18 return *is_incognito;
21 } // namespace
23 TestRapporService::TestRapporService()
24 : RapporService(&test_prefs_, base::Bind(&MockIsIncognito, &is_incognito_)),
25 next_rotation_(base::TimeDelta()),
26 is_incognito_(false) {
27 RegisterPrefs(test_prefs_.registry());
28 test_uploader_ = new TestLogUploader();
29 InitializeInternal(make_scoped_ptr(test_uploader_),
31 HmacByteVectorGenerator::GenerateEntropyInput());
32 Update(FINE_LEVEL, true);
35 TestRapporService::~TestRapporService() {}
37 void TestRapporService::RecordSample(const std::string& metric_name,
38 RapporType type,
39 const std::string& sample) {
40 // Save the recorded sample to the local structure.
41 RapporSample rappor_sample;
42 rappor_sample.type = type;
43 rappor_sample.value = sample;
44 samples_[metric_name] = rappor_sample;
45 // Original version is still called.
46 RapporService::RecordSample(metric_name, type, sample);
49 int TestRapporService::GetReportsCount() {
50 RapporReports reports;
51 ExportMetrics(&reports);
52 return reports.report_size();
55 void TestRapporService::GetReports(RapporReports* reports) {
56 ExportMetrics(reports);
59 bool TestRapporService::GetRecordedSampleForMetric(
60 const std::string& metric_name,
61 std::string* sample,
62 RapporType* type) {
63 SamplesMap::iterator it = samples_.find(metric_name);
64 if (it == samples_.end())
65 return false;
66 *sample = it->second.value;
67 *type = it->second.type;
68 return true;
71 // Cancel the next call to OnLogInterval.
72 void TestRapporService::CancelNextLogRotation() {
73 next_rotation_ = base::TimeDelta();
76 // Schedule the next call to OnLogInterval.
77 void TestRapporService::ScheduleNextLogRotation(base::TimeDelta interval) {
78 next_rotation_ = interval;
81 } // namespace rappor