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

Unified Diff: components/ukm/ukm_service.cc

Issue 2649303004: UKM: Added support for navigation sources (Closed)
Patch Set: Histogram description Created 3 years, 11 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 cbab848c255c7d29f813b0ebf5ad9d9655b15953..2822b7ba310f06f384bc09c4f5deaac604012dd2 100644
--- a/components/ukm/ukm_service.cc
+++ b/components/ukm/ukm_service.cc
@@ -18,11 +18,13 @@
#include "components/metrics/metrics_log_uploader.h"
#include "components/metrics/metrics_service_client.h"
#include "components/metrics/proto/ukm/report.pb.h"
+#include "components/metrics/proto/ukm/source.pb.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/ukm/metrics_reporting_scheduler.h"
#include "components/ukm/persisted_logs_metrics_impl.h"
#include "components/ukm/ukm_pref_names.h"
+#include "components/ukm/ukm_source.h"
#include "components/variations/variations_associated_data.h"
namespace ukm {
@@ -54,6 +56,10 @@ constexpr int kMinPersistedBytes = 300000;
// limit is exceeded.
constexpr size_t kMaxLogRetransmitSize = 100 * 1024;
+// Maximum number of Sources we'll keep in memory before discarding any
+// new ones being added.
+const size_t kMaxSources = 100;
+
std::string GetServerUrl() {
std::string server_url =
variations::GetVariationParamValueByFeature(kUkmFeature, "ServerUrl");
@@ -147,7 +153,7 @@ void UkmService::Flush() {
void UkmService::Purge() {
DVLOG(1) << "UkmService::Purge";
persisted_logs_.Purge();
- // TODO(oystein): Delete any stored sources.
+ sources_.clear();
}
// static
@@ -187,7 +193,14 @@ void UkmService::BuildAndStoreLog() {
Report report;
report.set_client_id(client_id_);
// TODO(holte): Populate system_profile.
- // TODO(oystein): Populate sources.
+
+ for (const auto& source : sources_) {
+ Source* proto_source = report.add_sources();
+ source->PopulateProto(proto_source);
+ }
+ UMA_HISTOGRAM_COUNTS_1000("UKM.Sources.SerializedCount", sources_.size());
+ sources_.clear();
+
std::string serialized_log;
report.SerializeToString(&serialized_log);
persisted_logs_.StoreLog(serialized_log);
@@ -244,4 +257,13 @@ void UkmService::OnLogUploadComplete(int response_code) {
scheduler_->UploadFinished(server_is_healthy, !persisted_logs_.empty());
}
+void UkmService::RecordSource(std::unique_ptr<UkmSource> source) {
+ if (sources_.size() >= kMaxSources) {
+ UMA_HISTOGRAM_BOOLEAN("UKM.Sources.MaxSourcesHit", true);
+ return;
+ }
+
+ sources_.push_back(std::move(source));
+}
+
} // 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