| 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..2b49c178144e132d3b14c6f71431f6baaa6a60f8 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>
|
| @@ -104,7 +105,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 +200,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 empty string, 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,16 +219,19 @@ 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);
|
| + // 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.
|
| + // Removes expired dismissed snippets from the service and the database.
|
| void ClearExpiredSnippets();
|
|
|
| + // 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,9 +306,14 @@ 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 suggestions from the most recent fetch (excl. the dismissed ones).
|
| NTPSnippet::PtrVector snippets;
|
|
|
| + // All previous snippets that we keep around in memory because they can be
|
| + // on some open NTP. We do not store this list to any DB so that on 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.
|
| NTPSnippet::PtrVector dismissed;
|
| @@ -327,9 +341,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_;
|
|
|
|
|