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

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: proper deps. 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 gfx { 22 namespace gfx {
20 class Image; 23 class Image;
21 } // namespace gfx 24 } // namespace gfx
22 25
23 namespace ntp_snippets { 26 namespace ntp_snippets {
24 27
25 // TODO(vitaliii): remove when Physical Web C++ interface is provided.
26 struct UrlInfo {
27 UrlInfo();
28 UrlInfo(const UrlInfo& other);
29 ~UrlInfo();
30 base::Time scan_time;
31 GURL site_url;
32 std::string title;
33 std::string description;
34 };
35
36 // Provides content suggestions from the Physical Web Service. 28 // Provides content suggestions from the Physical Web Service.
37 class PhysicalWebPageSuggestionsProvider : public ContentSuggestionsProvider { 29 class PhysicalWebPageSuggestionsProvider : public ContentSuggestionsProvider,
30 public PhysicalWebListener {
38 public: 31 public:
39 PhysicalWebPageSuggestionsProvider( 32 PhysicalWebPageSuggestionsProvider(
40 ContentSuggestionsProvider::Observer* observer, 33 ContentSuggestionsProvider::Observer* observer,
41 CategoryFactory* category_factory); 34 CategoryFactory* category_factory,
35 PhysicalWebDataSource* physical_web_data_source);
42 ~PhysicalWebPageSuggestionsProvider() override; 36 ~PhysicalWebPageSuggestionsProvider() override;
43 37
44 void OnDisplayableUrlsChanged(const std::vector<UrlInfo>& urls);
45
46 // ContentSuggestionsProvider implementation. 38 // ContentSuggestionsProvider implementation.
47 CategoryStatus GetCategoryStatus(Category category) override; 39 CategoryStatus GetCategoryStatus(Category category) override;
48 CategoryInfo GetCategoryInfo(Category category) override; 40 CategoryInfo GetCategoryInfo(Category category) override;
49 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; 41 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
50 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, 42 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
51 const ImageFetchedCallback& callback) override; 43 const ImageFetchedCallback& callback) override;
52 void Fetch(const Category& category, 44 void Fetch(const Category& category,
53 const std::set<std::string>& known_suggestion_ids, 45 const std::set<std::string>& known_suggestion_ids,
54 const FetchDoneCallback& callback) override; 46 const FetchDoneCallback& callback) override;
55 void ClearHistory( 47 void ClearHistory(
56 base::Time begin, 48 base::Time begin,
57 base::Time end, 49 base::Time end,
58 const base::Callback<bool(const GURL& url)>& filter) override; 50 const base::Callback<bool(const GURL& url)>& filter) override;
59 void ClearCachedSuggestions(Category category) override; 51 void ClearCachedSuggestions(Category category) override;
60 void GetDismissedSuggestionsForDebugging( 52 void GetDismissedSuggestionsForDebugging(
61 Category category, 53 Category category,
62 const DismissedSuggestionsCallback& callback) override; 54 const DismissedSuggestionsCallback& callback) override;
63 void ClearDismissedSuggestionsForDebugging(Category category) override; 55 void ClearDismissedSuggestionsForDebugging(Category category) override;
64 56
65 private: 57 private:
58 friend class PhysicalWebPageSuggestionsProviderTest;
59
60 // Updates the |category_status_| and notifies the |observer_|, if necessary.
66 void NotifyStatusChanged(CategoryStatus new_status); 61 void NotifyStatusChanged(CategoryStatus new_status);
67 62
63 // Manually requests all physical web pages and updates the suggestions.
64 void FetchPhysicalWebPages();
65
66 // Converts an Physical Web page to a ContentSuggestion for the
67 // |provided_category_|.
Marc Treib 2016/11/23 09:47:52 nit: I wouldn't mention provided_category_; it's n
vitaliii 2016/11/23 14:16:53 Done.
68 ContentSuggestion ConvertPhysicalWebPage(
69 const base::DictionaryValue* out_value) const;
Marc Treib 2016/11/23 09:47:52 out_value isn't a good name; this is an input. Als
vitaliii 2016/11/23 14:16:53 Done.
70
71 // PhysicalWebListener implementation.
72 void OnFound(const std::string& url) override;
73 void OnLost(const std::string& url) override;
74 void OnDistanceChanged(const std::string& url,
75 double distance_estimate) override;
76
68 CategoryStatus category_status_; 77 CategoryStatus category_status_;
69 const Category provided_category_; 78 const Category provided_category_;
79 PhysicalWebDataSource* physical_web_data_source_;
70 80
71 DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProvider); 81 DISALLOW_COPY_AND_ASSIGN(PhysicalWebPageSuggestionsProvider);
72 }; 82 };
73 83
74 } // namespace ntp_snippets 84 } // namespace ntp_snippets
75 85
76 #endif // COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTI ONS_PROVIDER_H_ 86 #endif // COMPONENTS_NTP_SNIPPETS_PHYSICAL_WEB_PAGES_PHYSICAL_WEB_PAGE_SUGGESTI ONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698