| 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 | 17 |
| 18 // Retrieves fresh content data (articles) from the server, stores them and | 18 // Retrieves fresh content data (articles) from the server, stores them and |
| 19 // provides them as content suggestions. | 19 // provides them as content suggestions. |
| 20 class RemoteSuggestionsProvider : public ContentSuggestionsProvider { | 20 class RemoteSuggestionsProvider : public ContentSuggestionsProvider { |
| 21 public: | 21 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. | 22 // Callback to notify with the result of a fetch. |
| 31 // TODO(jkrcal): Change to OnceCallback? A OnceCallback does only have a | 23 // TODO(jkrcal): Change to OnceCallback? A OnceCallback does only have a |
| 32 // move-constructor which seems problematic for google mock. | 24 // move-constructor which seems problematic for google mock. |
| 33 using FetchStatusCallback = base::Callback<void(Status status_code)>; | 25 using FetchStatusCallback = base::Callback<void(Status status_code)>; |
| 34 | 26 |
| 35 ~RemoteSuggestionsProvider() override; | 27 ~RemoteSuggestionsProvider() override; |
| 36 | 28 |
| 37 // Set a callback to be notified whenever the status of the provider changes. | |
| 38 // The initial change is also notified (switching from an initial undecided | |
| 39 // status). If the callback is set after the first change, it is called back | |
| 40 // immediately. | |
| 41 // TODO(treib): Get rid of unique_ptrs to callbacks. | |
| 42 virtual void SetProviderStatusCallback( | |
| 43 std::unique_ptr<ProviderStatusCallback> callback) = 0; | |
| 44 | |
| 45 // Fetches suggestions from the server for all remote categories and replaces | 29 // 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 | 30 // 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 | 31 // an background request. Background requests are used for actions not |
| 48 // triggered by the user and have lower priority on the server. After the | 32 // 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 | 33 // fetch finished, the provided |callback| will be triggered with the status |
| 50 // of the fetch (unless nullptr). | 34 // of the fetch (unless nullptr). |
| 51 virtual void RefetchInTheBackground( | 35 virtual void RefetchInTheBackground( |
| 52 std::unique_ptr<FetchStatusCallback> callback) = 0; | 36 std::unique_ptr<FetchStatusCallback> callback) = 0; |
| 53 | 37 |
| 54 virtual const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() | 38 virtual const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() |
| 55 const = 0; | 39 const = 0; |
| 56 | 40 |
| 57 protected: | 41 protected: |
| 58 RemoteSuggestionsProvider(Observer* observer); | 42 RemoteSuggestionsProvider(Observer* observer); |
| 59 }; | 43 }; |
| 60 | 44 |
| 61 } // namespace ntp_snippets | 45 } // namespace ntp_snippets |
| 62 | 46 |
| 63 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ | 47 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ |
| OLD | NEW |