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

Unified Diff: components/ukm/ukm_service.cc

Issue 2749433002: Create Field Trial param for whitelisting UKM Entries. (Closed)
Patch Set: add comment Created 3 years, 9 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/ukm_service.h ('k') | components/ukm/ukm_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ukm/ukm_service.cc
diff --git a/components/ukm/ukm_service.cc b/components/ukm/ukm_service.cc
index a43f426f346986148a9a15738dfc4f7c2a885207..2d5272d552158d7821f8deedf7f3f3031c46724f 100644
--- a/components/ukm/ukm_service.cc
+++ b/components/ukm/ukm_service.cc
@@ -14,8 +14,10 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
+#include "base/metrics/metrics_hashes.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
#include "base/time/time.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_log_uploader.h"
@@ -68,6 +70,19 @@ std::string GetServerUrl() {
return kDefaultServerUrl;
}
+// Gets the list of whitelisted Entries as string.
Alexei Svitkine (slow) 2017/03/14 15:40:56 Is it comma-separated or something? Mention. Or a
rkaplow 2017/03/14 18:01:41 Done.
+std::string GetWhitelistEntries() {
+ return base::GetFieldTrialParamValueByFeature(kUkmFeature,
+ "WhitelistEntries");
+}
+
+// Returns true if we should use the whitelist of Entries to record.
+bool UseWhitelistEntries() {
+ // If the Field Trial param is empty, we will default to not using the
+ // whitelist.
+ return GetWhitelistEntries() != std::string();
Alexei Svitkine (slow) 2017/03/14 15:40:56 Nit: ! .empty()
rkaplow 2017/03/14 18:01:41 Acknowledged.
+}
+
// Gets the maximum number of Sources we'll keep in memory before discarding any
// new ones being added.
size_t GetMaxSources() {
@@ -126,6 +141,7 @@ enum class DroppedDataReason {
NOT_DROPPED = 0,
RECORDING_DISABLED = 1,
MAX_HIT = 2,
+ NOT_WHITELISTED = 3,
NUM_DROPPED_DATA_REASONS
};
@@ -181,6 +197,8 @@ UkmService::UkmService(PrefService* pref_service,
for (auto& provider : metrics_providers_)
provider->Init();
+
+ StoreWhitelistedEntries();
}
UkmService::~UkmService() {
@@ -493,7 +511,22 @@ void UkmService::AddEntry(std::unique_ptr<UkmEntry> entry) {
return;
}
+ if (UseWhitelistEntries() &&
Alexei Svitkine (slow) 2017/03/14 15:40:56 Nit: I think it would be cleaner to just check !wh
rkaplow 2017/03/14 18:01:41 agreed
+ !base::ContainsKey(whitelisted_entry_hashes_, entry->event_hash())) {
+ RecordDroppedEntry(DroppedDataReason::NOT_WHITELISTED);
+ return;
+ }
+
entries_.push_back(std::move(entry));
}
+void UkmService::StoreWhitelistedEntries() {
+ const auto entries =
+ base::SplitString(GetWhitelistEntries(), ",", base::TRIM_WHITESPACE,
+ base::SPLIT_WANT_NONEMPTY);
+ for (const auto& entry_string : entries) {
+ whitelisted_entry_hashes_.insert(base::HashMetricName(entry_string));
+ }
+}
+
} // namespace ukm
« no previous file with comments | « components/ukm/ukm_service.h ('k') | components/ukm/ukm_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698