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

Unified Diff: chrome/browser/push_messaging/background_budget_service.cc

Issue 1977423002: Added UMA stats to track the budget for any service worker which receives a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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: chrome/browser/push_messaging/background_budget_service.cc
diff --git a/chrome/browser/push_messaging/background_budget_service.cc b/chrome/browser/push_messaging/background_budget_service.cc
index 5963bc288873b2ae56b54911f30177f9bb108c42..dd7ca4750720866bd1bfb013d7e13a07055fcf50 100644
--- a/chrome/browser/push_messaging/background_budget_service.cc
+++ b/chrome/browser/push_messaging/background_budget_service.cc
@@ -8,6 +8,7 @@
#include "base/callback.h"
#include "base/memory/ptr_util.h"
+#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
@@ -24,10 +25,15 @@
namespace {
constexpr char kSeparator = '#';
-// We calculate the ratio of the different components of a budget with respect
+
+// Calculate the ratio of the different components of a budget with respect
// to a maximum time period of 10 days = 864000.0 seconds.
constexpr double kSecondsToAccumulate = 864000.0;
+// Currently this just costs 2.0, but it may expand to include things like
+// whether wifi is available in the mobile case.
+const double kBackgroundProcessingCost = 2.0;
Peter Beverloo 2016/05/17 11:04:34 What's your take on explicitly calling out that th
harkness 2016/05/17 13:08:16 I've split it out now, although it makes the SES r
+
bool GetBudgetDataFromPrefs(Profile* profile,
const GURL& origin,
double* old_budget,
@@ -80,6 +86,14 @@ void SetBudgetDataInPrefs(Profile* profile,
map->SetStringWithoutPathExpansion(origin.spec(), s);
}
+void RecordSESForNoBudgetOrigin(double ses) {
+ UMA_HISTOGRAM_COUNTS("PushMessaging.SESForNoBudgetOrigin", ses);
+}
+
+void RecordSESForLowBudgetOrigin(double ses) {
+ UMA_HISTOGRAM_COUNTS("PushMessaging.SESForLowBudgetOrigin", ses);
Peter Beverloo 2016/05/17 11:04:34 Can we just inline these calls? No need for them t
harkness 2016/05/17 13:08:16 Done.
+}
+
} // namespace
BackgroundBudgetService::BackgroundBudgetService(Profile* profile)
@@ -95,6 +109,11 @@ void BackgroundBudgetService::RegisterProfilePrefs(
registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap);
}
+// static
+double BackgroundBudgetService::GetBackgroundProcessingCost() {
+ return kBackgroundProcessingCost;
+}
+
double BackgroundBudgetService::GetBudget(const GURL& origin) {
DCHECK_EQ(origin, origin.GetOrigin());
@@ -136,6 +155,14 @@ double BackgroundBudgetService::GetBudget(const GURL& origin) {
// component, which gives extra budget to sites that have a high ses score.
double budget = budget_carryover + ses_component;
DCHECK_GE(budget, 0.0);
+
+ // Generate histograms for the GetBudget calls which would return "no budget"
+ // or "low budget" if an API was available to app developers.
+ if (budget < GetBackgroundProcessingCost())
+ RecordSESForNoBudgetOrigin(ses_score);
+ else if (budget < 2.0 * GetBackgroundProcessingCost())
+ RecordSESForLowBudgetOrigin(ses_score);
+
return budget;
}

Powered by Google App Engine
This is Rietveld 408576698