Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: components/suggestions/suggestions_service.h

Issue 766053010: SuggestionsService undo blacklist functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GetTimeUntilReadyForUpload should not return negative values Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // exists, to fill the cache for next time. 74 // exists, to fill the cache for next time.
75 void FetchSuggestionsData(SyncState sync_state, 75 void FetchSuggestionsData(SyncState sync_state,
76 ResponseCallback callback); 76 ResponseCallback callback);
77 77
78 // Retrieves stored thumbnail for website |url| asynchronously. Calls 78 // Retrieves stored thumbnail for website |url| asynchronously. Calls
79 // |callback| with Bitmap pointer if found, and NULL otherwise. 79 // |callback| with Bitmap pointer if found, and NULL otherwise.
80 void GetPageThumbnail( 80 void GetPageThumbnail(
81 const GURL& url, 81 const GURL& url,
82 base::Callback<void(const GURL&, const SkBitmap*)> callback); 82 base::Callback<void(const GURL&, const SkBitmap*)> callback);
83 83
84 // Issue a blacklist request. If there is already a blacklist or suggestions 84 // Adds a URL to the blacklist cache, invoking |callback| on success or
85 // request in flight, the new blacklist request is ignored. 85 // |fail_callback| otherwise. The URL will eventually be uploaded to the
86 // server.
86 void BlacklistURL(const GURL& candidate_url, 87 void BlacklistURL(const GURL& candidate_url,
87 const ResponseCallback& callback); 88 const ResponseCallback& callback,
89 const base::Closure& fail_callback);
90
91 // Removes a URL from the local blacklist, then invokes |callback|. If the URL
92 // cannot be removed, the |fail_callback| is called.
93 void UndoBlacklistURL(const GURL& url,
94 const ResponseCallback& callback,
95 const base::Closure& fail_callback);
88 96
89 // Determines which URL a blacklist request was for, irrespective of the 97 // Determines which URL a blacklist request was for, irrespective of the
90 // request's status. Returns false if |request| is not a blacklist request. 98 // request's status. Returns false if |request| is not a blacklist request.
91 static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url); 99 static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url);
92 100
93 // Register SuggestionsService related prefs in the Profile prefs. 101 // Register SuggestionsService related prefs in the Profile prefs.
94 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 102 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
95 103
96 // Sets default timestamp for suggestions which do not have expiry timestamp. 104 // Sets default timestamp for suggestions which do not have expiry timestamp.
97 void SetDefaultExpiryTimestamp(SuggestionsProfile* suggestions, 105 void SetDefaultExpiryTimestamp(SuggestionsProfile* suggestions,
98 int64 timestamp_usec); 106 int64 timestamp_usec);
99 107
100 // Issue a network request if there isn't already one happening. Visible for 108 // Issue a network request if there isn't already one happening. Visible for
101 // testing. 109 // testing.
102 void IssueRequestIfNoneOngoing(const GURL& url); 110 void IssueRequestIfNoneOngoing(const GURL& url);
103 111
104 private: 112 private:
105 friend class SuggestionsServiceTest; 113 friend class SuggestionsServiceTest;
106 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLFails); 114 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURL);
115 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLRequestFails);
116 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UndoBlacklistURL);
117 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UndoBlacklistURLFailsHelper);
107 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay); 118 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay);
108 119
109 // Creates a request to the suggestions service, properly setting headers. 120 // Creates a request to the suggestions service, properly setting headers.
110 net::URLFetcher* CreateSuggestionsRequest(const GURL& url); 121 net::URLFetcher* CreateSuggestionsRequest(const GURL& url);
111 122
112 // net::URLFetcherDelegate implementation. 123 // net::URLFetcherDelegate implementation.
113 // Called when fetch request completes. Parses the received suggestions data, 124 // Called when fetch request completes. Parses the received suggestions data,
114 // and dispatches them to callbacks stored in queue. 125 // and dispatches them to callbacks stored in queue.
115 void OnURLFetchComplete(const net::URLFetcher* source) override; 126 void OnURLFetchComplete(const net::URLFetcher* source) override;
116 127
117 // KeyedService implementation. 128 // KeyedService implementation.
118 void Shutdown() override; 129 void Shutdown() override;
119 130
120 // Loads the cached suggestions (or empty suggestions if no cache) and serves 131 // Loads the cached suggestions (or empty suggestions if no cache) and serves
121 // the requestors with them. 132 // the requestors with them.
122 void ServeFromCache(); 133 void ServeFromCache();
123 134
124 // Applies the local blacklist to |suggestions|, then serves the requestors. 135 // Applies the local blacklist to |suggestions|, then serves the requestors.
125 void FilterAndServe(SuggestionsProfile* suggestions); 136 void FilterAndServe(SuggestionsProfile* suggestions);
126 137
127 // Schedules a blacklisting request if the local blacklist isn't empty. 138 // Schedules a blacklisting request if the local blacklist isn't empty.
128 // |last_request_successful| is used for exponentially backing off when 139 void ScheduleBlacklistUpload();
129 // requests fail.
130 void ScheduleBlacklistUpload(bool last_request_successful);
131 140
132 // If the local blacklist isn't empty, picks a URL from it and issues a 141 // If the local blacklist isn't empty, picks a URL from it and issues a
133 // blacklist request for it. 142 // blacklist request for it.
134 void UploadOneFromBlacklist(); 143 void UploadOneFromBlacklist();
135 144
136 // Updates |blacklist_delay_sec_| based on the success of the last request. 145 // Updates |scheduling_delay_| based on the success of the last request.
137 void UpdateBlacklistDelay(bool last_request_successful); 146 void UpdateBlacklistDelay(bool last_request_successful);
138 147
139 // Test seams. 148 // Test seams.
140 int blacklist_delay() const { return blacklist_delay_sec_; } 149 base::TimeDelta blacklist_delay() const { return scheduling_delay_; }
141 void set_blacklist_delay(int delay) { blacklist_delay_sec_ = delay; } 150 void set_blacklist_delay(base::TimeDelta delay) {
151 scheduling_delay_ = delay; }
142 152
143 base::ThreadChecker thread_checker_; 153 base::ThreadChecker thread_checker_;
144 154
145 net::URLRequestContextGetter* url_request_context_; 155 net::URLRequestContextGetter* url_request_context_;
146 156
147 // The cache for the suggestions. 157 // The cache for the suggestions.
148 scoped_ptr<SuggestionsStore> suggestions_store_; 158 scoped_ptr<SuggestionsStore> suggestions_store_;
149 159
150 // Used to obtain server thumbnails, if available. 160 // Used to obtain server thumbnails, if available.
151 scoped_ptr<ImageManager> thumbnail_manager_; 161 scoped_ptr<ImageManager> thumbnail_manager_;
152 162
153 // The local cache for temporary blacklist, until uploaded to the server. 163 // The local cache for temporary blacklist, until uploaded to the server.
154 scoped_ptr<BlacklistStore> blacklist_store_; 164 scoped_ptr<BlacklistStore> blacklist_store_;
155 165
156 // Delay used when scheduling a blacklisting task. 166 // Delay used when scheduling a blacklisting task.
157 int blacklist_delay_sec_; 167 base::TimeDelta scheduling_delay_;
158 168
159 // Contains the current suggestions fetch request. Will only have a value 169 // Contains the current suggestions fetch request. Will only have a value
160 // while a request is pending, and will be reset by |OnURLFetchComplete| or 170 // while a request is pending, and will be reset by |OnURLFetchComplete| or
161 // if cancelled. 171 // if cancelled.
162 scoped_ptr<net::URLFetcher> pending_request_; 172 scoped_ptr<net::URLFetcher> pending_request_;
163 173
164 // The start time of the previous suggestions request. This is used to measure 174 // The start time of the previous suggestions request. This is used to measure
165 // the latency of requests. Initially zero. 175 // the latency of requests. Initially zero.
166 base::TimeTicks last_request_started_time_; 176 base::TimeTicks last_request_started_time_;
167 177
168 // The URL to fetch suggestions data from. 178 // The URL to fetch suggestions data from.
169 GURL suggestions_url_; 179 GURL suggestions_url_;
170 180
171 // Prefix for building the blacklisting URL. 181 // Prefix for building the blacklisting URL.
172 std::string blacklist_url_prefix_; 182 std::string blacklist_url_prefix_;
173 183
174 // Queue of callbacks. These are flushed when fetch request completes. 184 // Queue of callbacks. These are flushed when fetch request completes.
175 std::vector<ResponseCallback> waiting_requestors_; 185 std::vector<ResponseCallback> waiting_requestors_;
176 186
177 // For callbacks may be run after destruction. 187 // For callbacks may be run after destruction.
178 base::WeakPtrFactory<SuggestionsService> weak_ptr_factory_; 188 base::WeakPtrFactory<SuggestionsService> weak_ptr_factory_;
179 189
180 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); 190 DISALLOW_COPY_AND_ASSIGN(SuggestionsService);
181 }; 191 };
182 192
183 } // namespace suggestions 193 } // namespace suggestions
184 194
185 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ 195 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698