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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_provider.h

Issue 2549163002: RemoteContentSuggestions: Stores the time of the last successful background fetch in a pref (Closed)
Patch Set: Address comments treib Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_REMOTE_SUGGESTIONS_PROVIDER_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_
7 7
8 #include <cstddef> 8 #include <cstddef>
9 #include <deque> 9 #include <deque>
10 #include <map> 10 #include <map>
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 const NTPSnippet::PtrVector& GetSnippetsForTesting(Category category) const { 144 const NTPSnippet::PtrVector& GetSnippetsForTesting(Category category) const {
145 return category_contents_.find(category)->second.snippets; 145 return category_contents_.find(category)->second.snippets;
146 } 146 }
147 147
148 // Dismissed snippets, only for unit tests. 148 // Dismissed snippets, only for unit tests.
149 const NTPSnippet::PtrVector& GetDismissedSnippetsForTesting( 149 const NTPSnippet::PtrVector& GetDismissedSnippetsForTesting(
150 Category category) const { 150 Category category) const {
151 return category_contents_.find(category)->second.dismissed; 151 return category_contents_.find(category)->second.dismissed;
152 } 152 }
153 153
154 // Overrides internal clock for testing purposes.
155 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) {
156 tick_clock_ = std::move(tick_clock);
tschumann 2016/12/08 18:18:51 nit: Couldn't we dependency-inject this into the c
157 }
158
154 private: 159 private:
155 friend class RemoteSuggestionsProviderTest; 160 friend class RemoteSuggestionsProviderTest;
156 161
157 FRIEND_TEST_ALL_PREFIXES(RemoteSuggestionsProviderTest, 162 FRIEND_TEST_ALL_PREFIXES(RemoteSuggestionsProviderTest,
158 DontNotifyIfNotAvailable); 163 DontNotifyIfNotAvailable);
159 FRIEND_TEST_ALL_PREFIXES(RemoteSuggestionsProviderTest, 164 FRIEND_TEST_ALL_PREFIXES(RemoteSuggestionsProviderTest,
160 RemoveExpiredDismissedContent); 165 RemoveExpiredDismissedContent);
161 FRIEND_TEST_ALL_PREFIXES(RemoteSuggestionsProviderTest, 166 FRIEND_TEST_ALL_PREFIXES(RemoteSuggestionsProviderTest,
162 RescheduleOnStateChange); 167 RescheduleOnStateChange);
163 FRIEND_TEST_ALL_PREFIXES(RemoteSuggestionsProviderTest, StatusChanges); 168 FRIEND_TEST_ALL_PREFIXES(RemoteSuggestionsProviderTest, StatusChanges);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 void OnImageDataFetched(const std::string& id_within_category, 259 void OnImageDataFetched(const std::string& id_within_category,
255 const std::string& image_data) override; 260 const std::string& image_data) override;
256 261
257 // Callbacks for the RemoteSuggestionsDatabase. 262 // Callbacks for the RemoteSuggestionsDatabase.
258 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets); 263 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets);
259 void OnDatabaseError(); 264 void OnDatabaseError();
260 265
261 // Callback for fetch-more requests with the NTPSnippetsFetcher. 266 // Callback for fetch-more requests with the NTPSnippetsFetcher.
262 void OnFetchMoreFinished( 267 void OnFetchMoreFinished(
263 const FetchDoneCallback& fetching_callback, 268 const FetchDoneCallback& fetching_callback,
269 NTPSnippetsFetcher::FetchResult fetch_result,
264 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories); 270 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories);
265 271
266 // Callback for regular fetch requests with the NTPSnippetsFetcher. 272 // Callback for regular fetch requests with the NTPSnippetsFetcher.
267 void OnFetchFinished( 273 void OnFetchFinished(
274 bool interactive_request,
275 NTPSnippetsFetcher::FetchResult fetch_status,
268 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories); 276 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories);
269 277
270 // Moves all snippets from |to_archive| into the archive of the |content|. 278 // Moves all snippets from |to_archive| into the archive of the |content|.
271 // Clears |to_archive|. As the archive is a FIFO buffer of limited size, this 279 // Clears |to_archive|. As the archive is a FIFO buffer of limited size, this
272 // function will also delete images from the database in case the associated 280 // function will also delete images from the database in case the associated
273 // snippet gets evicted from the archive. 281 // snippet gets evicted from the archive.
274 void ArchiveSnippets(CategoryContent* content, 282 void ArchiveSnippets(CategoryContent* content,
275 NTPSnippet::PtrVector* to_archive); 283 NTPSnippet::PtrVector* to_archive);
276 284
277 // Sanitizes newly fetched snippets -- e.g. adding missing dates and filtering 285 // Sanitizes newly fetched snippets -- e.g. adding missing dates and filtering
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 bool fetch_when_ready_; 408 bool fetch_when_ready_;
401 409
402 // Set to true if NukeAllSnippets is called while the service isn't ready. 410 // Set to true if NukeAllSnippets is called while the service isn't ready.
403 // The nuke will be executed once the service finishes initialization or 411 // The nuke will be executed once the service finishes initialization or
404 // enters the READY state. 412 // enters the READY state.
405 bool nuke_when_initialized_; 413 bool nuke_when_initialized_;
406 414
407 // Request throttler for limiting requests to thumbnail images. 415 // Request throttler for limiting requests to thumbnail images.
408 RequestThrottler thumbnail_requests_throttler_; 416 RequestThrottler thumbnail_requests_throttler_;
409 417
418 // A clock for getting the time. This allows to inject a tick clock in tests.
419 std::unique_ptr<base::TickClock> tick_clock_;
420
410 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProvider); 421 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProvider);
411 }; 422 };
412 423
413 } // namespace ntp_snippets 424 } // namespace ntp_snippets
414 425
415 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ 426 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698