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

Side by Side Diff: components/ntp_snippets/content_suggestions_provider.h

Issue 2194203002: Make ContentSuggestionsService recognize new/removed categories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@renaming
Patch Set: Rename EnsureCategoryRegistered to RegisterCategoryIfRequired Created 4 years, 4 months 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_CONTENT_SUGGESTIONS_PROVIDER_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 21 matching lines...) Expand all
32 32
33 // The observer of a provider is notified when new data is available. 33 // The observer of a provider is notified when new data is available.
34 class Observer { 34 class Observer {
35 public: 35 public:
36 // Called when the available content changed. 36 // Called when the available content changed.
37 // If a provider provides suggestions for multiple categories, this callback 37 // If a provider provides suggestions for multiple categories, this callback
38 // is called once per category. The |suggestions| parameter always contains 38 // is called once per category. The |suggestions| parameter always contains
39 // the full list of currently available suggestions for that category, i.e., 39 // the full list of currently available suggestions for that category, i.e.,
40 // an empty list will remove all suggestions from the given category. Note 40 // an empty list will remove all suggestions from the given category. Note
41 // that to clear them from the UI immediately, the provider needs to change 41 // that to clear them from the UI immediately, the provider needs to change
42 // the status of the respective category. 42 // the status of the respective category. If the given |category| is not
43 // known yet, the calling |provider| will be registered as its provider.
Marc Treib 2016/08/01 17:30:35 Wait, can this actually happen? Wouldn't OnCategor
Philipp Keck 2016/08/02 08:15:46 We currently don't require it. A provider could ca
43 // IDs for the ContentSuggestions should be generated with 44 // IDs for the ContentSuggestions should be generated with
44 // |MakeUniqueID(..)| below. 45 // |MakeUniqueID(..)| below.
45 virtual void OnNewSuggestions( 46 virtual void OnNewSuggestions(
46 Category changed_category, 47 ContentSuggestionsProvider* provider,
48 Category category,
47 std::vector<ContentSuggestion> suggestions) = 0; 49 std::vector<ContentSuggestion> suggestions) = 0;
48 50
49 // Called when the status of a category changed. 51 // Called when the status of a category changed.
50 // |new_status| must be the value that is currently returned from the 52 // If |new_status| is NOT_PROVIDED, the calling provider must be the one
51 // provider's |GetCategoryStatus(category)| below. 53 // that currently provides the |category|, and the category is unregistered
52 // Whenever the status changes to an unavailable status, all suggestions in 54 // without clearing the UI. The |category| must also be removed from
53 // that category must immediately be removed from all caches and from the 55 // |GetProvidedCategories()|.
54 // UI. 56 // If |new_status| is any other value, it must match the value that is
55 virtual void OnCategoryStatusChanged(Category changed_category, 57 // currently returned from the provider's |GetCategoryStatus(category)|. In
58 // case the given |category| is not known yet, the calling |provider| will
59 // be registered as its provider. Whenever the status changes to an
60 // unavailable status, all suggestions in that category must immediately be
61 // removed from all caches and from the UI, but the provider remains
62 // registered.
63 virtual void OnCategoryStatusChanged(ContentSuggestionsProvider* provider,
64 Category category,
56 CategoryStatus new_status) = 0; 65 CategoryStatus new_status) = 0;
57 66
58 // Called when the provider needs to shut down and will not deliver any 67 // Called when the provider needs to shut down and will not deliver any
59 // suggestions anymore. 68 // suggestions anymore.
60 virtual void OnProviderShutdown(ContentSuggestionsProvider* provider) = 0; 69 virtual void OnProviderShutdown(ContentSuggestionsProvider* provider) = 0;
61 }; 70 };
62 71
63 // Sets an observer which is notified about changes to the available 72 // Sets an observer which is notified about changes to the available
64 // suggestions, or removes it by passing a nullptr. The provider does not take 73 // suggestions, or removes it by passing a nullptr. The provider does not take
65 // ownership of the observer and the observer must outlive this provider. 74 // ownership of the observer and the observer must outlive this provider.
66 virtual void SetObserver(Observer* observer) = 0; 75 virtual void SetObserver(Observer* observer) = 0;
67 76
68 // Returns the categories provided by this provider. 77 // Returns the categories provided by this provider.
69 // TODO(pke): "The value returned by this getter must not change unless 78 // When the set of provided categories changes, the Observer is notified
70 // OnXxx is called on the observer." 79 // through |OnNewSuggestions| or |OnCategoryStatusChanged| for added
80 // categories, and through |OnCategoryStatusChanged| with parameter
81 // NOT_PROVIDED for removed categories.
71 virtual std::vector<Category> GetProvidedCategories() = 0; 82 virtual std::vector<Category> GetProvidedCategories() = 0;
72 83
73 // Determines the status of the given |category|, see CategoryStatus. 84 // Determines the status of the given |category|, see CategoryStatus.
74 virtual CategoryStatus GetCategoryStatus(Category category) = 0; 85 virtual CategoryStatus GetCategoryStatus(Category category) = 0;
75 86
76 // Dismisses the suggestion with the given ID. A provider needs to ensure that 87 // Dismisses the suggestion with the given ID. A provider needs to ensure that
77 // a once-dismissed suggestion is never delivered again (through the 88 // a once-dismissed suggestion is never delivered again (through the
78 // Observer). The provider must not call Observer::OnSuggestionsChanged if the 89 // Observer). The provider must not call Observer::OnSuggestionsChanged if the
79 // removal of the dismissed suggestion is the only change. 90 // removal of the dismissed suggestion is the only change.
80 virtual void DismissSuggestion(const std::string& suggestion_id) = 0; 91 virtual void DismissSuggestion(const std::string& suggestion_id) = 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 124
114 CategoryFactory* category_factory() const { return category_factory_; } 125 CategoryFactory* category_factory() const { return category_factory_; }
115 126
116 private: 127 private:
117 CategoryFactory* category_factory_; 128 CategoryFactory* category_factory_;
118 }; 129 };
119 130
120 } // namespace ntp_snippets 131 } // namespace ntp_snippets
121 132
122 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ 133 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698