OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ | 5 #ifndef COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ |
6 #define COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ | 6 #define COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 } // namespace user_prefs | 33 } // namespace user_prefs |
34 | 34 |
35 namespace suggestions { | 35 namespace suggestions { |
36 | 36 |
37 class BlacklistStore; | 37 class BlacklistStore; |
38 class SuggestionsStore; | 38 class SuggestionsStore; |
39 | 39 |
40 extern const char kSuggestionsURL[]; | 40 extern const char kSuggestionsURL[]; |
41 extern const char kSuggestionsBlacklistURLPrefix[]; | 41 extern const char kSuggestionsBlacklistURLPrefix[]; |
42 extern const char kSuggestionsBlacklistURLParam[]; | 42 extern const char kSuggestionsBlacklistURLParam[]; |
| 43 extern const char kSuggestionsBlacklistClearURL[]; |
43 extern const int64 kDefaultExpiryUsec; | 44 extern const int64 kDefaultExpiryUsec; |
44 | 45 |
45 // An interface to fetch server suggestions asynchronously. | 46 // An interface to fetch server suggestions asynchronously. |
46 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { | 47 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { |
47 public: | 48 public: |
48 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; | 49 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; |
49 | 50 |
50 // Class taking ownership of |suggestions_store|, |thumbnail_manager| and | 51 // Class taking ownership of |suggestions_store|, |thumbnail_manager| and |
51 // |blacklist_store|. | 52 // |blacklist_store|. |
52 SuggestionsService( | 53 SuggestionsService( |
(...skipping 27 matching lines...) Expand all Loading... |
80 void BlacklistURL(const GURL& candidate_url, | 81 void BlacklistURL(const GURL& candidate_url, |
81 const ResponseCallback& callback, | 82 const ResponseCallback& callback, |
82 const base::Closure& fail_callback); | 83 const base::Closure& fail_callback); |
83 | 84 |
84 // Removes a URL from the local blacklist, then invokes |callback|. If the URL | 85 // Removes a URL from the local blacklist, then invokes |callback|. If the URL |
85 // cannot be removed, the |fail_callback| is called. | 86 // cannot be removed, the |fail_callback| is called. |
86 void UndoBlacklistURL(const GURL& url, | 87 void UndoBlacklistURL(const GURL& url, |
87 const ResponseCallback& callback, | 88 const ResponseCallback& callback, |
88 const base::Closure& fail_callback); | 89 const base::Closure& fail_callback); |
89 | 90 |
| 91 // Removes all URLs from the blacklist then invokes |callback|. |
| 92 void ClearBlacklist(const ResponseCallback& callback); |
| 93 |
90 // Determines which URL a blacklist request was for, irrespective of the | 94 // Determines which URL a blacklist request was for, irrespective of the |
91 // request's status. Returns false if |request| is not a blacklist request. | 95 // request's status. Returns false if |request| is not a blacklist request. |
92 static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url); | 96 static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url); |
93 | 97 |
94 // Register SuggestionsService related prefs in the Profile prefs. | 98 // Register SuggestionsService related prefs in the Profile prefs. |
95 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 99 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
96 | 100 |
97 // Sets default timestamp for suggestions which do not have expiry timestamp. | 101 // Sets default timestamp for suggestions which do not have expiry timestamp. |
98 void SetDefaultExpiryTimestamp(SuggestionsProfile* suggestions, | 102 void SetDefaultExpiryTimestamp(SuggestionsProfile* suggestions, |
99 int64 timestamp_usec); | 103 int64 timestamp_usec); |
100 | 104 |
101 // Issue a network request if there isn't already one happening. Visible for | 105 // Issue a network request if there isn't already one happening. Visible for |
102 // testing. | 106 // testing. |
103 void IssueRequestIfNoneOngoing(const GURL& url); | 107 void IssueRequestIfNoneOngoing(const GURL& url); |
104 | 108 |
105 private: | 109 private: |
106 friend class SuggestionsServiceTest; | 110 friend class SuggestionsServiceTest; |
107 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURL); | 111 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURL); |
108 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLRequestFails); | 112 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLRequestFails); |
| 113 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, ClearBlacklist); |
109 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UndoBlacklistURL); | 114 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UndoBlacklistURL); |
110 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UndoBlacklistURLFailsHelper); | 115 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UndoBlacklistURLFailsHelper); |
111 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay); | 116 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay); |
112 | 117 |
113 // Creates a request to the suggestions service, properly setting headers. | 118 // Creates a request to the suggestions service, properly setting headers. |
114 scoped_ptr<net::URLFetcher> CreateSuggestionsRequest(const GURL& url); | 119 scoped_ptr<net::URLFetcher> CreateSuggestionsRequest(const GURL& url); |
115 | 120 |
116 // net::URLFetcherDelegate implementation. | 121 // net::URLFetcherDelegate implementation. |
117 // Called when fetch request completes. Parses the received suggestions data, | 122 // Called when fetch request completes. Parses the received suggestions data, |
118 // and dispatches them to callbacks stored in queue. | 123 // and dispatches them to callbacks stored in queue. |
(...skipping 12 matching lines...) Expand all Loading... |
131 // Schedules a blacklisting request if the local blacklist isn't empty. | 136 // Schedules a blacklisting request if the local blacklist isn't empty. |
132 void ScheduleBlacklistUpload(); | 137 void ScheduleBlacklistUpload(); |
133 | 138 |
134 // If the local blacklist isn't empty, picks a URL from it and issues a | 139 // If the local blacklist isn't empty, picks a URL from it and issues a |
135 // blacklist request for it. | 140 // blacklist request for it. |
136 void UploadOneFromBlacklist(); | 141 void UploadOneFromBlacklist(); |
137 | 142 |
138 // Updates |scheduling_delay_| based on the success of the last request. | 143 // Updates |scheduling_delay_| based on the success of the last request. |
139 void UpdateBlacklistDelay(bool last_request_successful); | 144 void UpdateBlacklistDelay(bool last_request_successful); |
140 | 145 |
| 146 // Adds favicon URLs to suggestions profile. |
| 147 void PopulateFaviconUrls(SuggestionsProfile* suggestions); |
| 148 |
141 // Test seams. | 149 // Test seams. |
142 base::TimeDelta blacklist_delay() const { return scheduling_delay_; } | 150 base::TimeDelta blacklist_delay() const { return scheduling_delay_; } |
143 void set_blacklist_delay(base::TimeDelta delay) { | 151 void set_blacklist_delay(base::TimeDelta delay) { |
144 scheduling_delay_ = delay; } | 152 scheduling_delay_ = delay; } |
145 | 153 |
146 base::ThreadChecker thread_checker_; | 154 base::ThreadChecker thread_checker_; |
147 | 155 |
148 net::URLRequestContextGetter* url_request_context_; | 156 net::URLRequestContextGetter* url_request_context_; |
149 | 157 |
150 // The cache for the suggestions. | 158 // The cache for the suggestions. |
(...skipping 28 matching lines...) Expand all Loading... |
179 | 187 |
180 // For callbacks may be run after destruction. | 188 // For callbacks may be run after destruction. |
181 base::WeakPtrFactory<SuggestionsService> weak_ptr_factory_; | 189 base::WeakPtrFactory<SuggestionsService> weak_ptr_factory_; |
182 | 190 |
183 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); | 191 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); |
184 }; | 192 }; |
185 | 193 |
186 } // namespace suggestions | 194 } // namespace suggestions |
187 | 195 |
188 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ | 196 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ |
OLD | NEW |