| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ |
| 6 #define CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ | 6 #define CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 11 #include "base/gtest_prod_util.h" |
| 10 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 11 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 12 | 14 |
| 13 class Profile; | 15 class Profile; |
| 14 | 16 |
| 17 namespace base { |
| 18 class Clock; |
| 19 } |
| 20 |
| 15 namespace user_prefs { | 21 namespace user_prefs { |
| 16 class PrefRegistrySyncable; | 22 class PrefRegistrySyncable; |
| 17 } | 23 } |
| 18 | 24 |
| 19 // A budget service to help Chrome decide how much background work a service | 25 // A budget service to help Chrome decide how much background work a service |
| 20 // worker should be able to do on behalf of the user. The budget currently | 26 // worker should be able to do on behalf of the user. The budget is calculated |
| 21 // implements a grace period of 1 non-visual notification in 10. | 27 // based on the Site Engagment Score and is consumed when a service worker does |
| 28 // background work on behalf of the user. |
| 22 class BackgroundBudgetService : public KeyedService { | 29 class BackgroundBudgetService : public KeyedService { |
| 23 public: | 30 public: |
| 24 explicit BackgroundBudgetService(Profile* profile); | 31 explicit BackgroundBudgetService(Profile* profile); |
| 25 ~BackgroundBudgetService() override {} | 32 ~BackgroundBudgetService() override; |
| 26 | 33 |
| 27 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 34 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 28 | 35 |
| 29 // Get the budget associated with the origin. This currently tracks a string | 36 // Get the budget associated with the origin. This is returned as the double |
| 30 // which holds 0 and 1 for the last 10 push messages and whether they | 37 // budget. Budget will be a value between 0.0 and |
| 31 // triggered a visual notification. | 38 // SiteEngagementScore::kMaxPoints. |
| 32 std::string GetBudget(const GURL& origin); | 39 double GetBudget(const GURL& origin); |
| 33 | 40 |
| 34 // Store the budget associated with the origin. notifications_shown is | 41 // Store the budget associated with the origin. Budget should be a value |
| 35 // expected to be a string encoding whether the last 10 push messages | 42 // between 0.0 and SiteEngagementScore::kMaxPoints. |
| 36 // triggered | 43 void StoreBudget(const GURL& origin, double budget); |
| 37 // a visual notification. | |
| 38 void StoreBudget(const GURL& origin, const std::string& notifications_shown); | |
| 39 | 44 |
| 40 private: | 45 private: |
| 46 friend class BackgroundBudgetServiceTest; |
| 47 |
| 48 // Used to allow tests to fast forward/reverse time. |
| 49 void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| 50 |
| 51 // The clock used to vend times. |
| 52 std::unique_ptr<base::Clock> clock_; |
| 53 |
| 41 Profile* profile_; | 54 Profile* profile_; |
| 42 DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService); | 55 DISALLOW_COPY_AND_ASSIGN(BackgroundBudgetService); |
| 43 }; | 56 }; |
| 44 | 57 |
| 45 #endif // CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ | 58 #endif // CHROME_BROWSER_PUSH_MESSAGING_BACKGROUND_BUDGET_SERVICE_H_ |
| OLD | NEW |