OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/ukm/ukm_service.h" | 5 #include "components/ukm/ukm_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 std::unique_ptr<metrics::MetricsProvider> provider) { | 222 std::unique_ptr<metrics::MetricsProvider> provider) { |
223 metrics_providers_.push_back(std::move(provider)); | 223 metrics_providers_.push_back(std::move(provider)); |
224 } | 224 } |
225 | 225 |
226 // static | 226 // static |
227 void UkmService::RegisterPrefs(PrefRegistrySimple* registry) { | 227 void UkmService::RegisterPrefs(PrefRegistrySimple* registry) { |
228 registry->RegisterInt64Pref(prefs::kUkmClientId, 0); | 228 registry->RegisterInt64Pref(prefs::kUkmClientId, 0); |
229 registry->RegisterListPref(prefs::kUkmPersistedLogs); | 229 registry->RegisterListPref(prefs::kUkmPersistedLogs); |
230 } | 230 } |
231 | 231 |
| 232 // static |
| 233 int32_t UkmService::NewSourceId() { |
| 234 static int32_t g_source_id_provider = 0; |
| 235 return g_source_id_provider++; |
| 236 } |
| 237 |
232 void UkmService::StartInitTask() { | 238 void UkmService::StartInitTask() { |
233 DCHECK(thread_checker_.CalledOnValidThread()); | 239 DCHECK(thread_checker_.CalledOnValidThread()); |
234 DVLOG(1) << "UkmService::StartInitTask"; | 240 DVLOG(1) << "UkmService::StartInitTask"; |
235 client_id_ = LoadOrGenerateClientId(pref_service_); | 241 client_id_ = LoadOrGenerateClientId(pref_service_); |
236 client_->InitializeSystemProfileMetrics(base::Bind( | 242 client_->InitializeSystemProfileMetrics(base::Bind( |
237 &UkmService::FinishedInitTask, self_ptr_factory_.GetWeakPtr())); | 243 &UkmService::FinishedInitTask, self_ptr_factory_.GetWeakPtr())); |
238 } | 244 } |
239 | 245 |
240 void UkmService::FinishedInitTask() { | 246 void UkmService::FinishedInitTask() { |
241 DCHECK(thread_checker_.CalledOnValidThread()); | 247 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 return; | 386 return; |
381 } | 387 } |
382 | 388 |
383 // Update the pre-existing source if there is any. This happens when the | 389 // Update the pre-existing source if there is any. This happens when the |
384 // initial URL is different from the committed URL for the same source, e.g., | 390 // initial URL is different from the committed URL for the same source, e.g., |
385 // when there is redirection. | 391 // when there is redirection. |
386 for (auto& source : sources_) { | 392 for (auto& source : sources_) { |
387 if (source_id != source->id()) | 393 if (source_id != source->id()) |
388 continue; | 394 continue; |
389 | 395 |
390 source->set_committed_url(url); | 396 source->set_url(url); |
391 return; | 397 return; |
392 } | 398 } |
393 | 399 |
394 if (sources_.size() >= kMaxSources) { | 400 if (sources_.size() >= kMaxSources) { |
395 RecordDroppedSource(DroppedDataReason::MAX_HIT); | 401 RecordDroppedSource(DroppedDataReason::MAX_HIT); |
396 return; | 402 return; |
397 } | 403 } |
398 std::unique_ptr<UkmSource> source = base::MakeUnique<UkmSource>(); | 404 std::unique_ptr<UkmSource> source = base::MakeUnique<UkmSource>(); |
399 source->set_id(source_id); | 405 source->set_id(source_id); |
400 source->set_committed_url(url); | 406 source->set_url(url); |
401 sources_.push_back(std::move(source)); | 407 sources_.push_back(std::move(source)); |
402 } | 408 } |
403 | 409 |
404 void UkmService::AddEntry(std::unique_ptr<UkmEntry> entry) { | 410 void UkmService::AddEntry(std::unique_ptr<UkmEntry> entry) { |
405 DCHECK(thread_checker_.CalledOnValidThread()); | 411 DCHECK(thread_checker_.CalledOnValidThread()); |
406 | 412 |
407 if (!recording_enabled_) { | 413 if (!recording_enabled_) { |
408 RecordDroppedEntry(DroppedDataReason::RECORDING_DISABLED); | 414 RecordDroppedEntry(DroppedDataReason::RECORDING_DISABLED); |
409 return; | 415 return; |
410 } | 416 } |
411 if (entries_.size() >= kMaxEntries) { | 417 if (entries_.size() >= kMaxEntries) { |
412 RecordDroppedEntry(DroppedDataReason::MAX_HIT); | 418 RecordDroppedEntry(DroppedDataReason::MAX_HIT); |
413 return; | 419 return; |
414 } | 420 } |
415 | 421 |
416 entries_.push_back(std::move(entry)); | 422 entries_.push_back(std::move(entry)); |
417 } | 423 } |
418 | 424 |
419 } // namespace ukm | 425 } // namespace ukm |
OLD | NEW |