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

Unified Diff: components/ukm/test_ukm_recorder.cc

Issue 2893943004: Refactor UKM interface for mojo-ification (Closed)
Patch Set: Fixed contextualsearch 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ukm/test_ukm_recorder.h ('k') | components/ukm/test_ukm_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..26a1307fedeab9739eed5ee60fba24911f13a3a7
--- /dev/null
+++ b/components/ukm/test_ukm_recorder.cc
@@ -0,0 +1,67 @@
+// 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 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();
+ }
+ }
+ 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();
+ }
+ }
+ return source;
+}
+
+const mojom::UkmEntry* TestUkmRecorder::GetEntry(size_t entry_num) const {
+ DCHECK_LT(entry_num, entries().size());
+ return entries()[entry_num].get();
+}
+
+const mojom::UkmEntry* TestUkmRecorder::GetEntryForEntryName(
+ const char* entry_name) const {
+ for (const auto& it : entries()) {
+ if (it->event_hash == base::HashMetricName(entry_name))
+ 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
« no previous file with comments | « components/ukm/test_ukm_recorder.h ('k') | components/ukm/test_ukm_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698