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

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: Put the status-change notification back in RegisterProvider() 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. This may be called with |category|
43 // values that are not yet provided by any provider to create a new
44 // category.
Marc Treib 2016/08/01 14:23:37 I find this a bit confusing... it's not called wit
Philipp Keck 2016/08/01 14:59:03 Done. Changed here and below.
43 // IDs for the ContentSuggestions should be generated with 45 // IDs for the ContentSuggestions should be generated with
44 // |MakeUniqueID(..)| below. 46 // |MakeUniqueID(..)| below.
45 virtual void OnNewSuggestions( 47 virtual void OnNewSuggestions(
46 Category changed_category, 48 ContentSuggestionsProvider* provider,
49 Category category,
47 std::vector<ContentSuggestion> suggestions) = 0; 50 std::vector<ContentSuggestion> suggestions) = 0;
48 51
49 // Called when the status of a category changed. 52 // Called when the status of a category changed.
50 // |new_status| must be the value that is currently returned from the 53 // |new_status| must be the value that is currently returned from the
51 // provider's |GetCategoryStatus(category)| below. 54 // provider's |GetCategoryStatus(category)| below (unless it is
55 // NOT_PROVIDED).
Marc Treib 2016/08/01 14:23:37 I don't understand this - for NOT_PROVIDED, whatev
Philipp Keck 2016/08/01 14:59:03 Well, the current provider implementations just DC
Marc Treib 2016/08/01 15:17:47 The consistent behavior with GetCategoryInfo() is
Philipp Keck 2016/08/01 15:58:11 The notion of "existing" is relatively cumbersome
tschumann 2016/08/01 16:30:12 We should work towards a sound model, where the ob
Philipp Keck 2016/08/01 17:04:57 Acknowledged.
56 // This may be called with |category| values that are not yet provided by
57 // any provider to create a new category.
52 // Whenever the status changes to an unavailable status, all suggestions in 58 // Whenever the status changes to an unavailable status, all suggestions in
53 // that category must immediately be removed from all caches and from the 59 // that category must immediately be removed from all caches and from the
54 // UI. 60 // UI, but the provider remains registered. When the status changes to
55 virtual void OnCategoryStatusChanged(Category changed_category, 61 // NOT_PROVIDED, the category is unregistered without clearing the UI and
62 // must also be removed from |GetProvidedCategories()|.
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 // The value returned by this getter must not change unless OnNewSuggestions
Marc Treib 2016/08/01 14:23:37 I'd formulate this as something like: When the set
Philipp Keck 2016/08/01 14:59:03 Done.
70 // OnXxx is called on the observer." 79 // (for adding categories) or OnCategoryStatusChanged (with NOT_PROVIDED for
80 // removing categories) is called on the observer.
tschumann 2016/08/01 14:21:17 i wonder if we can get rid of this function at all
Philipp Keck 2016/08/01 14:59:03 Yes we can, though I'm not sure about how we shoul
Marc Treib 2016/08/01 15:17:47 The service has the list categories per provider a
Philipp Keck 2016/08/01 15:58:11 Acknowledged.
tschumann 2016/08/01 16:24:08 To follow up briefly (we can move on offline): The
Philipp Keck 2016/08/01 17:04:57 Acknowledged.
Marc Treib 2016/08/01 17:30:35 Yay!
71 virtual std::vector<Category> GetProvidedCategories() = 0; 81 virtual std::vector<Category> GetProvidedCategories() = 0;
72 82
73 // Determines the status of the given |category|, see CategoryStatus. 83 // Determines the status of the given |category|, see CategoryStatus.
74 virtual CategoryStatus GetCategoryStatus(Category category) = 0; 84 virtual CategoryStatus GetCategoryStatus(Category category) = 0;
75 85
76 // Dismisses the suggestion with the given ID. A provider needs to ensure that 86 // Dismisses the suggestion with the given ID. A provider needs to ensure that
77 // a once-dismissed suggestion is never delivered again (through the 87 // a once-dismissed suggestion is never delivered again (through the
78 // Observer). The provider must not call Observer::OnSuggestionsChanged if the 88 // Observer). The provider must not call Observer::OnSuggestionsChanged if the
79 // removal of the dismissed suggestion is the only change. 89 // removal of the dismissed suggestion is the only change.
80 virtual void DismissSuggestion(const std::string& suggestion_id) = 0; 90 virtual void DismissSuggestion(const std::string& suggestion_id) = 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 123
114 CategoryFactory* category_factory() const { return category_factory_; } 124 CategoryFactory* category_factory() const { return category_factory_; }
115 125
116 private: 126 private:
117 CategoryFactory* category_factory_; 127 CategoryFactory* category_factory_;
118 }; 128 };
119 129
120 } // namespace ntp_snippets 130 } // namespace ntp_snippets
121 131
122 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ 132 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698