| 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 <cstddef> | 8 #include <cstddef> |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/callback_forward.h" | 17 #include "base/callback_forward.h" |
| 18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/time/clock.h" | 20 #include "base/time/clock.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "components/image_fetcher/image_fetcher_delegate.h" | 22 #include "components/image_fetcher/image_fetcher_delegate.h" |
| 23 #include "components/ntp_snippets/category.h" | 23 #include "components/ntp_snippets/category.h" |
| 24 #include "components/ntp_snippets/category_factory.h" | 24 #include "components/ntp_snippets/category_factory.h" |
| 25 #include "components/ntp_snippets/category_status.h" | 25 #include "components/ntp_snippets/category_status.h" |
| 26 #include "components/ntp_snippets/content_suggestion.h" | 26 #include "components/ntp_snippets/content_suggestion.h" |
| 27 #include "components/ntp_snippets/content_suggestions_provider.h" | 27 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 28 #include "components/ntp_snippets/remote/ntp_snippet.h" | 28 #include "components/ntp_snippets/remote/ntp_snippet.h" |
| 29 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" | 29 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" |
| 30 #include "components/ntp_snippets/remote/ntp_snippets_request_params.h" |
| 30 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" | 31 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" |
| 31 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" | 32 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" |
| 32 #include "components/ntp_snippets/remote/request_throttler.h" | 33 #include "components/ntp_snippets/remote/request_throttler.h" |
| 33 | 34 |
| 34 class PrefRegistrySimple; | 35 class PrefRegistrySimple; |
| 35 class PrefService; | 36 class PrefService; |
| 36 | 37 |
| 37 namespace gfx { | 38 namespace gfx { |
| 38 class Image; | 39 class Image; |
| 39 } // namespace gfx | 40 } // namespace gfx |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // Fetchs content suggestions from the Content Suggestions server for all | 142 // Fetchs content suggestions from the Content Suggestions server for all |
| 142 // remote categories in the background. | 143 // remote categories in the background. |
| 143 void FetchSnippetsInTheBackground(); | 144 void FetchSnippetsInTheBackground(); |
| 144 | 145 |
| 145 // Fetchs content suggestions from the Content Suggestions server for all | 146 // Fetchs content suggestions from the Content Suggestions server for all |
| 146 // remote categories. The request to the server is performed as an interactive | 147 // remote categories. The request to the server is performed as an interactive |
| 147 // request. Interactive requests are used for actions triggered by the user | 148 // request. Interactive requests are used for actions triggered by the user |
| 148 // and request lower latency processing. | 149 // and request lower latency processing. |
| 149 void FetchSnippetsForAllCategories(); | 150 void FetchSnippetsForAllCategories(); |
| 150 | 151 |
| 152 // Only used in tests and for debugging in snippets-internal/. |
| 153 // TODO(fhorschig): Remove this getter when there is an interface for the |
| 154 // fetcher that allows better mocks. |
| 151 const NTPSnippetsFetcher* snippets_fetcher() const { | 155 const NTPSnippetsFetcher* snippets_fetcher() const { |
| 152 return snippets_fetcher_.get(); | 156 return snippets_fetcher_.get(); |
| 153 } | 157 } |
| 154 | 158 |
| 155 // (Re)schedules the periodic fetching of snippets. If |force| is true, the | 159 // (Re)schedules the periodic fetching of snippets. If |force| is true, the |
| 156 // tasks will be re-scheduled even if they already exist and have the correct | 160 // tasks will be re-scheduled even if they already exist and have the correct |
| 157 // periods. | 161 // periods. |
| 158 void RescheduleFetching(bool force); | 162 void RescheduleFetching(bool force); |
| 159 | 163 |
| 160 // ContentSuggestionsProvider implementation | 164 // ContentSuggestionsProvider implementation |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 390 |
| 387 // Updates the category info for |category|. If a corresponding | 391 // Updates the category info for |category|. If a corresponding |
| 388 // CategoryContent object does not exist, it will be created. | 392 // CategoryContent object does not exist, it will be created. |
| 389 // Returns the existing or newly created object. | 393 // Returns the existing or newly created object. |
| 390 CategoryContent* UpdateCategoryInfo(Category category, | 394 CategoryContent* UpdateCategoryInfo(Category category, |
| 391 const CategoryInfo& info); | 395 const CategoryInfo& info); |
| 392 | 396 |
| 393 void RestoreCategoriesFromPrefs(); | 397 void RestoreCategoriesFromPrefs(); |
| 394 void StoreCategoriesToPrefs(); | 398 void StoreCategoriesToPrefs(); |
| 395 | 399 |
| 396 NTPSnippetsFetcher::Params BuildFetchParams() const; | 400 NTPSnippetsRequestParams BuildFetchParams() const; |
| 397 | 401 |
| 398 void MarkEmptyCategoriesAsLoading(); | 402 void MarkEmptyCategoriesAsLoading(); |
| 399 | 403 |
| 400 State state_; | 404 State state_; |
| 401 | 405 |
| 402 PrefService* pref_service_; | 406 PrefService* pref_service_; |
| 403 | 407 |
| 404 const Category articles_category_; | 408 const Category articles_category_; |
| 405 | 409 |
| 406 std::map<Category, CategoryContent, Category::CompareByID> category_contents_; | 410 std::map<Category, CategoryContent, Category::CompareByID> category_contents_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 442 |
| 439 // A clock for getting the time. This allows to inject a clock in tests. | 443 // A clock for getting the time. This allows to inject a clock in tests. |
| 440 std::unique_ptr<base::Clock> clock_; | 444 std::unique_ptr<base::Clock> clock_; |
| 441 | 445 |
| 442 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProvider); | 446 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProvider); |
| 443 }; | 447 }; |
| 444 | 448 |
| 445 } // namespace ntp_snippets | 449 } // namespace ntp_snippets |
| 446 | 450 |
| 447 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ | 451 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ |
| OLD | NEW |