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 COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_THROTTLER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_THROTTLER_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_THROTTLER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_THROTTLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 // Implementation notes: When extending this class for a new RequestType, please | 33 // Implementation notes: When extending this class for a new RequestType, please |
34 // 1) define in request_counter.cc in kRequestTypeInfo | 34 // 1) define in request_counter.cc in kRequestTypeInfo |
35 // a) the string value for your |type| and | 35 // a) the string value for your |type| and |
36 // b) constants for day/count prefs; | 36 // b) constants for day/count prefs; |
37 // 2) define a new RequestThrottlerTypes histogram suffix in histogram.xml | 37 // 2) define a new RequestThrottlerTypes histogram suffix in histogram.xml |
38 // (with the same string value as in 1a)). | 38 // (with the same string value as in 1a)). |
39 class RequestThrottler { | 39 class RequestThrottler { |
40 public: | 40 public: |
41 // Enumeration listing all current applications of the request counter. | 41 // Enumeration listing all current applications of the request counter. |
42 enum class RequestType { | 42 enum class RequestType { |
43 CONTENT_SUGGESTION_FETCHER, | 43 CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER, |
44 CONTENT_SUGGESTION_FETCHER_ACTIVE_NTP_USER, | |
45 CONTENT_SUGGESTION_FETCHER_ACTIVE_SUGGESTIONS_CONSUMER, | |
44 CONTENT_SUGGESTION_THUMBNAIL, | 46 CONTENT_SUGGESTION_THUMBNAIL, |
45 }; | 47 }; |
46 | 48 |
47 RequestThrottler(PrefService* pref_service, RequestType type); | 49 RequestThrottler(PrefService* pref_service, RequestType type); |
48 | 50 |
51 void ChangeRequestType(RequestType new_type); | |
Marc Treib
2016/10/06 13:41:55
Hm, I find this rather weird. Could we instead jus
jkrcal
2016/10/06 14:45:58
Okay (I would still like them to share the same pr
Marc Treib
2016/10/06 14:54:37
Yup, sharing prefs makes sense.
| |
52 | |
49 // Registers profile prefs for all RequestTypes. Called from browser_prefs.cc. | 53 // Registers profile prefs for all RequestTypes. Called from browser_prefs.cc. |
50 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 54 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
51 | 55 |
52 // Returns whether quota is available for another request and reports this | 56 // Returns whether quota is available for another request and reports this |
53 // information to UMA. Interactive requests should be always granted (upon | 57 // information to UMA. Interactive requests should be always granted (upon |
54 // standard conditions) and should be only used for requests initiated by the | 58 // standard conditions) and should be only used for requests initiated by the |
55 // user (if it is safe to assume that all users cannot generate an amount of | 59 // user (if it is safe to assume that all users cannot generate an amount of |
56 // requests we cannot handle). | 60 // requests we cannot handle). |
57 bool DemandQuotaForRequest(bool interactive_request); | 61 bool DemandQuotaForRequest(bool interactive_request); |
58 | 62 |
(...skipping 11 matching lines...) Expand all Loading... | |
70 const char* GetRequestTypeName() const; | 74 const char* GetRequestTypeName() const; |
71 | 75 |
72 int GetQuota(bool interactive_request) const; | 76 int GetQuota(bool interactive_request) const; |
73 int GetCount(bool interactive_request) const; | 77 int GetCount(bool interactive_request) const; |
74 void SetCount(bool interactive_request, int count); | 78 void SetCount(bool interactive_request, int count); |
75 int GetDay() const; | 79 int GetDay() const; |
76 void SetDay(int day); | 80 void SetDay(int day); |
77 bool HasDay() const; | 81 bool HasDay() const; |
78 | 82 |
79 PrefService* pref_service_; | 83 PrefService* pref_service_; |
80 const RequestTypeInfo& type_info_; | 84 const RequestTypeInfo* type_info_; |
81 | 85 |
82 // The quotas are hardcoded, but can be overridden by variation params. | 86 // The quotas are hardcoded, but can be overridden by variation params. |
83 int quota_; | 87 int quota_; |
84 int interactive_quota_; | 88 int interactive_quota_; |
85 | 89 |
86 // The histograms for reporting the requests of the given |type_|. | 90 // The histograms for reporting the requests of the given |type_|. |
87 base::HistogramBase* histogram_request_status_; | 91 base::HistogramBase* histogram_request_status_; |
88 base::HistogramBase* histogram_per_day_background_; | 92 base::HistogramBase* histogram_per_day_background_; |
89 base::HistogramBase* histogram_per_day_interactive_; | 93 base::HistogramBase* histogram_per_day_interactive_; |
90 | 94 |
91 DISALLOW_COPY_AND_ASSIGN(RequestThrottler); | 95 DISALLOW_COPY_AND_ASSIGN(RequestThrottler); |
92 }; | 96 }; |
93 | 97 |
94 } // namespace ntp_snippets | 98 } // namespace ntp_snippets |
95 | 99 |
96 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_THROTTLER_H_ | 100 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_THROTTLER_H_ |
OLD | NEW |