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

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

Issue 2883563002: Refactor UKM interface for mojo-ification (Closed)
Patch Set: Move interface to next CL 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 std::map<ukm::SourceId, std::unique_ptr<UkmSource>>&
20 TestUkmRecorder::GetSources() const {
21 return sources();
22 }
23
24 const UkmSource* TestUkmRecorder::GetSourceForUrl(const char* url) const {
25 const UkmSource* source = nullptr;
26 for (const auto& kv : sources()) {
27 if (kv.second->url() == url) {
28 DCHECK_EQ(nullptr, source);
29 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
30 }
31 }
32 return source;
33 }
34
35 const UkmSource* TestUkmRecorder::GetSourceForSourceId(
36 ukm::SourceId source_id) const {
37 const UkmSource* source = nullptr;
38 for (const auto& kv : sources()) {
39 if (kv.second->id() == source_id) {
40 DCHECK_EQ(nullptr, source);
41 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.
42 }
43 }
44 return source;
45 }
46
47 const mojom::UkmEntry* TestUkmRecorder::GetEntry(size_t entry_num) const {
48 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.
49 }
50
51 const mojom::UkmEntry* TestUkmRecorder::GetEntryForEntryName(
52 const char* entry_name) const {
53 for (const auto& it : entries()) {
54 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
55 return it.get();
56 }
57 return nullptr;
58 }
59
60 // static
61 const mojom::UkmMetric* TestUkmRecorder::FindMetric(
62 const mojom::UkmEntry* entry,
63 const char* metric_name) {
64 for (const auto& metric : entry->metrics) {
65 if (metric->metric_hash == base::HashMetricName(metric_name))
66 return metric.get();
67 }
68 return nullptr;
69 }
70
71 } // namespace ukm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698