Chromium Code Reviews| Index: components/ukm/test_ukm_recorder.cc |
| diff --git a/components/ukm/test_ukm_recorder.cc b/components/ukm/test_ukm_recorder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fa989f8284e600f6457afd94b8c6aae4c0d250de |
| --- /dev/null |
| +++ b/components/ukm/test_ukm_recorder.cc |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2017 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 "components/ukm/test_ukm_recorder.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/metrics/metrics_hashes.h" |
| +#include "components/ukm/ukm_source.h" |
| + |
| +namespace ukm { |
| + |
| +TestUkmRecorder::TestUkmRecorder() { |
| + EnableRecording(); |
| +} |
| + |
| +TestUkmRecorder::~TestUkmRecorder() = default; |
| + |
| +const std::map<ukm::SourceId, std::unique_ptr<UkmSource>>& |
| +TestUkmRecorder::GetSources() const { |
| + return sources(); |
| +} |
| + |
| +const UkmSource* TestUkmRecorder::GetSourceForUrl(const char* url) const { |
| + const UkmSource* source = nullptr; |
| + for (const auto& kv : sources()) { |
| + if (kv.second->url() == url) { |
| + DCHECK_EQ(nullptr, source); |
| + source = kv.second.get(); |
|
oystein (OOO til 10th of July)
2017/05/17 18:25:06
Right now we'll keep looping and return the last m
Steven Holte
2017/05/17 20:44:31
I've just renamed this from the same function in T
|
| + } |
| + } |
| + return source; |
| +} |
| + |
| +const UkmSource* TestUkmRecorder::GetSourceForSourceId( |
| + ukm::SourceId source_id) const { |
| + const UkmSource* source = nullptr; |
| + for (const auto& kv : sources()) { |
| + if (kv.second->id() == source_id) { |
| + DCHECK_EQ(nullptr, source); |
| + source = kv.second.get(); |
|
oystein (OOO til 10th of July)
2017/05/17 18:25:06
Same comment as above.
Steven Holte
2017/05/17 20:44:31
Ditto.
|
| + } |
| + } |
| + return source; |
| +} |
| + |
| +const mojom::UkmEntry* TestUkmRecorder::GetEntry(size_t entry_num) const { |
| + return entries()[entry_num].get(); |
|
oystein (OOO til 10th of July)
2017/05/17 18:25:06
DCHECK(entry_num < entries().size());
Steven Holte
2017/05/17 20:44:31
Done.
|
| +} |
| + |
| +const mojom::UkmEntry* TestUkmRecorder::GetEntryForEntryName( |
| + const char* entry_name) const { |
| + for (const auto& it : entries()) { |
| + if (it->event_hash == base::HashMetricName(entry_name)) |
|
oystein (OOO til 10th of July)
2017/05/17 18:25:06
Same as above; in this case we're returning the fi
Steven Holte
2017/05/17 20:44:31
I think this one just isn't bothering with the DCH
|
| + return it.get(); |
| + } |
| + return nullptr; |
| +} |
| + |
| +// static |
| +const mojom::UkmMetric* TestUkmRecorder::FindMetric( |
| + const mojom::UkmEntry* entry, |
| + const char* metric_name) { |
| + for (const auto& metric : entry->metrics) { |
| + if (metric->metric_hash == base::HashMetricName(metric_name)) |
| + return metric.get(); |
| + } |
| + return nullptr; |
| +} |
| + |
| +} // namespace ukm |