Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: components/ukm/test_ukm_recorder.cc

Issue 2883563002: Refactor UKM interface for mojo-ification (Closed)
Patch Set: Fix uma_session_stats.cc Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "components/ukm/test_ukm_recorder.h"
6
7 #include "base/logging.h"
8 #include "base/metrics/metrics_hashes.h"
9 #include "components/ukm/ukm_source.h"
10
11 namespace ukm {
12
13 TestUkmRecorder::TestUkmRecorder() {
14 EnableRecording();
15 }
16
17 TestUkmRecorder::~TestUkmRecorder() = default;
18
19 const UkmSource* TestUkmRecorder::GetSourceForUrl(const char* url) const {
20 const UkmSource* source = nullptr;
21 for (const auto& kv : sources()) {
22 if (kv.second->url() == url) {
23 DCHECK_EQ(nullptr, source);
24 source = kv.second.get();
25 }
26 }
27 return source;
28 }
29
30 const UkmSource* TestUkmRecorder::GetSourceForSourceId(
31 ukm::SourceId source_id) const {
32 const UkmSource* source = nullptr;
33 for (const auto& kv : sources()) {
34 if (kv.second->id() == source_id) {
35 DCHECK_EQ(nullptr, source);
36 source = kv.second.get();
37 }
38 }
39 return source;
40 }
41
42 const mojom::UkmEntry* TestUkmRecorder::GetEntry(size_t entry_num) const {
43 DCHECK_LT(entry_num, entries().size());
44 return entries()[entry_num].get();
45 }
46
47 const mojom::UkmEntry* TestUkmRecorder::GetEntryForEntryName(
48 const char* entry_name) const {
49 for (const auto& it : entries()) {
50 if (it->event_hash == base::HashMetricName(entry_name))
51 return it.get();
52 }
53 return nullptr;
54 }
55
56 // static
57 const mojom::UkmMetric* TestUkmRecorder::FindMetric(
58 const mojom::UkmEntry* entry,
59 const char* metric_name) {
60 for (const auto& metric : entry->metrics) {
61 if (metric->metric_hash == base::HashMetricName(metric_name))
62 return metric.get();
63 }
64 return nullptr;
65 }
66
67 } // namespace ukm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698