Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 constexpr int kMinPersistedBytes = 300000; | 56 constexpr int kMinPersistedBytes = 300000; |
| 57 | 57 |
| 58 // If an upload fails, and the transmission was over this byte count, then we | 58 // If an upload fails, and the transmission was over this byte count, then we |
| 59 // will discard the log, and not try to retransmit it. We also don't persist | 59 // will discard the log, and not try to retransmit it. We also don't persist |
| 60 // the log to the prefs for transmission during the next chrome session if this | 60 // the log to the prefs for transmission during the next chrome session if this |
| 61 // limit is exceeded. | 61 // limit is exceeded. |
| 62 constexpr size_t kMaxLogRetransmitSize = 100 * 1024; | 62 constexpr size_t kMaxLogRetransmitSize = 100 * 1024; |
| 63 | 63 |
| 64 // Maximum number of Sources we'll keep in memory before discarding any | 64 // Maximum number of Sources we'll keep in memory before discarding any |
| 65 // new ones being added. | 65 // new ones being added. |
| 66 const size_t kMaxSources = 500; | 66 const size_t kDefaultMaxSources = 500; |
| 67 | 67 |
| 68 // Maximum number of Entries we'll keep in memory before discarding any | 68 // Maximum number of Entries we'll keep in memory before discarding any |
| 69 // new ones being added. | 69 // new ones being added. |
| 70 const size_t kMaxEntries = 5000; | 70 const size_t kDefaultMaxEntries = 5000; |
| 71 | 71 |
| 72 std::string GetServerUrl() { | 72 std::string GetServerUrl() { |
| 73 std::string server_url = | 73 std::string server_url = |
| 74 base::GetFieldTrialParamValueByFeature(kUkmFeature, "ServerUrl"); | 74 base::GetFieldTrialParamValueByFeature(kUkmFeature, "ServerUrl"); |
| 75 if (!server_url.empty()) | 75 if (!server_url.empty()) |
| 76 return server_url; | 76 return server_url; |
| 77 return kDefaultServerUrl; | 77 return kDefaultServerUrl; |
| 78 } | 78 } |
| 79 | 79 |
| 80 size_t GetMaxSources() { | |
|
Alexei Svitkine (slow)
2017/03/02 23:13:42
Nit: Can you add comments to these?
| |
| 81 return static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt( | |
| 82 kUkmFeature, "MaxSources", kDefaultMaxSources)); | |
| 83 } | |
| 84 | |
| 85 size_t GetMaxEntries() { | |
| 86 return static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt( | |
| 87 kUkmFeature, "MaxEntries", kDefaultMaxEntries)); | |
| 88 } | |
| 89 | |
| 80 bool ShouldRecordInitialUrl() { | 90 bool ShouldRecordInitialUrl() { |
| 81 return base::GetFieldTrialParamByFeatureAsBool(kUkmFeature, | 91 return base::GetFieldTrialParamByFeatureAsBool(kUkmFeature, |
| 82 "RecordInitialUrl", false); | 92 "RecordInitialUrl", false); |
| 83 } | 93 } |
| 84 | 94 |
| 85 bool ShouldRecordSessionId() { | 95 bool ShouldRecordSessionId() { |
| 86 return base::GetFieldTrialParamByFeatureAsBool(kUkmFeature, "RecordSessionId", | 96 return base::GetFieldTrialParamByFeatureAsBool(kUkmFeature, "RecordSessionId", |
| 87 false); | 97 false); |
| 88 } | 98 } |
| 89 | 99 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 persisted_logs_.has_unsent_logs()); | 421 persisted_logs_.has_unsent_logs()); |
| 412 } | 422 } |
| 413 | 423 |
| 414 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) { | 424 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) { |
| 415 DCHECK(thread_checker_.CalledOnValidThread()); | 425 DCHECK(thread_checker_.CalledOnValidThread()); |
| 416 | 426 |
| 417 if (!recording_enabled_) { | 427 if (!recording_enabled_) { |
| 418 RecordDroppedSource(DroppedDataReason::RECORDING_DISABLED); | 428 RecordDroppedSource(DroppedDataReason::RECORDING_DISABLED); |
| 419 return; | 429 return; |
| 420 } | 430 } |
| 421 if (sources_.size() >= kMaxSources) { | 431 if (sources_.size() >= GetMaxSources()) { |
| 422 RecordDroppedSource(DroppedDataReason::MAX_HIT); | 432 RecordDroppedSource(DroppedDataReason::MAX_HIT); |
| 423 return; | 433 return; |
| 424 } | 434 } |
| 425 | 435 |
| 426 sources_.push_back(std::move(source)); | 436 sources_.push_back(std::move(source)); |
| 427 } | 437 } |
| 428 | 438 |
| 429 // static | 439 // static |
| 430 int32_t UkmService::GetNewSourceID() { | 440 int32_t UkmService::GetNewSourceID() { |
| 431 static int32_t next_source_id = 0; | 441 static int32_t next_source_id = 0; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 452 // initial URL is different from the committed URL for the same source, e.g., | 462 // initial URL is different from the committed URL for the same source, e.g., |
| 453 // when there is redirection. | 463 // when there is redirection. |
| 454 for (auto& source : sources_) { | 464 for (auto& source : sources_) { |
| 455 if (source_id != source->id()) | 465 if (source_id != source->id()) |
| 456 continue; | 466 continue; |
| 457 | 467 |
| 458 source->UpdateUrl(url); | 468 source->UpdateUrl(url); |
| 459 return; | 469 return; |
| 460 } | 470 } |
| 461 | 471 |
| 462 if (sources_.size() >= kMaxSources) { | 472 if (sources_.size() >= GetMaxSources()) { |
| 463 RecordDroppedSource(DroppedDataReason::MAX_HIT); | 473 RecordDroppedSource(DroppedDataReason::MAX_HIT); |
| 464 return; | 474 return; |
| 465 } | 475 } |
| 466 std::unique_ptr<UkmSource> source = base::MakeUnique<UkmSource>(); | 476 std::unique_ptr<UkmSource> source = base::MakeUnique<UkmSource>(); |
| 467 source->set_id(source_id); | 477 source->set_id(source_id); |
| 468 source->set_url(url); | 478 source->set_url(url); |
| 469 sources_.push_back(std::move(source)); | 479 sources_.push_back(std::move(source)); |
| 470 } | 480 } |
| 471 | 481 |
| 472 void UkmService::AddEntry(std::unique_ptr<UkmEntry> entry) { | 482 void UkmService::AddEntry(std::unique_ptr<UkmEntry> entry) { |
| 473 DCHECK(thread_checker_.CalledOnValidThread()); | 483 DCHECK(thread_checker_.CalledOnValidThread()); |
| 474 | 484 |
| 475 if (!recording_enabled_) { | 485 if (!recording_enabled_) { |
| 476 RecordDroppedEntry(DroppedDataReason::RECORDING_DISABLED); | 486 RecordDroppedEntry(DroppedDataReason::RECORDING_DISABLED); |
| 477 return; | 487 return; |
| 478 } | 488 } |
| 479 if (entries_.size() >= kMaxEntries) { | 489 if (entries_.size() >= GetMaxEntries()) { |
| 480 RecordDroppedEntry(DroppedDataReason::MAX_HIT); | 490 RecordDroppedEntry(DroppedDataReason::MAX_HIT); |
| 481 return; | 491 return; |
| 482 } | 492 } |
| 483 | 493 |
| 484 entries_.push_back(std::move(entry)); | 494 entries_.push_back(std::move(entry)); |
| 485 } | 495 } |
| 486 | 496 |
| 487 } // namespace ukm | 497 } // namespace ukm |
| OLD | NEW |