Chromium Code Reviews| Index: components/ukm/ukm_service.cc |
| diff --git a/components/ukm/ukm_service.cc b/components/ukm/ukm_service.cc |
| index 285dedfa4bda02189f48e76e7c2690c575d5a099..337a80aaec1a94426db7bdfb0f788ed959b17e8d 100644 |
| --- a/components/ukm/ukm_service.cc |
| +++ b/components/ukm/ukm_service.cc |
| @@ -15,11 +15,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 { |
| @@ -59,6 +61,9 @@ const int kMinPersistedBytes = 300000; |
| // limit is exceeded. |
| const 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::GetVariationParamValue( |
| kUkmRolloutFieldTrialName, kUkmRolloutServerUrlParam); |
| @@ -175,7 +180,12 @@ void UkmService::BuildAndStoreLog() { |
| Report report; |
| report.set_client_id(client_id_); |
| // TODO(holte): Populate system_profile. |
| - // TODO(zhenw): Populate sources. |
| + |
| + for (auto& source : sources_) { |
|
Steven Holte
2017/01/09 18:23:39
It seems like we probably want to drop Sources we'
oystein (OOO til 10th of July)
2017/01/24 19:21:41
Done.
|
| + Source* proto_source = report.add_sources(); |
| + source->PopulateProto(proto_source); |
| + } |
| + |
| std::string serialized_log; |
| report.SerializeToString(&serialized_log); |
| persisted_logs_.StoreLog(serialized_log); |
| @@ -232,4 +242,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 |