1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_SUGGESTIONS_PROVIDER_H_ 6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_SUGGESTIONS_PROVIDER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/callback.h" 12 #include "url/gurl.h" 13 14 namespace offline_pages { 15 16 // Data struct for a suggestion of an article to be prefetched. 17 struct PrefetchSuggestion { 18 PrefetchSuggestion(); 19 PrefetchSuggestion(const PrefetchSuggestion&); 20 PrefetchSuggestion(PrefetchSuggestion&&); 21 ~PrefetchSuggestion(); 22 23 // The URL of the suggested article. It acts as a unique key for the 24 // suggestion and may be de-duplicated if the same URL is suggested more than 25 // once. 26 GURL article_url; 27 // The title of the suggested article. 28 std::string article_title; 29 // The publisher name/web site the article is attributed to. 30 std::string article_attribution; 31 // A snippet of the article's contents. 32 std::string article_snippet; 33 // The URL to the thumbnail image representing the suggested article. 34 GURL thumbnail_url; 35 // The URL to the favicon image of the article's hosting web site. 36 GURL favicon_url; 37 }; 38 39 // Interface implemented by the suggestions provider. 40 class SuggestionsProvider { 41 public: 42 using SuggestionCallback = 43 base::OnceCallback<void(std::vector<PrefetchSuggestion>)>; 44 45 // Request the list of current article suggestions, to be returned via the 46 // provided callback (via PostTask) in descending priority order. Freshest 47 // articles are prefetched first based both on the order they are listed and 48 // on the timestamp at which the suggestion was last seen. 49 virtual void GetCurrentArticleSuggestions( 50 SuggestionCallback suggestions_callback) = 0; 51 52 // Notifies that a non-empty list of prefetched articles was presented to the 53 // user. 54 virtual void ReportArticleListViewed() = 0; 55 56 // Notifies that the a specific prefetched article was presented to the user. 57 // This will always provide the original suggested URL, not the potentially 58 // different downloaded one in case redirects take place during archive 59 // generation. 60 virtual void ReportArticleViewed(GURL article_url) = 0; 61 }; 62 63 } // namespace offline_pages 64 65 #endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_SUGGESTIONS_PROVIDER_H_ 66