Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "components/ntp_snippets/content_suggestions_provider.h" | 12 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 13 | 13 |
| 14 namespace ntp_snippets { | 14 namespace ntp_snippets { |
| 15 | 15 |
| 16 class RemoteSuggestionsFetcher; | 16 class RemoteSuggestionsFetcher; |
| 17 class RemoteSuggestionsScheduler; | |
| 17 | 18 |
| 18 // Retrieves fresh content data (articles) from the server, stores them and | 19 // Retrieves fresh content data (articles) from the server, stores them and |
| 19 // provides them as content suggestions. | 20 // provides them as content suggestions. |
| 20 class RemoteSuggestionsProvider : public ContentSuggestionsProvider { | 21 class RemoteSuggestionsProvider : public ContentSuggestionsProvider { |
| 21 public: | 22 public: |
| 22 // TODO(jkrcal): Would be nice to get rid of this another level of statuses. | |
| 23 // Maybe possible while refactoring the RemoteSuggestionsStatusService? (and | |
| 24 // letting it notify both the SchedulingRemoteSuggestionsProvider and | |
| 25 // RemoteSuggestionsProviderImpl or just the scheduling one). | |
| 26 enum class ProviderStatus { ACTIVE, INACTIVE }; | |
| 27 using ProviderStatusCallback = | |
| 28 base::RepeatingCallback<void(ProviderStatus status)>; | |
| 29 | |
| 30 // Callback to notify with the result of a fetch. | 23 // Callback to notify with the result of a fetch. |
| 31 // TODO(jkrcal): Change to OnceCallback? A OnceCallback does only have a | 24 // TODO(jkrcal): Change to OnceCallback? A OnceCallback does only have a |
| 32 // move-constructor which seems problematic for google mock. | 25 // move-constructor which seems problematic for google mock. |
| 33 using FetchStatusCallback = base::Callback<void(Status status_code)>; | 26 using FetchStatusCallback = base::Callback<void(Status status_code)>; |
| 34 | 27 |
| 35 ~RemoteSuggestionsProvider() override; | 28 ~RemoteSuggestionsProvider() override; |
| 36 | 29 |
| 37 // Set a callback to be notified whenever the status of the provider changes. | 30 // Set the scheduler to be notified whenever the provider becomes active / |
| 38 // The initial change is also notified (switching from an initial undecided | 31 // in-active and whenever history is deleted. The initial change is also |
| 39 // status). If the callback is set after the first change, it is called back | 32 // notified (switching from an initial undecided status). If the scheduler is |
| 40 // immediately. | 33 // set after the first change, it is called back immediately. |
| 41 // TODO(treib): Get rid of unique_ptrs to callbacks. | 34 virtual void SetRemoteSuggestionsScheduler( |
|
tschumann
2017/02/24 09:37:12
Completely missed this (and thanks Marc for pointi
jkrcal
2017/02/24 09:47:04
I am puzzled: How is this different from the previ
tschumann
2017/02/24 10:22:59
The main issue was here before (guess we missed th
| |
| 42 virtual void SetProviderStatusCallback( | 35 RemoteSuggestionsScheduler* scheduler) = 0; |
| 43 std::unique_ptr<ProviderStatusCallback> callback) = 0; | |
| 44 | 36 |
| 45 // Fetches suggestions from the server for all remote categories and replaces | 37 // Fetches suggestions from the server for all remote categories and replaces |
| 46 // old suggestions by the new ones. The request to the server is performed as | 38 // old suggestions by the new ones. The request to the server is performed as |
| 47 // an background request. Background requests are used for actions not | 39 // an background request. Background requests are used for actions not |
| 48 // triggered by the user and have lower priority on the server. After the | 40 // triggered by the user and have lower priority on the server. After the |
| 49 // fetch finished, the provided |callback| will be triggered with the status | 41 // fetch finished, the provided |callback| will be triggered with the status |
| 50 // of the fetch (unless nullptr). | 42 // of the fetch (unless nullptr). |
| 51 virtual void RefetchInTheBackground( | 43 virtual void RefetchInTheBackground( |
| 52 std::unique_ptr<FetchStatusCallback> callback) = 0; | 44 std::unique_ptr<FetchStatusCallback> callback) = 0; |
| 53 | 45 |
| 54 virtual const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() | 46 virtual const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() |
| 55 const = 0; | 47 const = 0; |
| 56 | 48 |
| 57 protected: | 49 protected: |
| 58 RemoteSuggestionsProvider(Observer* observer); | 50 RemoteSuggestionsProvider(Observer* observer); |
| 59 }; | 51 }; |
| 60 | 52 |
| 61 } // namespace ntp_snippets | 53 } // namespace ntp_snippets |
| 62 | 54 |
| 63 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ | 55 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ |
| OLD | NEW |