Commit 6f83c851 authored by Robert Kaplow's avatar Robert Kaplow Committed by Commit Bot

Strict UKM entry whitelisting.

Currently if there is no whitelist, we record everything. We shouldn't do this since if a user has no field trial params (first run, etc.), they will record everything, avoiding the whitelist.

Also changed a bitwise and to && while I was making a change. No-op but seems bad style (and apparently can be different as & doesn't shortcut).

Bug: 820632
Change-Id: I3fd3b1ca6669294e61467bb0f4d0ad87fb2ff576
Reviewed-on: https://chromium-review.googlesource.com/957384
Commit-Queue: Robert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544034}
parent 866affd2
...@@ -143,7 +143,7 @@ void MetricsServicesManager::UpdateUkmService() { ...@@ -143,7 +143,7 @@ void MetricsServicesManager::UpdateUkmService() {
metrics_service_client_->IsHistorySyncEnabledOnAllProfiles(); metrics_service_client_->IsHistorySyncEnabledOnAllProfiles();
bool is_incognito = client_->IsIncognitoSessionActive(); bool is_incognito = client_->IsIncognitoSessionActive();
if (consent_given_ && sync_enabled & !is_incognito) { if (consent_given_ && sync_enabled && !is_incognito) {
ukm->EnableRecording( ukm->EnableRecording(
metrics_service_client_->IsExtensionSyncEnabledOnAllProfiles()); metrics_service_client_->IsExtensionSyncEnabledOnAllProfiles());
if (may_upload_) if (may_upload_)
......
...@@ -67,7 +67,13 @@ TestUkmRecorder::~TestUkmRecorder() { ...@@ -67,7 +67,13 @@ TestUkmRecorder::~TestUkmRecorder() {
}; };
bool TestUkmRecorder::ShouldRestrictToWhitelistedSourceIds() const { bool TestUkmRecorder::ShouldRestrictToWhitelistedSourceIds() const {
// In tests, we want to record all source ids (not just hose that are // In tests, we want to record all source ids (not just those that are
// whitelisted).
return false;
}
bool TestUkmRecorder::ShouldRestrictToWhitelistedEntries() const {
// In tests, we want to record all entries (not just those that are
// whitelisted). // whitelisted).
return false; return false;
} }
......
...@@ -29,6 +29,7 @@ class TestUkmRecorder : public UkmRecorderImpl { ...@@ -29,6 +29,7 @@ class TestUkmRecorder : public UkmRecorderImpl {
~TestUkmRecorder() override; ~TestUkmRecorder() override;
bool ShouldRestrictToWhitelistedSourceIds() const override; bool ShouldRestrictToWhitelistedSourceIds() const override;
bool ShouldRestrictToWhitelistedEntries() const override;
size_t sources_count() const { return sources().size(); } size_t sources_count() const { return sources().size(); }
......
...@@ -306,6 +306,10 @@ bool UkmRecorderImpl::ShouldRestrictToWhitelistedSourceIds() const { ...@@ -306,6 +306,10 @@ bool UkmRecorderImpl::ShouldRestrictToWhitelistedSourceIds() const {
kUkmFeature, "RestrictToWhitelistedSourceIds", false); kUkmFeature, "RestrictToWhitelistedSourceIds", false);
} }
bool UkmRecorderImpl::ShouldRestrictToWhitelistedEntries() const {
return true;
}
UkmRecorderImpl::EventAggregate::EventAggregate() = default; UkmRecorderImpl::EventAggregate::EventAggregate() = default;
UkmRecorderImpl::EventAggregate::~EventAggregate() = default; UkmRecorderImpl::EventAggregate::~EventAggregate() = default;
...@@ -371,7 +375,7 @@ void UkmRecorderImpl::AddEntry(mojom::UkmEntryPtr entry) { ...@@ -371,7 +375,7 @@ void UkmRecorderImpl::AddEntry(mojom::UkmEntryPtr entry) {
return; return;
} }
if (!whitelisted_entry_hashes_.empty() && if (ShouldRestrictToWhitelistedEntries() &&
!base::ContainsKey(whitelisted_entry_hashes_, entry->event_hash)) { !base::ContainsKey(whitelisted_entry_hashes_, entry->event_hash)) {
RecordDroppedEntry(DroppedDataReason::NOT_WHITELISTED); RecordDroppedEntry(DroppedDataReason::NOT_WHITELISTED);
return; return;
......
...@@ -69,6 +69,8 @@ class UkmRecorderImpl : public UkmRecorder { ...@@ -69,6 +69,8 @@ class UkmRecorderImpl : public UkmRecorder {
virtual bool ShouldRestrictToWhitelistedSourceIds() const; virtual bool ShouldRestrictToWhitelistedSourceIds() const;
virtual bool ShouldRestrictToWhitelistedEntries() const;
private: private:
friend ::metrics::UkmBrowserTest; friend ::metrics::UkmBrowserTest;
friend ::metrics::UkmEGTestHelper; friend ::metrics::UkmEGTestHelper;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment