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

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

Issue 2167063003: Rename discard to dismiss for NTP snippets and content suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bridgeumbiegen
Patch Set: Fix unit test Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_NTP_SNIPPETS_SERVICE_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 std::unique_ptr<NTPSnippetsStatusService> status_service); 85 std::unique_ptr<NTPSnippetsStatusService> status_service);
86 86
87 ~NTPSnippetsService() override; 87 ~NTPSnippetsService() override;
88 88
89 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 89 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
90 90
91 // Inherited from KeyedService. 91 // Inherited from KeyedService.
92 void Shutdown() override; 92 void Shutdown() override;
93 93
94 // Returns whether the service is ready. While this is false, the list of 94 // Returns whether the service is ready. While this is false, the list of
95 // snippets will be empty, and all modifications to it (fetch, discard, etc) 95 // snippets will be empty, and all modifications to it (fetch, dismiss, etc)
96 // will be ignored. 96 // will be ignored.
97 bool ready() const { return state_ == State::READY; } 97 bool ready() const { return state_ == State::READY; }
98 98
99 // Returns whether the service is initialized. While this is false, some 99 // Returns whether the service is initialized. While this is false, some
100 // calls may trigger DCHECKs. 100 // calls may trigger DCHECKs.
101 bool initialized() const { return ready() || state_ == State::DISABLED; } 101 bool initialized() const { return ready() || state_ == State::DISABLED; }
102 102
103 // Fetches snippets from the server and adds them to the current ones. 103 // Fetches snippets from the server and adds them to the current ones.
104 void FetchSnippets(); 104 void FetchSnippets();
105 // Fetches snippets from the server for specified hosts (overriding 105 // Fetches snippets from the server for specified hosts (overriding
106 // suggestions from the suggestion service) and adds them to the current ones. 106 // suggestions from the suggestion service) and adds them to the current ones.
107 // Only called from chrome://snippets-internals, DO NOT USE otherwise! 107 // Only called from chrome://snippets-internals, DO NOT USE otherwise!
108 // Ignored while |loaded()| is false. 108 // Ignored while |loaded()| is false.
109 void FetchSnippetsFromHosts(const std::set<std::string>& hosts); 109 void FetchSnippetsFromHosts(const std::set<std::string>& hosts);
110 110
111 // Available snippets. 111 // Available snippets.
112 const NTPSnippet::PtrVector& snippets() const { return snippets_; } 112 const NTPSnippet::PtrVector& snippets() const { return snippets_; }
113 113
114 // Returns the list of snippets previously discarded by the user (that are 114 // Returns the list of snippets previously dismissed by the user (that are
115 // not expired yet). 115 // not expired yet).
116 const NTPSnippet::PtrVector& discarded_snippets() const { 116 const NTPSnippet::PtrVector& dismissed_snippets() const {
117 return discarded_snippets_; 117 return dismissed_snippets_;
118 } 118 }
119 119
120 const NTPSnippetsFetcher* snippets_fetcher() const { 120 const NTPSnippetsFetcher* snippets_fetcher() const {
121 return snippets_fetcher_.get(); 121 return snippets_fetcher_.get();
122 } 122 }
123 123
124 // Returns a reason why the service is disabled, or DisabledReason::NONE 124 // Returns a reason why the service is disabled, or DisabledReason::NONE
125 // if it's not. 125 // if it's not.
126 DisabledReason disabled_reason() const { 126 DisabledReason disabled_reason() const {
127 return snippets_status_service_->disabled_reason(); 127 return snippets_status_service_->disabled_reason();
128 } 128 }
129 129
130 // (Re)schedules the periodic fetching of snippets. This is necessary because 130 // (Re)schedules the periodic fetching of snippets. This is necessary because
131 // the schedule depends on the time of day. 131 // the schedule depends on the time of day.
132 void RescheduleFetching(); 132 void RescheduleFetching();
133 133
134 // ContentSuggestionsProvider implementation 134 // ContentSuggestionsProvider implementation
135 // TODO(pke): At some point reorder the implementations in the .cc file 135 // TODO(pke): At some point reorder the implementations in the .cc file
136 // accordingly. 136 // accordingly.
137 void SetObserver(Observer* observer) override; 137 void SetObserver(Observer* observer) override;
138 ContentSuggestionsCategoryStatus GetCategoryStatus( 138 ContentSuggestionsCategoryStatus GetCategoryStatus(
139 ContentSuggestionsCategory category) override; 139 ContentSuggestionsCategory category) override;
140 void DiscardSuggestion(const std::string& suggestion_id) override; 140 void DismissSuggestion(const std::string& suggestion_id) override;
141 void FetchSuggestionImage(const std::string& suggestion_id, 141 void FetchSuggestionImage(const std::string& suggestion_id,
142 const ImageFetchedCallback& callback) override; 142 const ImageFetchedCallback& callback) override;
143 void ClearCachedSuggestionsForDebugging() override; 143 void ClearCachedSuggestionsForDebugging() override;
144 void ClearDiscardedSuggestionsForDebugging() override; 144 void ClearDismissedSuggestionsForDebugging() override;
145 145
146 // Returns the lists of suggestion hosts the snippets are restricted to. 146 // Returns the lists of suggestion hosts the snippets are restricted to.
147 std::set<std::string> GetSuggestionsHosts() const; 147 std::set<std::string> GetSuggestionsHosts() const;
148 148
149 // Observer accessors. 149 // Observer accessors.
150 void AddObserver(NTPSnippetsServiceObserver* observer); 150 void AddObserver(NTPSnippetsServiceObserver* observer);
151 void RemoveObserver(NTPSnippetsServiceObserver* observer); 151 void RemoveObserver(NTPSnippetsServiceObserver* observer);
152 152
153 // Returns the maximum number of snippets that will be shown at once. 153 // Returns the maximum number of snippets that will be shown at once.
154 static int GetMaxSnippetCountForTesting(); 154 static int GetMaxSnippetCountForTesting();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 // Callback for the NTPSnippetsFetcher. 210 // Callback for the NTPSnippetsFetcher.
211 void OnFetchFinished(NTPSnippetsFetcher::OptionalSnippets snippets); 211 void OnFetchFinished(NTPSnippetsFetcher::OptionalSnippets snippets);
212 212
213 // Merges newly available snippets with the previously available list. 213 // Merges newly available snippets with the previously available list.
214 void MergeSnippets(NTPSnippet::PtrVector new_snippets); 214 void MergeSnippets(NTPSnippet::PtrVector new_snippets);
215 215
216 std::set<std::string> GetSnippetHostsFromPrefs() const; 216 std::set<std::string> GetSnippetHostsFromPrefs() const;
217 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts); 217 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts);
218 218
219 // Removes the expired snippets (including discarded) from the service and the 219 // Removes the expired snippets (including dismissed) from the service and the
220 // database, and schedules another pass for the next expiration. 220 // database, and schedules another pass for the next expiration.
221 void ClearExpiredSnippets(); 221 void ClearExpiredSnippets();
222 222
223 // Completes the initialization phase of the service, registering the last 223 // Completes the initialization phase of the service, registering the last
224 // observers. This is done after construction, once the database is loaded. 224 // observers. This is done after construction, once the database is loaded.
225 void FinishInitialization(); 225 void FinishInitialization();
226 226
227 void OnSnippetImageFetchedFromDatabase(const std::string& snippet_id, 227 void OnSnippetImageFetchedFromDatabase(const std::string& snippet_id,
228 const ImageFetchedCallback& callback, 228 const ImageFetchedCallback& callback,
229 std::string data); 229 std::string data);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void NotifyCategoryStatusChanged(); 265 void NotifyCategoryStatusChanged();
266 266
267 State state_; 267 State state_;
268 268
269 ContentSuggestionsCategoryStatus category_status_; 269 ContentSuggestionsCategoryStatus category_status_;
270 270
271 PrefService* pref_service_; 271 PrefService* pref_service_;
272 272
273 suggestions::SuggestionsService* suggestions_service_; 273 suggestions::SuggestionsService* suggestions_service_;
274 274
275 // All current suggestions (i.e. not discarded ones). 275 // All current suggestions (i.e. not dismissed ones).
276 NTPSnippet::PtrVector snippets_; 276 NTPSnippet::PtrVector snippets_;
277 277
278 // Suggestions that the user discarded. We keep these around until they expire 278 // Suggestions that the user dismissed. We keep these around until they expire
279 // so we won't re-add them on the next fetch. 279 // so we won't re-add them on the next fetch.
280 NTPSnippet::PtrVector discarded_snippets_; 280 NTPSnippet::PtrVector dismissed_snippets_;
281 281
282 // The ISO 639-1 code of the language used by the application. 282 // The ISO 639-1 code of the language used by the application.
283 const std::string application_language_code_; 283 const std::string application_language_code_;
284 284
285 // The observers. 285 // The observers.
286 // TODO(pke): This is an old kind of observers that will be removed. 286 // TODO(pke): This is an old kind of observers that will be removed.
287 base::ObserverList<NTPSnippetsServiceObserver> observers_; 287 base::ObserverList<NTPSnippetsServiceObserver> observers_;
288 288
289 // The observer to deliver data to. 289 // The observer to deliver data to.
290 Observer* observer_; 290 Observer* observer_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // If the service might be enabled, DisabledReason::NONE will be provided. 336 // If the service might be enabled, DisabledReason::NONE will be provided.
337 virtual void NTPSnippetsServiceDisabledReasonChanged(DisabledReason) = 0; 337 virtual void NTPSnippetsServiceDisabledReasonChanged(DisabledReason) = 0;
338 338
339 protected: 339 protected:
340 virtual ~NTPSnippetsServiceObserver() {} 340 virtual ~NTPSnippetsServiceObserver() {}
341 }; 341 };
342 342
343 } // namespace ntp_snippets 343 } // namespace ntp_snippets
344 344
345 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 345 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_database_unittest.cc ('k') | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698