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

Unified Diff: components/ukm/ukm_service.cc

Issue 2649303004: UKM: Added support for navigation sources (Closed)
Patch Set: Removed redundant test steps 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 823bff5fb368bbe1278aecd598f42adfab331284..7d4c5dd0558f9f8eac0794b1ca1de7af73b0b45c 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;
Alexei Svitkine (slow) 2017/01/25 15:35:04 Nit: Just kMaxSources
oystein (OOO til 10th of July) 2017/01/25 18:38:04 Done.
+
std::string GetServerUrl() {
std::string server_url =
variations::GetVariationParamValueByFeature(kUkmFeature, "ServerUrl");
@@ -150,7 +155,7 @@ void UkmService::Flush() {
void UkmService::Purge() {
DVLOG(1) << "UkmService::Purge";
persisted_logs_.Purge();
- // TODO(oystein): Delete any stored sources.
+ sources_.clear();
}
// static
@@ -190,7 +195,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_) {
Alexei Svitkine (slow) 2017/01/25 15:35:04 Nit: const auto&
oystein (OOO til 10th of July) 2017/01/25 18:38:04 Done.
+ 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);
@@ -247,4 +257,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