Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: components/ntp_snippets/physical_web_pages/physical_web_page_suggestions_provider.h

Issue 2560783002: [NTP::PhysicalWeb] Implement suggestion dismissal. (Closed)
Patch Set: rebase and bauerb@ nit. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/values.h"
14 #include "components/ntp_snippets/category.h" 14 #include "components/ntp_snippets/category.h"
15 #include "components/ntp_snippets/category_factory.h" 15 #include "components/ntp_snippets/category_factory.h"
16 #include "components/ntp_snippets/category_status.h" 16 #include "components/ntp_snippets/category_status.h"
17 #include "components/ntp_snippets/content_suggestion.h" 17 #include "components/ntp_snippets/content_suggestion.h"
18 #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" 19 #include "components/physical_web/data_source/physical_web_data_source.h"
20 #include "components/physical_web/data_source/physical_web_listener.h" 20 #include "components/physical_web/data_source/physical_web_listener.h"
21 21
22 class PrefRegistrySimple;
23 class PrefService;
24
22 namespace ntp_snippets { 25 namespace ntp_snippets {
23 26
24 // Provides content suggestions from the Physical Web Service. 27 // Provides content suggestions from the Physical Web Service.
25 class PhysicalWebPageSuggestionsProvider 28 class PhysicalWebPageSuggestionsProvider
26 : public ContentSuggestionsProvider, 29 : public ContentSuggestionsProvider,
27 public physical_web::PhysicalWebListener { 30 public physical_web::PhysicalWebListener {
28 public: 31 public:
29 PhysicalWebPageSuggestionsProvider( 32 PhysicalWebPageSuggestionsProvider(
30 ContentSuggestionsProvider::Observer* observer, 33 ContentSuggestionsProvider::Observer* observer,
31 CategoryFactory* category_factory, 34 CategoryFactory* category_factory,
32 physical_web::PhysicalWebDataSource* physical_web_data_source); 35 physical_web::PhysicalWebDataSource* physical_web_data_source,
36 PrefService* pref_service);
33 ~PhysicalWebPageSuggestionsProvider() override; 37 ~PhysicalWebPageSuggestionsProvider() override;
34 38
35 // ContentSuggestionsProvider implementation. 39 // ContentSuggestionsProvider implementation.
36 CategoryStatus GetCategoryStatus(Category category) override; 40 CategoryStatus GetCategoryStatus(Category category) override;
37 CategoryInfo GetCategoryInfo(Category category) override; 41 CategoryInfo GetCategoryInfo(Category category) override;
38 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; 42 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
39 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, 43 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
40 const ImageFetchedCallback& callback) override; 44 const ImageFetchedCallback& callback) override;
41 void Fetch(const Category& category, 45 void Fetch(const Category& category,
42 const std::set<std::string>& known_suggestion_ids, 46 const std::set<std::string>& known_suggestion_ids,
43 const FetchDoneCallback& callback) override; 47 const FetchDoneCallback& callback) override;
44 void ClearHistory( 48 void ClearHistory(
45 base::Time begin, 49 base::Time begin,
46 base::Time end, 50 base::Time end,
47 const base::Callback<bool(const GURL& url)>& filter) override; 51 const base::Callback<bool(const GURL& url)>& filter) override;
48 void ClearCachedSuggestions(Category category) override; 52 void ClearCachedSuggestions(Category category) override;
49 void GetDismissedSuggestionsForDebugging( 53 void GetDismissedSuggestionsForDebugging(
50 Category category, 54 Category category,
51 const DismissedSuggestionsCallback& callback) override; 55 const DismissedSuggestionsCallback& callback) override;
52 void ClearDismissedSuggestionsForDebugging(Category category) override; 56 void ClearDismissedSuggestionsForDebugging(Category category) override;
53 57
58 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
59
54 private: 60 private:
55 friend class PhysicalWebPageSuggestionsProviderTest; 61 friend class PhysicalWebPageSuggestionsProviderTest;
56 62
57 // Updates the |category_status_| and notifies the |observer_|, if necessary. 63 // Updates the |category_status_| and notifies the |observer_|, if necessary.
58 void NotifyStatusChanged(CategoryStatus new_status); 64 void NotifyStatusChanged(CategoryStatus new_status);
59 65
60 // Manually requests all physical web pages and updates the suggestions. 66 // Manually requests all physical web pages and updates the suggestions.
61 void FetchPhysicalWebPages(); 67 void FetchPhysicalWebPages();
62 68
63 // Returns at most |max_count| ContentSuggestions with IDs not in 69 // Returns at most |max_count| ContentSuggestions with IDs not in
64 // |excluded_ids| and sorted by distance (the closest first). The raw pages 70 // |excluded_ids| and sorted by distance (the closest first). Dismissed
65 // are obtained from Physical Web data source. 71 // suggestions are excluded automatically (no need to add them to
72 // |excluded_ids|) and pruned. The raw pages are obtained from Physical Web
73 // data source.
66 std::vector<ContentSuggestion> GetMostRecentPhysicalWebPagesWithFilter( 74 std::vector<ContentSuggestion> GetMostRecentPhysicalWebPagesWithFilter(
67 int max_count, 75 int max_count,
68 const std::set<std::string>& excluded_ids); 76 const std::set<std::string>& excluded_ids);
69 77
70 // Converts an Physical Web page to a ContentSuggestion. 78 // Converts an Physical Web page to a ContentSuggestion.
71 ContentSuggestion ConvertPhysicalWebPage( 79 ContentSuggestion ConvertPhysicalWebPage(
72 const base::DictionaryValue& page) const; 80 const base::DictionaryValue& page) const;
73 81
74 // PhysicalWebListener implementation. 82 // PhysicalWebListener implementation.
75 void OnFound(const std::string& url) override; 83 void OnFound(const std::string& url) override;
76 void OnLost(const std::string& url) override; 84 void OnLost(const std::string& url) override;
77 void OnDistanceChanged(const std::string& url, 85 void OnDistanceChanged(const std::string& url,
78 double distance_estimate) override; 86 double distance_estimate) override;
79 87
88 // Fires the |OnSuggestionInvalidated| event for the suggestion corresponding
89 // to the given |page_id| and deletes it from the dismissed IDs list, if
90 // necessary.
91 void InvalidateSuggestion(const std::string& page_id);
92
93 // Reads dismissed IDs from Prefs.
94 std::set<std::string> ReadDismissedIDsFromPrefs() const;
95
96 // Writes |dismissed_ids| into Prefs.
97 void StoreDismissedIDsToPrefs(const std::set<std::string>& dismissed_ids);
98
80 CategoryStatus category_status_; 99 CategoryStatus category_status_;
81 const Category provided_category_; 100 const Category provided_category_;
82 physical_web::PhysicalWebDataSource* physical_web_data_source_; 101 physical_web::PhysicalWebDataSource* physical_web_data_source_;
102 PrefService* pref_service_;
83 103
84 DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProvider); 104 DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProvider);
85 }; 105 };
86 106
87 } // namespace ntp_snippets 107 } // namespace ntp_snippets
88 108
89 #endif // COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTI ONS_PROVIDER_H_ 109 #endif // COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTI ONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698