Chromium Code Reviews| 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..2b489394de7768666f667a49c5d6c1290d076a9c 100644 |
| --- a/chrome/browser/push_messaging/background_budget_service.h |
| +++ b/chrome/browser/push_messaging/background_budget_service.h |
| @@ -7,37 +7,52 @@ |
| #include <string> |
|
Peter Beverloo
2016/05/04 15:41:52
IWYU: #include <memory>
harkness
2016/05/09 15:33:27
Done.
|
| +#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 |
| +// doesn't show a notification when it needed to. |
|
Peter Beverloo
2016/05/04 15:41:52
I've noticed that you're very diligent in keeping
harkness
2016/05/09 15:33:27
I'll generify the comment.
|
| 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: |
| + FRIEND_TEST_ALL_PREFIXES(BackgroundBudgetServiceTest, GetBudgetNoElapsedTime); |
| + FRIEND_TEST_ALL_PREFIXES(BackgroundBudgetServiceTest, GetBudgetElapsedTime); |
| + FRIEND_TEST_ALL_PREFIXES(BackgroundBudgetServiceTest, |
| + GetBudgetConsumedOverTime); |
| + |
| + // Only called directly by tests. |
| + BackgroundBudgetService(Profile* profile, std::unique_ptr<base::Clock> clock); |
|
Peter Beverloo
2016/05/04 15:41:52
You could move some of the complexity from the Bac
harkness
2016/05/09 15:33:27
As discussed in person, I've combined the two cons
|
| + |
| + // The clock used to vend times. |
| + std::unique_ptr<base::Clock> clock_; |
| + |
| Profile* profile_; |
| DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService); |
| }; |