| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTIONS
_PROVIDER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTIONS
_PROVIDER_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTIONS
_PROVIDER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTIONS
_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/values.h" |
| 13 #include "components/ntp_snippets/category.h" | 14 #include "components/ntp_snippets/category.h" |
| 14 #include "components/ntp_snippets/category_factory.h" | 15 #include "components/ntp_snippets/category_factory.h" |
| 15 #include "components/ntp_snippets/category_status.h" | 16 #include "components/ntp_snippets/category_status.h" |
| 16 #include "components/ntp_snippets/content_suggestion.h" | 17 #include "components/ntp_snippets/content_suggestion.h" |
| 17 #include "components/ntp_snippets/content_suggestions_provider.h" | 18 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 19 #include "components/physical_web/data_source/physical_web_data_source.h" |
| 20 #include "components/physical_web/data_source/physical_web_listener.h" |
| 18 | 21 |
| 19 namespace ntp_snippets { | 22 namespace ntp_snippets { |
| 20 | 23 |
| 21 // TODO(vitaliii): remove when Physical Web C++ interface is provided. | |
| 22 struct UrlInfo { | |
| 23 UrlInfo(); | |
| 24 UrlInfo(const UrlInfo& other); | |
| 25 ~UrlInfo(); | |
| 26 base::Time scan_time; | |
| 27 GURL site_url; | |
| 28 std::string title; | |
| 29 std::string description; | |
| 30 }; | |
| 31 | |
| 32 // Provides content suggestions from the Physical Web Service. | 24 // Provides content suggestions from the Physical Web Service. |
| 33 class PhysicalWebPageSuggestionsProvider : public ContentSuggestionsProvider { | 25 class PhysicalWebPageSuggestionsProvider : public ContentSuggestionsProvider, |
| 26 public PhysicalWebListener { |
| 34 public: | 27 public: |
| 35 PhysicalWebPageSuggestionsProvider( | 28 PhysicalWebPageSuggestionsProvider( |
| 36 ContentSuggestionsProvider::Observer* observer, | 29 ContentSuggestionsProvider::Observer* observer, |
| 37 CategoryFactory* category_factory); | 30 CategoryFactory* category_factory, |
| 31 PhysicalWebDataSource* physical_web_data_source); |
| 38 ~PhysicalWebPageSuggestionsProvider() override; | 32 ~PhysicalWebPageSuggestionsProvider() override; |
| 39 | 33 |
| 40 void OnDisplayableUrlsChanged(const std::vector<UrlInfo>& urls); | |
| 41 | |
| 42 // ContentSuggestionsProvider implementation. | 34 // ContentSuggestionsProvider implementation. |
| 43 CategoryStatus GetCategoryStatus(Category category) override; | 35 CategoryStatus GetCategoryStatus(Category category) override; |
| 44 CategoryInfo GetCategoryInfo(Category category) override; | 36 CategoryInfo GetCategoryInfo(Category category) override; |
| 45 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; | 37 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; |
| 46 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, | 38 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, |
| 47 const ImageFetchedCallback& callback) override; | 39 const ImageFetchedCallback& callback) override; |
| 48 void Fetch(const Category& category, | 40 void Fetch(const Category& category, |
| 49 const std::set<std::string>& known_suggestion_ids, | 41 const std::set<std::string>& known_suggestion_ids, |
| 50 const FetchDoneCallback& callback) override; | 42 const FetchDoneCallback& callback) override; |
| 51 void ClearHistory( | 43 void ClearHistory( |
| 52 base::Time begin, | 44 base::Time begin, |
| 53 base::Time end, | 45 base::Time end, |
| 54 const base::Callback<bool(const GURL& url)>& filter) override; | 46 const base::Callback<bool(const GURL& url)>& filter) override; |
| 55 void ClearCachedSuggestions(Category category) override; | 47 void ClearCachedSuggestions(Category category) override; |
| 56 void GetDismissedSuggestionsForDebugging( | 48 void GetDismissedSuggestionsForDebugging( |
| 57 Category category, | 49 Category category, |
| 58 const DismissedSuggestionsCallback& callback) override; | 50 const DismissedSuggestionsCallback& callback) override; |
| 59 void ClearDismissedSuggestionsForDebugging(Category category) override; | 51 void ClearDismissedSuggestionsForDebugging(Category category) override; |
| 60 | 52 |
| 61 private: | 53 private: |
| 54 friend class PhysicalWebPageSuggestionsProviderTest; |
| 55 |
| 56 // Updates the |category_status_| and notifies the |observer_|, if necessary. |
| 62 void NotifyStatusChanged(CategoryStatus new_status); | 57 void NotifyStatusChanged(CategoryStatus new_status); |
| 63 | 58 |
| 59 // Manually requests all physical web pages and updates the suggestions. |
| 60 void FetchPhysicalWebPages(); |
| 61 |
| 62 // Converts an Physical Web page to a ContentSuggestion. |
| 63 ContentSuggestion ConvertPhysicalWebPage( |
| 64 const base::DictionaryValue& page) const; |
| 65 |
| 66 // PhysicalWebListener implementation. |
| 67 void OnFound(const std::string& url) override; |
| 68 void OnLost(const std::string& url) override; |
| 69 void OnDistanceChanged(const std::string& url, |
| 70 double distance_estimate) override; |
| 71 |
| 64 CategoryStatus category_status_; | 72 CategoryStatus category_status_; |
| 65 const Category provided_category_; | 73 const Category provided_category_; |
| 74 PhysicalWebDataSource* physical_web_data_source_; |
| 66 | 75 |
| 67 DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProvider); | 76 DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProvider); |
| 68 }; | 77 }; |
| 69 | 78 |
| 70 } // namespace ntp_snippets | 79 } // namespace ntp_snippets |
| 71 | 80 |
| 72 #endif // COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTI
ONS_PROVIDER_H_ | 81 #endif // COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTI
ONS_PROVIDER_H_ |
| OLD | NEW |