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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_provider_impl.h

Issue 2786023002: [Remote suggestions] Remove the unique_ptr wrapper around callbacks (Closed)
Patch Set: Created 3 years, 8 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_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_
7 7
8 #include <cstddef> 8 #include <cstddef>
9 #include <deque> 9 #include <deque>
10 #include <map> 10 #include <map>
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // Returns whether the service is ready. While this is false, the list of 130 // Returns whether the service is ready. While this is false, the list of
131 // suggestions will be empty, and all modifications to it (fetch, dismiss, 131 // suggestions will be empty, and all modifications to it (fetch, dismiss,
132 // etc) will be ignored. 132 // etc) will be ignored.
133 bool ready() const { return state_ == State::READY; } 133 bool ready() const { return state_ == State::READY; }
134 134
135 // Returns whether the service is successfully initialized. While this is 135 // Returns whether the service is successfully initialized. While this is
136 // false, some calls may trigger DCHECKs. 136 // false, some calls may trigger DCHECKs.
137 bool initialized() const { return ready() || state_ == State::DISABLED; } 137 bool initialized() const { return ready() || state_ == State::DISABLED; }
138 138
139 // RemoteSuggestionsProvider implementation. 139 // RemoteSuggestionsProvider implementation.
140 void RefetchInTheBackground( 140 void RefetchInTheBackground(const FetchStatusCallback& callback) override;
141 std::unique_ptr<FetchStatusCallback> callback) override;
142 141
143 // TODO(fhorschig): Remove this getter when there is an interface for the 142 // TODO(fhorschig): Remove this getter when there is an interface for the
144 // fetcher that allows better mocks. 143 // fetcher that allows better mocks.
145 const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() 144 const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging()
146 const override; 145 const override;
147 146
148 // ContentSuggestionsProvider implementation. 147 // ContentSuggestionsProvider implementation.
149 CategoryStatus GetCategoryStatus(Category category) override; 148 CategoryStatus GetCategoryStatus(Category category) override;
150 CategoryInfo GetCategoryInfo(Category category) override; 149 CategoryInfo GetCategoryInfo(Category category) override;
151 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; 150 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 CategoryContent& operator=(CategoryContent&&); 285 CategoryContent& operator=(CategoryContent&&);
287 }; 286 };
288 287
289 // Fetches suggestions from the server and replaces old suggestions by the new 288 // Fetches suggestions from the server and replaces old suggestions by the new
290 // ones. Requests can be marked more important by setting 289 // ones. Requests can be marked more important by setting
291 // |interactive_request| to true (such request might circumvent the daily 290 // |interactive_request| to true (such request might circumvent the daily
292 // quota for requests, etc.), useful for requests triggered by the user. After 291 // quota for requests, etc.), useful for requests triggered by the user. After
293 // the fetch finished, the provided |callback| will be triggered with the 292 // the fetch finished, the provided |callback| will be triggered with the
294 // status of the fetch. 293 // status of the fetch.
295 void FetchSuggestions(bool interactive_request, 294 void FetchSuggestions(bool interactive_request,
296 std::unique_ptr<FetchStatusCallback> callback); 295 const FetchStatusCallback& callback);
297 296
298 // Returns the URL of the image of a suggestion if it is among the current or 297 // Returns the URL of the image of a suggestion if it is among the current or
299 // among the archived suggestions in the matching category. Returns an empty 298 // among the archived suggestions in the matching category. Returns an empty
300 // URL otherwise. 299 // URL otherwise.
301 GURL FindSuggestionImageUrl(const ContentSuggestion::ID& suggestion_id) const; 300 GURL FindSuggestionImageUrl(const ContentSuggestion::ID& suggestion_id) const;
302 301
303 // Callbacks for the RemoteSuggestionsDatabase. 302 // Callbacks for the RemoteSuggestionsDatabase.
304 void OnDatabaseLoaded(RemoteSuggestion::PtrVector suggestions); 303 void OnDatabaseLoaded(RemoteSuggestion::PtrVector suggestions);
305 void OnDatabaseError(); 304 void OnDatabaseError();
306 305
307 // Callback for fetch-more requests with the RemoteSuggestionsFetcher. 306 // Callback for fetch-more requests with the RemoteSuggestionsFetcher.
308 void OnFetchMoreFinished( 307 void OnFetchMoreFinished(
309 const FetchDoneCallback& fetching_callback, 308 const FetchDoneCallback& fetching_callback,
310 Status status, 309 Status status,
311 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories); 310 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories);
312 311
313 // Callback for regular fetch requests with the RemoteSuggestionsFetcher. 312 // Callback for regular fetch requests with the RemoteSuggestionsFetcher.
314 void OnFetchFinished( 313 void OnFetchFinished(
315 std::unique_ptr<FetchStatusCallback> callback, 314 const FetchStatusCallback& callback,
316 bool interactive_request, 315 bool interactive_request,
317 Status status, 316 Status status,
318 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories); 317 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories);
319 318
320 // Moves all suggestions from |to_archive| into the archive of the |content|. 319 // Moves all suggestions from |to_archive| into the archive of the |content|.
321 // Clears |to_archive|. As the archive is a FIFO buffer of limited size, this 320 // Clears |to_archive|. As the archive is a FIFO buffer of limited size, this
322 // function will also delete images from the database in case the associated 321 // function will also delete images from the database in case the associated
323 // suggestion gets evicted from the archive. 322 // suggestion gets evicted from the archive.
324 void ArchiveSuggestions(CategoryContent* content, 323 void ArchiveSuggestions(CategoryContent* content,
325 RemoteSuggestion::PtrVector* to_archive); 324 RemoteSuggestion::PtrVector* to_archive);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // The service that provides events and data about the signin and sync state. 440 // The service that provides events and data about the signin and sync state.
442 std::unique_ptr<RemoteSuggestionsStatusService> status_service_; 441 std::unique_ptr<RemoteSuggestionsStatusService> status_service_;
443 442
444 // Set to true if FetchSuggestions is called while the service isn't ready. 443 // Set to true if FetchSuggestions is called while the service isn't ready.
445 // The fetch will be executed once the service enters the READY state. 444 // The fetch will be executed once the service enters the READY state.
446 // TODO(jkrcal): create a struct and have here just one base::Optional<>? 445 // TODO(jkrcal): create a struct and have here just one base::Optional<>?
447 bool fetch_when_ready_; 446 bool fetch_when_ready_;
448 447
449 // The parameters for the fetch to perform later. 448 // The parameters for the fetch to perform later.
450 bool fetch_when_ready_interactive_; 449 bool fetch_when_ready_interactive_;
451 std::unique_ptr<FetchStatusCallback> fetch_when_ready_callback_; 450 FetchStatusCallback fetch_when_ready_callback_;
452 451
453 // Set to true if ClearHistoryDependentState is called while the service isn't 452 // Set to true if ClearHistoryDependentState is called while the service isn't
454 // ready. The nuke will be executed once the service finishes initialization 453 // ready. The nuke will be executed once the service finishes initialization
455 // or enters the READY state. 454 // or enters the READY state.
456 bool clear_history_dependent_state_when_initialized_; 455 bool clear_history_dependent_state_when_initialized_;
457 456
458 // A clock for getting the time. This allows to inject a clock in tests. 457 // A clock for getting the time. This allows to inject a clock in tests.
459 std::unique_ptr<base::Clock> clock_; 458 std::unique_ptr<base::Clock> clock_;
460 459
461 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderImpl); 460 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderImpl);
462 }; 461 };
463 462
464 } // namespace ntp_snippets 463 } // namespace ntp_snippets
465 464
466 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_ 465 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698