| OLD | NEW |
| (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_service.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/metrics/metrics_hashes.h" | |
| 9 #include "components/ukm/ukm_entry.h" | |
| 10 #include "components/ukm/ukm_source.h" | |
| 11 | |
| 12 namespace ukm { | |
| 13 | |
| 14 UkmServiceTestingHarness::UkmServiceTestingHarness() { | |
| 15 UkmService::RegisterPrefs(test_prefs_.registry()); | |
| 16 test_prefs_.ClearPref(prefs::kUkmClientId); | |
| 17 test_prefs_.ClearPref(prefs::kUkmSessionId); | |
| 18 test_prefs_.ClearPref(prefs::kUkmPersistedLogs); | |
| 19 | |
| 20 test_ukm_service_ = base::MakeUnique<TestUkmService>(&test_prefs_); | |
| 21 } | |
| 22 | |
| 23 UkmServiceTestingHarness::~UkmServiceTestingHarness() = default; | |
| 24 | |
| 25 TestUkmService::TestUkmService(PrefService* prefs_service) | |
| 26 : UkmService(prefs_service, &test_metrics_service_client_) { | |
| 27 EnableRecording(); | |
| 28 DisableReporting(); | |
| 29 } | |
| 30 | |
| 31 TestUkmService::~TestUkmService() = default; | |
| 32 | |
| 33 const std::map<int32_t, std::unique_ptr<UkmSource>>& | |
| 34 TestUkmService::GetSources() const { | |
| 35 return sources_for_testing(); | |
| 36 } | |
| 37 | |
| 38 const UkmSource* TestUkmService::GetSourceForUrl(const char* url) const { | |
| 39 const UkmSource* source = nullptr; | |
| 40 for (const auto& kv : sources_for_testing()) { | |
| 41 if (kv.second->url() == url) { | |
| 42 DCHECK_EQ(nullptr, source); | |
| 43 source = kv.second.get(); | |
| 44 } | |
| 45 } | |
| 46 return source; | |
| 47 } | |
| 48 | |
| 49 const UkmSource* TestUkmService::GetSourceForSourceId(int32_t source_id) const { | |
| 50 const UkmSource* source = nullptr; | |
| 51 for (const auto& kv : sources_for_testing()) { | |
| 52 if (kv.second->id() == source_id) { | |
| 53 DCHECK_EQ(nullptr, source); | |
| 54 source = kv.second.get(); | |
| 55 } | |
| 56 } | |
| 57 return source; | |
| 58 } | |
| 59 | |
| 60 const UkmEntry* TestUkmService::GetEntry(size_t entry_num) const { | |
| 61 return entries_for_testing()[entry_num].get(); | |
| 62 } | |
| 63 | |
| 64 const UkmEntry* TestUkmService::GetEntryForEntryName( | |
| 65 const char* entry_name) const { | |
| 66 for (const auto& it : entries_for_testing()) { | |
| 67 if (it->event_hash() == base::HashMetricName(entry_name)) | |
| 68 return it.get(); | |
| 69 } | |
| 70 return nullptr; | |
| 71 } | |
| 72 | |
| 73 } // namespace ukm | |
| OLD | NEW |