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

Unified Diff: components/metrics/data_use_tracker.cc

Issue 2770853002: Create Ukm ReportingService implementation. (Closed)
Patch Set: Incorporate comments Created 3 years, 9 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
« no previous file with comments | « components/metrics/data_use_tracker.h ('k') | components/metrics/data_use_tracker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/metrics/data_use_tracker.cc
diff --git a/components/metrics/data_use_tracker.cc b/components/metrics/data_use_tracker.cc
index 6081facf5d6c068bdbf782c5fd05d7890e1b263b..cf211cbf28478f089bc72e58a27d492211fd1a7d 100644
--- a/components/metrics/data_use_tracker.cc
+++ b/components/metrics/data_use_tracker.cc
@@ -22,6 +22,34 @@ namespace {
const int kDefaultUMAWeeklyQuotaBytes = 204800;
const double kDefaultUMARatio = 0.05;
+struct CellDataUsePrefs {
+ const MetricsLogUploader::MetricServiceType service_type;
+ const char* service_name;
+ const char* pref_name;
+};
+
+const CellDataUsePrefs data_use_prefs[] = {
+ {MetricsLogUploader::UMA, "UMA", metrics::prefs::kUmaCellDataUse},
+ {MetricsLogUploader::UKM, "UKM", metrics::prefs::kUkmCellDataUse},
+};
+
+const char* GetPrefByServiceName(const std::string& service_name) {
+ for (const auto& pref : data_use_prefs) {
+ if (service_name == pref.service_name)
+ return pref.pref_name;
+ }
+ return nullptr;
+}
+
+const char* GetPrefByServiceType(
+ MetricsLogUploader::MetricServiceType service_type) {
+ for (const auto& pref : data_use_prefs) {
+ if (service_type == pref.service_type)
+ return pref.pref_name;
+ }
+ return nullptr;
+}
+
} // namespace
DataUseTracker::DataUseTracker(PrefService* local_state)
@@ -42,7 +70,9 @@ std::unique_ptr<DataUseTracker> DataUseTracker::Create(
// static
void DataUseTracker::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(metrics::prefs::kUserCellDataUse);
- registry->RegisterDictionaryPref(metrics::prefs::kUmaCellDataUse);
+ for (const auto& pref : data_use_prefs) {
+ registry->RegisterDictionaryPref(pref.pref_name);
+ }
}
void DataUseTracker::UpdateMetricsUsagePrefs(const std::string& service_name,
@@ -54,12 +84,18 @@ void DataUseTracker::UpdateMetricsUsagePrefs(const std::string& service_name,
return;
UpdateUsagePref(prefs::kUserCellDataUse, message_size);
- if (service_name == "UMA")
- UpdateUsagePref(prefs::kUmaCellDataUse, message_size);
+ const char* pref_name = GetPrefByServiceName(service_name);
+ if (pref_name)
+ UpdateUsagePref(pref_name, message_size);
}
-bool DataUseTracker::ShouldUploadLogOnCellular(int log_bytes) {
+bool DataUseTracker::ShouldUploadLogOnCellular(
+ int log_bytes,
+ MetricsLogUploader::MetricServiceType service_type) {
DCHECK(thread_checker_.CalledOnValidThread());
+ const char* pref_name = GetPrefByServiceType(service_type);
+ if (!pref_name)
+ return false;
RemoveExpiredEntries();
@@ -67,7 +103,7 @@ bool DataUseTracker::ShouldUploadLogOnCellular(int log_bytes) {
if (!GetUmaWeeklyQuota(&uma_weekly_quota_bytes))
Alexei Svitkine (slow) 2017/03/24 18:27:21 This function and variable names still say "uma".
return true;
- int uma_total_data_use = ComputeTotalDataUse(prefs::kUmaCellDataUse);
+ int uma_total_data_use = ComputeTotalDataUse(pref_name);
int new_uma_total_data_use = log_bytes + uma_total_data_use;
// If the new log doesn't increase the total UMA traffic to be above the
// allowed quota then the log should be uploaded.
@@ -102,7 +138,9 @@ void DataUseTracker::UpdateUsagePref(const std::string& pref_name,
void DataUseTracker::RemoveExpiredEntries() {
DCHECK(thread_checker_.CalledOnValidThread());
- RemoveExpiredEntriesForPref(prefs::kUmaCellDataUse);
+ for (const auto& pref : data_use_prefs) {
+ RemoveExpiredEntriesForPref(pref.pref_name);
+ }
RemoveExpiredEntriesForPref(prefs::kUserCellDataUse);
}
« no previous file with comments | « components/metrics/data_use_tracker.h ('k') | components/metrics/data_use_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698