Index: components/ntp_snippets/ntp_snippets_service.h |
diff --git a/components/ntp_snippets/ntp_snippets_service.h b/components/ntp_snippets/ntp_snippets_service.h |
index 3d659a402807a52405841380ff92c5c60e4a9fae..2c2b9e41d615b56adcfdcea2467b5f898ea3dc35 100644 |
--- a/components/ntp_snippets/ntp_snippets_service.h |
+++ b/components/ntp_snippets/ntp_snippets_service.h |
@@ -7,6 +7,7 @@ |
#include <stddef.h> |
+#include <map> |
#include <memory> |
#include <set> |
#include <string> |
@@ -16,7 +17,6 @@ |
#include "base/gtest_prod_util.h" |
#include "base/macros.h" |
#include "base/scoped_observer.h" |
-#include "base/timer/timer.h" |
#include "components/image_fetcher/image_fetcher_delegate.h" |
#include "components/ntp_snippets/category.h" |
#include "components/ntp_snippets/category_factory.h" |
@@ -104,7 +104,7 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
// calls may trigger DCHECKs. |
bool initialized() const { return ready() || state_ == State::DISABLED; } |
- // Fetches snippets from the server and adds them to the current ones. |
+ // Fetches snippets from the server and replaces old snippets by the new ones. |
// Requests can be marked more important by setting |interactive_request| to |
// true (such request might circumvent the daily quota for requests, etc.) |
// Useful for requests triggered by the user. |
@@ -199,6 +199,11 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
ERROR_OCCURRED |
}; |
+ // Returns the URL of the image of a snippet if it is among the current or |
+ // among the archived snippets in |category|. Returns an empty URL, otherwise. |
+ GURL FindSnippetImageUrl(Category category, |
+ const std::string& snippet_id) const; |
+ |
// image_fetcher::ImageFetcherDelegate implementation. |
void OnImageDataFetched(const std::string& snippet_id, |
const std::string& image_data) override; |
@@ -213,15 +218,23 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
// Callback for the NTPSnippetsFetcher. |
void OnFetchFinished(NTPSnippetsFetcher::OptionalSnippets snippets); |
- // Merges newly available snippets with the previously available list. |
- void MergeSnippets(Category category, NTPSnippet::PtrVector new_snippets); |
+ // Moves all snippets from |to_archive| into the archive of the |category|. |
+ // It also deletes the snippets from the DB and keeps the archive reasonably |
+ // short. |
+ void ArchiveSnippets(Category category, NTPSnippet::PtrVector* to_archive); |
+ |
+ // Replace old snippets in |category| by newly available snippets. |
+ void ReplaceSnippets(Category category, NTPSnippet::PtrVector new_snippets); |
std::set<std::string> GetSnippetHostsFromPrefs() const; |
void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts); |
- // Removes the expired snippets (including dismissed) from the service and the |
- // database, and schedules another pass for the next expiration. |
- void ClearExpiredSnippets(); |
+ // Removes expired dismissed snippets from the service and the database. |
+ void ClearExpiredDismissedSnippets(); |
+ |
+ // Removes images from the DB that do not have any corresponding snippet |
+ // (neither in the current set, nor in the archived set). |
+ void ClearOrphanedImages(); |
// Clears all stored snippets and updates the observer. |
void NukeAllSnippets(); |
@@ -297,11 +310,16 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
// while we still have non-expired snippets in it. |
bool provided_by_server = true; |
- // All current suggestions (i.e. not dismissed ones). |
+ // All currently active suggestions (excl. the dismissed ones). |
NTPSnippet::PtrVector snippets; |
+ // All previous suggestions that we keep around in memory because they can |
+ // be on some open NTP. We do not persist this list so that on a new start |
+ // of Chrome, this is empty. |
+ NTPSnippet::PtrVector archived; |
+ |
// Suggestions that the user dismissed. We keep these around until they |
- // expire so we won't re-add them on the next fetch. |
+ // expire so we won't re-add them to |snippets| on the next fetch. |
NTPSnippet::PtrVector dismissed; |
CategoryContent(); |
@@ -327,9 +345,6 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
// The snippets fetcher. |
std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; |
- // Timer that calls us back when the next snippet expires. |
- base::OneShotTimer expiry_timer_; |
- |
std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
std::unique_ptr<image_fetcher::ImageDecoder> image_decoder_; |