Chromium Code Reviews| Index: chrome/browser/search/suggestions/suggestions_service.h |
| diff --git a/chrome/browser/search/suggestions/suggestions_service.h b/chrome/browser/search/suggestions/suggestions_service.h |
| index a23be99635c311d97b7618b670c843d3018a07f7..2f75601b657aceb127b0e35974b40973a2633978 100644 |
| --- a/chrome/browser/search/suggestions/suggestions_service.h |
| +++ b/chrome/browser/search/suggestions/suggestions_service.h |
| @@ -30,12 +30,14 @@ class PrefRegistrySyncable; |
| namespace suggestions { |
| +class BlacklistStore; |
| class SuggestionsStore; |
| extern const char kSuggestionsFieldTrialName[]; |
| extern const char kSuggestionsFieldTrialURLParam[]; |
| -extern const char kSuggestionsFieldTrialSuggestionsSuffixParam[]; |
| -extern const char kSuggestionsFieldTrialBlacklistSuffixParam[]; |
| +extern const char kSuggestionsFieldTrialCommonParamsParam[]; |
| +extern const char kSuggestionsFieldTrialBlacklistPathParam[]; |
| +extern const char kSuggestionsFieldTrialBlacklistUrlParamParam[]; |
| extern const char kSuggestionsFieldTrialStateParam[]; |
| extern const char kSuggestionsFieldTrialStateEnabled[]; |
| @@ -45,7 +47,8 @@ class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { |
| typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; |
| SuggestionsService(Profile* profile, |
| - scoped_ptr<SuggestionsStore> suggestions_store); |
| + scoped_ptr<SuggestionsStore> suggestions_store, |
| + scoped_ptr<BlacklistStore> blacklist_store); |
| virtual ~SuggestionsService(); |
| // Whether this service is enabled. |
| @@ -70,7 +73,12 @@ class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { |
| // Issue a blacklist request. If there is already a blacklist request |
| // in flight, the new blacklist request is ignored. |
| - void BlacklistURL(const GURL& candidate_url, ResponseCallback callback); |
| + void BlacklistURL(const GURL& candidate_url, |
| + const ResponseCallback& callback); |
| + |
| + // Determines which URL a blacklist request was for, irrespective of the |
| + // request's status. Returns false if |request| is not a blacklist request. |
| + static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url); |
| // Register SuggestionsService related prefs in the Profile prefs. |
| static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| @@ -78,6 +86,12 @@ class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { |
| private: |
| FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); |
| + // Issue a request. |
| + void IssueRequest(const GURL& url); |
| + |
| + // Creates a request to the suggestions service, properly setting headers. |
| + net::URLFetcher* CreateSuggestionsRequest(const GURL& url); |
| + |
| // Called to service the requestors if the issued suggestions request has |
| // not completed in a given amount of time. |
| virtual void OnRequestTimeout(); |
| @@ -90,18 +104,34 @@ class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { |
| // KeyedService implementation. |
| virtual void Shutdown() OVERRIDE; |
| - // Determines whether |request| is a blacklisting request. |
| - bool IsBlacklistRequest(net::URLFetcher* request) const; |
| - |
| - // Creates a request to the suggestions service, properly setting headers. |
| - net::URLFetcher* CreateSuggestionsRequest(const GURL& url); |
| - |
| // Load the cached suggestions and service the requestors with them. |
| void ServeFromCache(); |
| + // Apply the local blacklist to |suggestions|, then serve the requestors. |
| + void FilterAndServe(SuggestionsProfile* suggestions); |
| + |
| + // Schedule a blacklisting request if the local blacklist isn't empty. |
| + // |last_request_successful| is used for exponentially backing off when |
| + // requests fail. |
| + void ScheduleBlacklistUpload(bool last_request_successful); |
| + |
| + // If the local blacklist isn't empty, pick a URL from it and issue a |
| + // blacklist request for it. |
| + void UploadOneFromBlacklist(); |
| + |
| + // Updates |blacklist_delay_sec_| based on the success of the last request. |
| + void UpdateBlacklistDelay(bool last_request_successful); |
| + |
| + // Test seams. |
| + int GetBlacklistDelay() const; |
|
Mathieu
2014/06/18 13:56:23
these could be blacklist_delay() and set_blacklist
manzagop (departed)
2014/06/18 18:44:55
Done.
|
| + void SetBlacklistDelay(int delay); |
| + |
| // The cache for the suggestions. |
| scoped_ptr<SuggestionsStore> suggestions_store_; |
| + // The local cache for temporary blacklist, until uploaded to the server. |
| + scoped_ptr<BlacklistStore> blacklist_store_; |
| + |
| // Contains the current suggestions fetch request. Will only have a value |
| // while a request is pending, and will be reset by |OnURLFetchComplete|. |
| scoped_ptr<net::URLFetcher> pending_request_; |
| @@ -128,9 +158,15 @@ class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { |
| Profile* profile_; |
| + // Delay used when scheduling a blacklisting task. |
| + int blacklist_delay_sec_; |
| + |
| // For callbacks may be run after destruction. |
| base::WeakPtrFactory<SuggestionsService> weak_ptr_factory_; |
| + FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay); |
|
Mathieu
2014/06/18 13:56:23
you already have FRIEND_TEST above for another tes
manzagop (departed)
2014/06/18 18:44:55
Moved the one from above to here.
|
| + FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLFails); |
| + |
| DISALLOW_COPY_AND_ASSIGN(SuggestionsService); |
| }; |