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_BOOKMARKS_BOOKMARK_SUGGESTIONS_PROVIDER_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_BOOKMARKS_BOOKMARK_SUGGESTIONS_PROVIDER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 |
| 11 #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "components/ntp_snippets/category.h" |
| 14 #include "components/ntp_snippets/category_status.h" |
| 15 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 16 |
| 17 namespace gfx { |
| 18 class Image; |
| 19 } |
| 20 |
| 21 namespace ntp_snippets { |
| 22 |
| 23 // Provides content suggestions from the bookmarks model. |
| 24 class BookmarkSuggestionsProvider : public ContentSuggestionsProvider, |
| 25 public bookmarks::BookmarkModelObserver { |
| 26 public: |
| 27 BookmarkSuggestionsProvider(ContentSuggestionsProvider::Observer* observer, |
| 28 CategoryFactory* category_factory, |
| 29 bookmarks::BookmarkModel* bookmark_model); |
| 30 ~BookmarkSuggestionsProvider() override; |
| 31 |
| 32 private: |
| 33 // ContentSuggestionsProvider implementation. |
| 34 std::vector<Category> GetProvidedCategories() override; |
| 35 CategoryStatus GetCategoryStatus(Category category) override; |
| 36 void DismissSuggestion(const std::string& suggestion_id) override; |
| 37 void FetchSuggestionImage(const std::string& suggestion_id, |
| 38 const ImageFetchedCallback& callback) override; |
| 39 void ClearCachedSuggestionsForDebugging() override; |
| 40 void ClearDismissedSuggestionsForDebugging() override; |
| 41 |
| 42 // bookmarks::BookmarkModelObserver implementation. |
| 43 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, |
| 44 bool ids_reassigned) override; |
| 45 void OnWillChangeBookmarkMetaInfo( |
| 46 bookmarks::BookmarkModel* model, |
| 47 const bookmarks::BookmarkNode* node) override; |
| 48 void BookmarkMetaInfoChanged(bookmarks::BookmarkModel* model, |
| 49 const bookmarks::BookmarkNode* node) override; |
| 50 |
| 51 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, |
| 52 const bookmarks::BookmarkNode* old_parent, |
| 53 int old_index, |
| 54 const bookmarks::BookmarkNode* new_parent, |
| 55 int new_index) override {} |
| 56 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, |
| 57 const bookmarks::BookmarkNode* parent, |
| 58 int index) override {} |
| 59 void BookmarkNodeRemoved( |
| 60 bookmarks::BookmarkModel* model, |
| 61 const bookmarks::BookmarkNode* parent, |
| 62 int old_index, |
| 63 const bookmarks::BookmarkNode* node, |
| 64 const std::set<GURL>& no_longer_bookmarked) override {} |
| 65 void BookmarkNodeChanged(bookmarks::BookmarkModel* model, |
| 66 const bookmarks::BookmarkNode* node) override {} |
| 67 void BookmarkNodeFaviconChanged( |
| 68 bookmarks::BookmarkModel* model, |
| 69 const bookmarks::BookmarkNode* node) override {} |
| 70 void BookmarkNodeChildrenReordered( |
| 71 bookmarks::BookmarkModel* model, |
| 72 const bookmarks::BookmarkNode* node) override {} |
| 73 void BookmarkAllUserNodesRemoved( |
| 74 bookmarks::BookmarkModel* model, |
| 75 const std::set<GURL>& removed_urls) override {} |
| 76 |
| 77 // The actual method to fetch bookmarks - follows each call to FetchBookmarks |
| 78 // but not sooner than the BookmarkModel gets loaded. |
| 79 void FetchBookmarksInternal(); |
| 80 |
| 81 // Queries the BookmarkModel for recently visited bookmarks and pushes the |
| 82 // results to the ContentSuggestionService. The actual fetching does not |
| 83 // happen before the Bookmark model gets loaded. |
| 84 void FetchBookmarks(); |
| 85 |
| 86 // Updates the |category_status_| and notifies the |observer_|, if necessary. |
| 87 void NotifyStatusChanged(CategoryStatus new_status); |
| 88 |
| 89 CategoryStatus category_status_; |
| 90 const Category provided_category_; |
| 91 bookmarks::BookmarkModel* bookmark_model_; |
| 92 bool fetch_requested_; |
| 93 |
| 94 base::Time node_to_change_last_visit_date_; |
| 95 base::Time end_of_list_last_visit_date_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(BookmarkSuggestionsProvider); |
| 98 }; |
| 99 |
| 100 } // namespace ntp_snippets |
| 101 |
| 102 #endif // COMPONENTS_NTP_SNIPPETS_BOOKMARKS_BOOKMARK_SUGGESTIONS_PROVIDER_H_ |
OLD | NEW |