summaryrefslogtreecommitdiff
path: root/chromium/components/ukm
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-03-12 09:13:00 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-03-16 09:58:26 +0000
commit03561cae90f1d99b5c54b1ef3be69f10e882b25e (patch)
treecc5f0958e823c044e7ae51cc0117fe51432abe5e /chromium/components/ukm
parentfa98118a45f7e169f8846086dc2c22c49a8ba310 (diff)
downloadqtwebengine-chromium-03561cae90f1d99b5c54b1ef3be69f10e882b25e.tar.gz
BASELINE: Update Chromium to 88.0.4324.208
Change-Id: I3ae87d23e4eff4b4a469685658740a213600c667 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/ukm')
-rw-r--r--chromium/components/ukm/content/source_url_recorder_test.cc8
-rw-r--r--chromium/components/ukm/debug/ukm_internals.html1
-rw-r--r--chromium/components/ukm/observers/history_delete_observer.cc4
-rw-r--r--chromium/components/ukm/observers/history_delete_observer.h7
-rw-r--r--chromium/components/ukm/observers/ukm_consent_state_observer.cc7
-rw-r--r--chromium/components/ukm/observers/ukm_consent_state_observer.h7
-rw-r--r--chromium/components/ukm/ukm_recorder_impl.cc28
-rw-r--r--chromium/components/ukm/ukm_recorder_impl_unittest.cc3
-rw-r--r--chromium/components/ukm/ukm_reporting_service.cc35
-rw-r--r--chromium/components/ukm/ukm_reporting_service.h6
-rw-r--r--chromium/components/ukm/ukm_service.cc31
-rw-r--r--chromium/components/ukm/ukm_service.h9
-rw-r--r--chromium/components/ukm/ukm_service_unittest.cc3
13 files changed, 107 insertions, 42 deletions
diff --git a/chromium/components/ukm/content/source_url_recorder_test.cc b/chromium/components/ukm/content/source_url_recorder_test.cc
index 475228979bd..04f1a50c73f 100644
--- a/chromium/components/ukm/content/source_url_recorder_test.cc
+++ b/chromium/components/ukm/content/source_url_recorder_test.cc
@@ -10,6 +10,7 @@
#include "content/public/test/test_renderer_host.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source.h"
+#include "services/metrics/public/cpp/ukm_source_id.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/ukm/source.pb.h"
#include "url/gurl.h"
@@ -66,13 +67,13 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, InitialUrl) {
size_t document_type_source_count = 0;
for (const auto& kv : sources) {
if (ukm::GetSourceIdType(kv.first) ==
- base::UkmSourceId::Type::NAVIGATION_ID) {
+ ukm::SourceIdObj::Type::NAVIGATION_ID) {
// The navigation source has both URLs.
EXPECT_EQ(initial_url, kv.second->urls().front());
EXPECT_EQ(final_url, kv.second->urls().back());
navigation_type_source_count++;
}
- if (ukm::GetSourceIdType(kv.first) == base::UkmSourceId::Type::DEFAULT) {
+ if (ukm::GetSourceIdType(kv.first) == ukm::SourceIdObj::Type::DEFAULT) {
// The document source has the final URL which is one set on the
// committed document.
EXPECT_EQ(final_url, kv.second->urls().front());
@@ -129,8 +130,7 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, SameDocumentNavigation) {
for (auto& kv : test_ukm_recorder_.GetSources()) {
// Populate protos from the navigation sources.
- if (ukm::GetSourceIdType(kv.first) !=
- base::UkmSourceId::Type::NAVIGATION_ID)
+ if (ukm::GetSourceIdType(kv.first) != ukm::SourceIdObj::Type::NAVIGATION_ID)
continue;
if (kv.second->url() == url1) {
diff --git a/chromium/components/ukm/debug/ukm_internals.html b/chromium/components/ukm/debug/ukm_internals.html
index 7f74dd63429..054c88fd0b5 100644
--- a/chromium/components/ukm/debug/ukm_internals.html
+++ b/chromium/components/ukm/debug/ukm_internals.html
@@ -5,6 +5,7 @@
<html lang="en">
<meta charset="utf-8">
<script src="chrome://resources/js/cr.js"></script>
+ <script src="chrome://resources/js/assert.js"></script>
<script src="chrome://resources/js/promise_resolver.js"></script>
<script src="chrome://resources/js/util.js"></script>
<if expr="is_ios">
diff --git a/chromium/components/ukm/observers/history_delete_observer.cc b/chromium/components/ukm/observers/history_delete_observer.cc
index bbc71a09c9a..55dae084cfe 100644
--- a/chromium/components/ukm/observers/history_delete_observer.cc
+++ b/chromium/components/ukm/observers/history_delete_observer.cc
@@ -13,7 +13,7 @@ HistoryDeleteObserver::~HistoryDeleteObserver() {}
void HistoryDeleteObserver::ObserveServiceForDeletions(
history::HistoryService* history_service) {
if (history_service)
- history_observer_.Add(history_service);
+ history_observations_.AddObservation(history_service);
}
void HistoryDeleteObserver::OnURLsDeleted(
@@ -25,7 +25,7 @@ void HistoryDeleteObserver::OnURLsDeleted(
void HistoryDeleteObserver::HistoryServiceBeingDeleted(
history::HistoryService* history_service) {
- history_observer_.Remove(history_service);
+ history_observations_.RemoveObservation(history_service);
}
} // namespace ukm
diff --git a/chromium/components/ukm/observers/history_delete_observer.h b/chromium/components/ukm/observers/history_delete_observer.h
index c27efadf99b..7a96bc380db 100644
--- a/chromium/components/ukm/observers/history_delete_observer.h
+++ b/chromium/components/ukm/observers/history_delete_observer.h
@@ -7,7 +7,7 @@
#include <set>
-#include "base/scoped_observer.h"
+#include "base/scoped_multi_source_observation.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_service_observer.h"
@@ -34,8 +34,9 @@ class HistoryDeleteObserver : public history::HistoryServiceObserver {
private:
// Tracks observed history services, for cleanup.
- ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
- history_observer_{this};
+ base::ScopedMultiSourceObservation<history::HistoryService,
+ history::HistoryServiceObserver>
+ history_observations_{this};
DISALLOW_COPY_AND_ASSIGN(HistoryDeleteObserver);
};
diff --git a/chromium/components/ukm/observers/ukm_consent_state_observer.cc b/chromium/components/ukm/observers/ukm_consent_state_observer.cc
index e67a74bf46f..2c9da4b4d69 100644
--- a/chromium/components/ukm/observers/ukm_consent_state_observer.cc
+++ b/chromium/components/ukm/observers/ukm_consent_state_observer.cc
@@ -18,7 +18,7 @@ using unified_consent::UrlKeyedDataCollectionConsentHelper;
namespace ukm {
-UkmConsentStateObserver::UkmConsentStateObserver() : sync_observer_(this) {}
+UkmConsentStateObserver::UkmConsentStateObserver() = default;
UkmConsentStateObserver::~UkmConsentStateObserver() {
for (const auto& entry : consent_helpers_) {
@@ -55,7 +55,7 @@ void UkmConsentStateObserver::StartObserving(syncer::SyncService* sync_service,
consent_helper->AddObserver(this);
consent_helpers_[sync_service] = std::move(consent_helper);
- sync_observer_.Add(sync_service);
+ sync_observations_.AddObservation(sync_service);
UpdateUkmAllowedForAllProfiles(false);
}
@@ -149,7 +149,8 @@ void UkmConsentStateObserver::OnSyncShutdown(syncer::SyncService* sync) {
found->second->RemoveObserver(this);
consent_helpers_.erase(found);
}
- sync_observer_.Remove(sync);
+ DCHECK(sync_observations_.IsObservingSource(sync));
+ sync_observations_.RemoveObservation(sync);
previous_states_.erase(sync);
UpdateUkmAllowedForAllProfiles(/*must_purge=*/false);
}
diff --git a/chromium/components/ukm/observers/ukm_consent_state_observer.h b/chromium/components/ukm/observers/ukm_consent_state_observer.h
index 4d214765b1c..258f46a85d9 100644
--- a/chromium/components/ukm/observers/ukm_consent_state_observer.h
+++ b/chromium/components/ukm/observers/ukm_consent_state_observer.h
@@ -7,7 +7,7 @@
#include <map>
-#include "base/scoped_observer.h"
+#include "base/scoped_multi_source_observation.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_service_observer.h"
#include "components/unified_consent/url_keyed_data_collection_consent_helper.h"
@@ -69,8 +69,9 @@ class UkmConsentStateObserver
bool CheckPreviousStatesAllowExtensionUkm();
// Tracks observed sync services, for cleanup.
- ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver>
- sync_observer_;
+ base::ScopedMultiSourceObservation<syncer::SyncService,
+ syncer::SyncServiceObserver>
+ sync_observations_{this};
// State data about profiles that we need to remember.
struct ProfileState {
diff --git a/chromium/components/ukm/ukm_recorder_impl.cc b/chromium/components/ukm/ukm_recorder_impl.cc
index 0cf4bb4ff63..0871b25e50c 100644
--- a/chromium/components/ukm/ukm_recorder_impl.cc
+++ b/chromium/components/ukm/ukm_recorder_impl.cc
@@ -98,6 +98,24 @@ void LogEventHashAsUmaHistogram(const std::string& histogram_name,
event_hash & 0x7fffffff);
}
+// Artificially inflates counts of some event types reported to UMA histogram.
+// TODO(crbug/1137922): remove this artificial inflation of counts after alerts
+// are tested.
+void MaybeInflateHistogramCount(const std::string& histogram_name,
+ uint64_t event_hash) {
+ const static std::map<uint64_t, size_t> event_hash_to_multipliers = {
+ {builders::Media_BasicPlayback::kEntryNameHash, 4},
+ {builders::RendererSchedulerTask::kEntryNameHash, 2},
+ {builders::HistoryNavigation::kEntryNameHash, 99},
+ };
+
+ auto iter = event_hash_to_multipliers.find(event_hash);
+ if (iter != event_hash_to_multipliers.end()) {
+ for (size_t i = 0; i < iter->second; ++i)
+ LogEventHashAsUmaHistogram(histogram_name, event_hash);
+ }
+}
+
enum class DroppedDataReason {
NOT_DROPPED = 0,
RECORDING_DISABLED = 1,
@@ -354,9 +372,9 @@ void UkmRecorderImpl::StoreRecordingsInReport(Report* report) {
for (const auto& kv : recordings_.sources) {
// Don't keep sources of these types after current report because their
// entries are logged only at source creation time.
- if (GetSourceIdType(kv.first) == base::UkmSourceId::Type::APP_ID ||
- GetSourceIdType(kv.first) == base::UkmSourceId::Type::HISTORY_ID ||
- GetSourceIdType(kv.first) == base::UkmSourceId::Type::WEBAPK_ID ||
+ if (GetSourceIdType(kv.first) == ukm::SourceIdObj::Type::APP_ID ||
+ GetSourceIdType(kv.first) == ukm::SourceIdObj::Type::HISTORY_ID ||
+ GetSourceIdType(kv.first) == ukm::SourceIdObj::Type::WEBAPK_ID ||
GetSourceIdType(kv.first) == SourceIdType::PAYMENT_APP_ID) {
MarkSourceForDeletion(kv.first);
}
@@ -378,7 +396,7 @@ void UkmRecorderImpl::StoreRecordingsInReport(Report* report) {
if (!base::Contains(source_ids_seen, kv.first)) {
continue;
} else {
- // Source of base::UkmSourceId::Type::DEFAULT type will not be kept
+ // Source of ukm::SourceIdObj::Type::DEFAULT type will not be kept
// after entries are logged.
MarkSourceForDeletion(kv.first);
}
@@ -761,6 +779,8 @@ void UkmRecorderImpl::AddEntry(mojom::UkmEntryPtr entry) {
// entry counts.
LogEventHashAsUmaHistogram("UKM.Entries.Recorded.ByEntryHash",
entry->event_hash);
+ MaybeInflateHistogramCount("UKM.Entries.Recorded.ByEntryHash",
+ entry->event_hash);
recordings_.entries.push_back(std::move(entry));
}
diff --git a/chromium/components/ukm/ukm_recorder_impl_unittest.cc b/chromium/components/ukm/ukm_recorder_impl_unittest.cc
index 15d9f90f31e..187ea182590 100644
--- a/chromium/components/ukm/ukm_recorder_impl_unittest.cc
+++ b/chromium/components/ukm/ukm_recorder_impl_unittest.cc
@@ -6,13 +6,12 @@
#include "base/bind.h"
#include "base/metrics/metrics_hashes.h"
-#include "base/metrics/ukm_source_id.h"
-#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_entry_builder.h"
#include "services/metrics/public/cpp/ukm_source.h"
+#include "services/metrics/public/cpp/ukm_source_id.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/ukm/report.pb.h"
#include "url/gurl.h"
diff --git a/chromium/components/ukm/ukm_reporting_service.cc b/chromium/components/ukm/ukm_reporting_service.cc
index 8beedce934d..3f32214b6db 100644
--- a/chromium/components/ukm/ukm_reporting_service.cc
+++ b/chromium/components/ukm/ukm_reporting_service.cc
@@ -13,9 +13,10 @@
#include "base/metrics/histogram_macros.h"
#include "components/metrics/metrics_service_client.h"
#include "components/prefs/pref_registry_simple.h"
-#include "components/ukm/unsent_log_store_metrics_impl.h"
#include "components/ukm/ukm_pref_names.h"
#include "components/ukm/ukm_service.h"
+#include "components/ukm/unsent_log_store_metrics_impl.h"
+#include "third_party/zlib/google/compression_utils.h"
namespace ukm {
@@ -106,10 +107,40 @@ void UkmReportingService::LogResponseOrErrorCode(int response_code,
response_code >= 0 ? response_code : error_code);
}
-void UkmReportingService::LogSuccess(size_t log_size) {
+void UkmReportingService::LogSuccessLogSize(size_t log_size) {
UMA_HISTOGRAM_COUNTS_10000("UKM.LogSize.OnSuccess", log_size / 1024);
}
+void UkmReportingService::LogSuccessMetadata(const std::string& staged_log) {
+ // Recover the report from the compressed staged log.
+ std::string uncompressed_log_data;
+ bool uncompress_successful =
+ compression::GzipUncompress(staged_log, &uncompressed_log_data);
+ DCHECK(uncompress_successful);
+ Report report;
+ report.ParseFromString(uncompressed_log_data);
+
+ // Log the relative size of the report with relevant UKM data omitted. This
+ // helps us to estimate the bandwidth usage of logs upload that is not
+ // directly attributed to UKM data, for example the system profile info.
+ // Note that serialized logs are further compressed before upload, thus the
+ // percentages here are not the exact percentage of bandwidth they ended up
+ // taking.
+ std::string log_without_ukm_data;
+ report.clear_sources();
+ report.clear_source_counts();
+ report.clear_entries();
+ report.clear_aggregates();
+ report.SerializeToString(&log_without_ukm_data);
+
+ int non_ukm_percentage =
+ log_without_ukm_data.length() * 100 / uncompressed_log_data.length();
+ DCHECK_GE(non_ukm_percentage, 0);
+ DCHECK_LE(non_ukm_percentage, 100);
+ base::UmaHistogramPercentage("UKM.ReportSize.NonUkmPercentage",
+ non_ukm_percentage);
+}
+
void UkmReportingService::LogLargeRejection(size_t log_size) {}
} // namespace ukm
diff --git a/chromium/components/ukm/ukm_reporting_service.h b/chromium/components/ukm/ukm_reporting_service.h
index c011f0fe18e..7abd15670fb 100644
--- a/chromium/components/ukm/ukm_reporting_service.h
+++ b/chromium/components/ukm/ukm_reporting_service.h
@@ -12,8 +12,9 @@
#include <string>
#include "base/macros.h"
-#include "components/metrics/unsent_log_store.h"
#include "components/metrics/reporting_service.h"
+#include "components/metrics/unsent_log_store.h"
+#include "third_party/metrics_proto/ukm/report.pb.h"
class PrefService;
class PrefRegistrySimple;
@@ -56,7 +57,8 @@ class UkmReportingService : public metrics::ReportingService {
void LogResponseOrErrorCode(int response_code,
int error_code,
bool was_https) override;
- void LogSuccess(size_t log_size) override;
+ void LogSuccessLogSize(size_t log_size) override;
+ void LogSuccessMetadata(const std::string& staged_log) override;
void LogLargeRejection(size_t log_size) override;
metrics::UnsentLogStore unsent_log_store_;
diff --git a/chromium/components/ukm/ukm_service.cc b/chromium/components/ukm/ukm_service.cc
index 4750e7893f0..cab3d7c51d5 100644
--- a/chromium/components/ukm/ukm_service.cc
+++ b/chromium/components/ukm/ukm_service.cc
@@ -13,6 +13,7 @@
#include "base/feature_list.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
+#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/rand_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
@@ -153,11 +154,8 @@ void PurgeExtensionDataFromUnsentLogStore(
},
report.entries(), report.mutable_entries());
- std::string reserialized_log_data;
- report.SerializeToString(&reserialized_log_data);
- // This allows catching errors with bad UKM serialization we've seen before
- // that would otherwise only be noticed on the server.
- DCHECK(UkmService::LogCanBeParsed(reserialized_log_data));
+ std::string reserialized_log_data =
+ UkmService::SerializeReportProtoToString(&report);
// Replace the compressed log in the store by its filtered version.
const std::string old_compressed_log_data =
@@ -181,13 +179,23 @@ bool UkmService::LogCanBeParsed(const std::string& serialized_data) {
bool report_parse_successful = report.ParseFromString(serialized_data);
if (!report_parse_successful)
return false;
- // Make sure the reserialzed log from this |report| matches the input
+ // Make sure the reserialized log from this |report| matches the input
// |serialized_data|.
std::string reserialized_from_report;
report.SerializeToString(&reserialized_from_report);
return reserialized_from_report == serialized_data;
}
+std::string UkmService::SerializeReportProtoToString(Report* report) {
+ std::string serialized_full_log;
+ report->SerializeToString(&serialized_full_log);
+
+ // This allows catching errors with bad UKM serialization we've seen before
+ // that would otherwise only be noticed on the server.
+ DCHECK(UkmService::LogCanBeParsed(serialized_full_log));
+ return serialized_full_log;
+}
+
UkmService::UkmService(PrefService* pref_service,
metrics::MetricsServiceClient* client,
std::unique_ptr<metrics::UkmDemographicMetricsProvider>
@@ -354,8 +362,8 @@ void UkmService::RegisterPrefs(PrefRegistrySimple* registry) {
void UkmService::StartInitTask() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DVLOG(1) << "UkmService::StartInitTask";
- metrics_providers_.AsyncInit(base::Bind(&UkmService::FinishedInitTask,
- self_ptr_factory_.GetWeakPtr()));
+ metrics_providers_.AsyncInit(base::BindOnce(&UkmService::FinishedInitTask,
+ self_ptr_factory_.GetWeakPtr()));
}
void UkmService::FinishedInitTask() {
@@ -418,11 +426,8 @@ void UkmService::BuildAndStoreLog() {
AddSyncedUserNoiseBirthYearAndGenderToReport(&report);
- std::string serialized_log;
- report.SerializeToString(&serialized_log);
- // This allows catching errors with bad UKM serialization we've seen before
- // that would otherwise only be noticed on the server.
- DCHECK(LogCanBeParsed(serialized_log));
+ std::string serialized_log =
+ UkmService::SerializeReportProtoToString(&report);
reporting_service_.ukm_log_store()->StoreLog(serialized_log, base::nullopt);
}
diff --git a/chromium/components/ukm/ukm_service.h b/chromium/components/ukm/ukm_service.h
index 37d6ab19591..3355ddf90a5 100644
--- a/chromium/components/ukm/ukm_service.h
+++ b/chromium/components/ukm/ukm_service.h
@@ -114,12 +114,15 @@ class UkmService : public UkmRecorderImpl {
// Enables adding the synced user's noised birth year and gender to the UKM
// report. For more details, see doc of metrics::DemographicMetricsProvider in
- // components/metrics/demographic_metrics_provider.h.
+ // components/metrics/demographics/demographic_metrics_provider.h.
static const base::Feature kReportUserNoisedUserBirthYearAndGender;
- // Makes sure that the serialized ukm report can be parsed.
+ // Makes sure that the serialized UKM report can be parsed.
static bool LogCanBeParsed(const std::string& serialized_data);
+ // Serializes the input UKM report into a string and validates it.
+ static std::string SerializeReportProtoToString(Report* report);
+
private:
friend ::metrics::UkmBrowserTestBase;
friend ::ukm::UkmTestHelper;
@@ -158,7 +161,7 @@ class UkmService : public UkmRecorderImpl {
// Adds the user's birth year and gender to the UKM |report| only if (1) the
// provider is registered and (2) the feature is enabled. For more details,
// see doc of metrics::DemographicMetricsProvider in
- // components/metrics/demographic_metrics_provider.h.
+ // components/metrics/demographics/demographic_metrics_provider.h.
void AddSyncedUserNoiseBirthYearAndGenderToReport(Report* report);
void SetInitializationCompleteCallbackForTesting(base::OnceClosure callback);
diff --git a/chromium/components/ukm/ukm_service_unittest.cc b/chromium/components/ukm/ukm_service_unittest.cc
index 7d90ad8074a..c4e916a68d7 100644
--- a/chromium/components/ukm/ukm_service_unittest.cc
+++ b/chromium/components/ukm/ukm_service_unittest.cc
@@ -38,6 +38,7 @@
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_entry_builder.h"
#include "services/metrics/public/cpp/ukm_source.h"
+#include "services/metrics/public/cpp/ukm_source_id.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/ukm/report.pb.h"
@@ -62,7 +63,7 @@ std::string Entry1And2Whitelist() {
}
SourceId ConvertSourceIdToWhitelistedType(SourceId id, SourceIdType type) {
- return base::UkmSourceId::FromOtherId(id, type).ToInt64();
+ return ukm::SourceIdObj::FromOtherId(id, type).ToInt64();
}
// A small shim exposing UkmRecorder methods to tests.