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

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

Issue 1887623002: Replace the 1 in 10 grace period with an accumulating budget based on SES. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Integrated code review comments and refactored service constructors. 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.h
diff --git a/chrome/browser/push_messaging/background_budget_service.h b/chrome/browser/push_messaging/background_budget_service.h
index b8f9b199bdc9c95b2392aac258db6e50451a91d3..255823327a5d36120e82c6624e3957bf80854403 100644
--- a/chrome/browser/push_messaging/background_budget_service.h
+++ b/chrome/browser/push_messaging/background_budget_service.h
@@ -5,39 +5,51 @@
#ifndef CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_
#define CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_
+#include <memory>
#include <string>
+#include "base/gtest_prod_util.h"
#include "components/keyed_service/core/keyed_service.h"
#include "url/gurl.h"
class Profile;
+namespace base {
+class Clock;
+}
+
namespace user_prefs {
class PrefRegistrySyncable;
}
// A budget service to help Chrome decide how much background work a service
-// worker should be able to do on behalf of the user. The budget currently
-// implements a grace period of 1 non-visual notification in 10.
+// worker should be able to do on behalf of the user. The budget is calculated
+// based on the Site Engagment Score and is consumed when a service worker does
+// background work on behalf of the user.
class BackgroundBudgetService : public KeyedService {
public:
explicit BackgroundBudgetService(Profile* profile);
- ~BackgroundBudgetService() override {}
+ ~BackgroundBudgetService() override;
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
- // Get the budget associated with the origin. This currently tracks a string
- // which holds 0 and 1 for the last 10 push messages and whether they
- // triggered a visual notification.
- std::string GetBudget(const GURL& origin);
+ // Get the budget associated with the origin. This is returned as the double
+ // budget. Budget will be a value between 0.0 and
+ // SiteEngagementScore::kMaxPoints.
+ double GetBudget(const GURL& origin);
- // Store the budget associated with the origin. notifications_shown is
- // expected to be a string encoding whether the last 10 push messages
- // triggered
- // a visual notification.
- void StoreBudget(const GURL& origin, const std::string& notifications_shown);
+ // Store the budget associated with the origin. Budget should be a value
+ // between 0.0 and SiteEngagementScore::kMaxPoints.
+ void StoreBudget(const GURL& origin, double budget);
private:
+ // Used to allow tests to control the clock.
+ friend class BackgroundBudgetServiceTest;
+ void setClock(std::unique_ptr<base::Clock> clock);
Peter Beverloo 2016/05/09 17:12:06 nit: Blank line after the friend declaration. Sinc
Peter Beverloo 2016/05/09 17:12:06 nit: (Override|Set)ClockForTesting() to further cl
harkness 2016/05/13 13:58:36 moved/updated.
harkness 2016/05/13 13:58:36 Done.
+
+ // The clock used to vend times.
+ std::unique_ptr<base::Clock> clock_;
+
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService);
};

Powered by Google App Engine
This is Rietveld 408576698