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

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

Issue 2517113005: [NTP::PhysicalWeb] Wire Physical Web provider to the data source. (Closed)
Patch Set: rebase. 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 "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
26 : public ContentSuggestionsProvider,
27 public physical_web::PhysicalWebListener {
34 public: 28 public:
35 PhysicalWebPageSuggestionsProvider( 29 PhysicalWebPageSuggestionsProvider(
36 ContentSuggestionsProvider::Observer* observer, 30 ContentSuggestionsProvider::Observer* observer,
37 CategoryFactory* category_factory); 31 CategoryFactory* category_factory,
32 physical_web::PhysicalWebDataSource* physical_web_data_source);
38 ~PhysicalWebPageSuggestionsProvider() override; 33 ~PhysicalWebPageSuggestionsProvider() override;
39 34
40 void OnDisplayableUrlsChanged(const std::vector<UrlInfo>& urls);
41
42 // ContentSuggestionsProvider implementation. 35 // ContentSuggestionsProvider implementation.
43 CategoryStatus GetCategoryStatus(Category category) override; 36 CategoryStatus GetCategoryStatus(Category category) override;
44 CategoryInfo GetCategoryInfo(Category category) override; 37 CategoryInfo GetCategoryInfo(Category category) override;
45 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; 38 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
46 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, 39 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
47 const ImageFetchedCallback& callback) override; 40 const ImageFetchedCallback& callback) override;
48 void Fetch(const Category& category, 41 void Fetch(const Category& category,
49 const std::set<std::string>& known_suggestion_ids, 42 const std::set<std::string>& known_suggestion_ids,
50 const FetchDoneCallback& callback) override; 43 const FetchDoneCallback& callback) override;
51 void ClearHistory( 44 void ClearHistory(
52 base::Time begin, 45 base::Time begin,
53 base::Time end, 46 base::Time end,
54 const base::Callback<bool(const GURL& url)>& filter) override; 47 const base::Callback<bool(const GURL& url)>& filter) override;
55 void ClearCachedSuggestions(Category category) override; 48 void ClearCachedSuggestions(Category category) override;
56 void GetDismissedSuggestionsForDebugging( 49 void GetDismissedSuggestionsForDebugging(
57 Category category, 50 Category category,
58 const DismissedSuggestionsCallback& callback) override; 51 const DismissedSuggestionsCallback& callback) override;
59 void ClearDismissedSuggestionsForDebugging(Category category) override; 52 void ClearDismissedSuggestionsForDebugging(Category category) override;
60 53
61 private: 54 private:
55 friend class PhysicalWebPageSuggestionsProviderTest;
56
57 // Updates the |category_status_| and notifies the |observer_|, if necessary.
62 void NotifyStatusChanged(CategoryStatus new_status); 58 void NotifyStatusChanged(CategoryStatus new_status);
63 59
60 // Manually requests all physical web pages and updates the suggestions.
61 void FetchPhysicalWebPages();
62
63 // Converts an Physical Web page to a ContentSuggestion.
64 ContentSuggestion ConvertPhysicalWebPage(
65 const base::DictionaryValue& page) const;
66
67 // PhysicalWebListener implementation.
68 void OnFound(const std::string& url) override;
69 void OnLost(const std::string& url) override;
70 void OnDistanceChanged(const std::string& url,
71 double distance_estimate) override;
72
64 CategoryStatus category_status_; 73 CategoryStatus category_status_;
65 const Category provided_category_; 74 const Category provided_category_;
75 physical_web::PhysicalWebDataSource* physical_web_data_source_;
66 76
67 DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProvider); 77 DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProvider);
68 }; 78 };
69 79
70 } // namespace ntp_snippets 80 } // namespace ntp_snippets
71 81
72 #endif // COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTI ONS_PROVIDER_H_ 82 #endif // COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTI ONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698