OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_SUGGESTED_ARTICLES_OBSERVER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_SUGGESTED_ARTICLES_OBSERVER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "components/ntp_snippets/content_suggestions_service.h" |
| 13 #include "components/offline_pages/core/prefetch/prefetch_service.h" |
| 14 |
| 15 namespace ntp_snippets { |
| 16 class Category; |
| 17 } |
| 18 |
| 19 namespace offline_pages { |
| 20 |
| 21 // Observes the ContentSuggestionsService, listening for new suggestions in the |
| 22 // ARTICLES category. When those suggestions arrive, it then forwards them to |
| 23 // the Prefetch Service, which does not know about Content Suggestions |
| 24 // specifically. |
| 25 class SuggestedArticlesObserver |
| 26 : public ntp_snippets::ContentSuggestionsService::Observer { |
| 27 public: |
| 28 SuggestedArticlesObserver( |
| 29 // This can be |nullptr| in test. |
| 30 ntp_snippets::ContentSuggestionsService* content_suggestions_service, |
| 31 PrefetchService* prefetch_service); |
| 32 ~SuggestedArticlesObserver() override; |
| 33 |
| 34 // ContentSuggestionsService::Observer overrides. |
| 35 void OnNewSuggestions(ntp_snippets::Category category) override; |
| 36 void OnCategoryStatusChanged( |
| 37 ntp_snippets::Category category, |
| 38 ntp_snippets::CategoryStatus new_status) override; |
| 39 void OnSuggestionInvalidated( |
| 40 const ntp_snippets::ContentSuggestion::ID& suggestion_id) override; |
| 41 void OnFullRefreshRequired() override; |
| 42 void ContentSuggestionsServiceShutdown() override; |
| 43 |
| 44 // Returns a pointer to the list of testing articles. If there is no such |
| 45 // list, allocates one before returning the list. The observer owns the list. |
| 46 std::vector<ntp_snippets::ContentSuggestion>* GetTestingArticles(); |
| 47 |
| 48 private: |
| 49 // Unowned, only used when we are called by observer methods (so the |
| 50 // pointer will be valid). |
| 51 ntp_snippets::ContentSuggestionsService* content_suggestions_service_; |
| 52 |
| 53 // This class is owned by the prefetch service. |
| 54 PrefetchService* prefetch_service_; |
| 55 |
| 56 // Normally null, but can be set in tests to override the default behavior. |
| 57 std::unique_ptr<std::vector<ntp_snippets::ContentSuggestion>> test_articles_; |
| 58 |
| 59 ntp_snippets::CategoryStatus category_status_ = |
| 60 ntp_snippets::CategoryStatus::INITIALIZING; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(SuggestedArticlesObserver); |
| 63 }; |
| 64 |
| 65 } // namespace offline_pages |
| 66 |
| 67 #endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_SUGGESTED_ARTICLES_OBSERVER_H_ |
OLD | NEW |