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

Unified Diff: components/ukm/ukm_service.cc

Issue 2617883004: Initial UKMPageLoadMetricsObserver (Closed)
Patch Set: Class rename 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
Index: components/ukm/ukm_service.cc
diff --git a/components/ukm/ukm_service.cc b/components/ukm/ukm_service.cc
index cbab848c255c7d29f813b0ebf5ad9d9655b15953..aa4d7fffdf118863a008539d5aa01e9b0f481d80 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,9 @@ constexpr int kMinPersistedBytes = 300000;
// limit is exceeded.
constexpr size_t kMaxLogRetransmitSize = 100 * 1024;
+// Maximum number of Sources we'll keep around before dropping new ones.
+const size_t kMaxSourcesLength = 100;
+
std::string GetServerUrl() {
std::string server_url =
variations::GetVariationParamValueByFeature(kUkmFeature, "ServerUrl");
@@ -147,7 +152,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 +192,12 @@ void UkmService::BuildAndStoreLog() {
Report report;
report.set_client_id(client_id_);
// TODO(holte): Populate system_profile.
- // TODO(oystein): Populate sources.
+ for (auto& source : sources_) {
+ Source* proto_source = report.add_sources();
+ source->PopulateProto(proto_source);
+ }
+ sources_.clear();
+
std::string serialized_log;
report.SerializeToString(&serialized_log);
persisted_logs_.StoreLog(serialized_log);
@@ -244,4 +254,11 @@ 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() >= kMaxSourcesLength)
+ return;
+
+ sources_.push_back(std::move(source));
+}
+
} // namespace ukm

Powered by Google App Engine
This is Rietveld 408576698