OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVIDER_
H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVIDER_
H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/callback_forward.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "components/ntp_snippets/content_suggestion.h" |
| 14 #include "components/ntp_snippets/content_suggestions_category.h" |
| 15 #include "components/ntp_snippets/content_suggestions_category_status.h" |
| 16 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 17 #include "components/offline_pages/offline_page_item.h" |
| 18 #include "components/offline_pages/offline_page_model.h" |
| 19 #include "components/offline_pages/offline_page_types.h" |
| 20 |
| 21 namespace gfx { |
| 22 class Image; |
| 23 } |
| 24 |
| 25 namespace ntp_snippets { |
| 26 |
| 27 // Provides content suggestions from the offline pages model. |
| 28 // Currently, those are only the pages that the user last navigated to in an |
| 29 // open tab and offlined bookmarks. |
| 30 class OfflinePageSuggestionsProvider |
| 31 : public KeyedService, |
| 32 public ContentSuggestionsProvider, |
| 33 public offline_pages::OfflinePageModel::Observer { |
| 34 public: |
| 35 using ImageFetchedCallback = |
| 36 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; |
| 37 |
| 38 OfflinePageSuggestionsProvider( |
| 39 offline_pages::OfflinePageModel* offline_page_model); |
| 40 ~OfflinePageSuggestionsProvider() override; |
| 41 |
| 42 // Inherited from KeyedService. |
| 43 void Shutdown() override; |
| 44 |
| 45 private: |
| 46 // ContentSuggestionsProvider implementation |
| 47 void SetObserver(ContentSuggestionsProvider::Observer* observer) override; |
| 48 ContentSuggestionsCategoryStatus GetCategoryStatus( |
| 49 ContentSuggestionsCategory category) override; |
| 50 void DiscardSuggestion(const std::string& suggestion_id) override; |
| 51 void FetchSuggestionImage(const std::string& suggestion_id, |
| 52 const ImageFetchedCallback& callback) override; |
| 53 void ClearCachedSuggestionsForDebugging() override; |
| 54 void ClearDiscardedSuggestionsForDebugging() override; |
| 55 |
| 56 // OfflinePageModel::Observer implementation |
| 57 void OfflinePageModelLoaded(offline_pages::OfflinePageModel* model) override; |
| 58 void OfflinePageModelChanged(offline_pages::OfflinePageModel* model) override; |
| 59 void OfflinePageDeleted(int64_t offline_id, |
| 60 const offline_pages::ClientId& client_id) override; |
| 61 |
| 62 // Queries the OfflinePageModel for offline pages |
| 63 void FetchOfflinePages(); |
| 64 |
| 65 // Callback from the OfflinePageModel |
| 66 void OnOfflinePagesLoaded( |
| 67 const offline_pages::MultipleOfflinePageItemResult& result); |
| 68 |
| 69 ContentSuggestionsCategoryStatus category_status_; |
| 70 |
| 71 ContentSuggestionsProvider::Observer* observer_ = nullptr; |
| 72 |
| 73 offline_pages::OfflinePageModel* offline_page_model_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProvider); |
| 76 }; |
| 77 |
| 78 } // namespace ntp_snippets |
| 79 |
| 80 #endif // COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVID
ER_H_ |
OLD | NEW |