| 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 <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/time/clock.h" | 19 #include "base/time/clock.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "components/image_fetcher/image_fetcher_delegate.h" | 21 #include "components/image_fetcher/image_fetcher_delegate.h" |
| 22 #include "components/ntp_snippets/category.h" | 22 #include "components/ntp_snippets/category.h" |
| 23 #include "components/ntp_snippets/category_factory.h" | |
| 24 #include "components/ntp_snippets/category_status.h" | 23 #include "components/ntp_snippets/category_status.h" |
| 25 #include "components/ntp_snippets/content_suggestion.h" | 24 #include "components/ntp_snippets/content_suggestion.h" |
| 26 #include "components/ntp_snippets/content_suggestions_provider.h" | 25 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 27 #include "components/ntp_snippets/remote/ntp_snippet.h" | 26 #include "components/ntp_snippets/remote/ntp_snippet.h" |
| 28 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" | 27 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" |
| 29 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" | 28 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" |
| 30 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" | 29 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" |
| 31 #include "components/ntp_snippets/remote/request_throttler.h" | 30 #include "components/ntp_snippets/remote/request_throttler.h" |
| 32 | 31 |
| 33 class PrefRegistrySimple; | 32 class PrefRegistrySimple; |
| 34 class PrefService; | 33 class PrefService; |
| 35 | 34 |
| 36 namespace gfx { | 35 namespace gfx { |
| 37 class Image; | 36 class Image; |
| 38 } // namespace gfx | 37 } // namespace gfx |
| 39 | 38 |
| 40 namespace image_fetcher { | 39 namespace image_fetcher { |
| 41 class ImageDecoder; | 40 class ImageDecoder; |
| 42 class ImageFetcher; | 41 class ImageFetcher; |
| 43 } // namespace image_fetcher | 42 } // namespace image_fetcher |
| 44 | 43 |
| 45 namespace ntp_snippets { | 44 namespace ntp_snippets { |
| 46 | 45 |
| 47 class RemoteSuggestionsDatabase; | 46 class RemoteSuggestionsDatabase; |
| 47 class CategoryRanker; |
| 48 class UserClassifier; | 48 class UserClassifier; |
| 49 | 49 |
| 50 // Retrieves fresh content data (articles) from the server, stores them and | 50 // Retrieves fresh content data (articles) from the server, stores them and |
| 51 // provides them as content suggestions. | 51 // provides them as content suggestions. |
| 52 // This class is final because it does things in its constructor which make it | 52 // This class is final because it does things in its constructor which make it |
| 53 // unsafe to derive from it. | 53 // unsafe to derive from it. |
| 54 // TODO(treib): Introduce two-phase initialization and make the class not final? | 54 // TODO(treib): Introduce two-phase initialization and make the class not final? |
| 55 // TODO(jkrcal): this class grows really, really large. The fact that | 55 // TODO(jkrcal): this class grows really, really large. The fact that |
| 56 // NTPSnippetService also implements ImageFetcherDelegate adds unnecessary | 56 // NTPSnippetService also implements ImageFetcherDelegate adds unnecessary |
| 57 // complexity (and after all the Service is conceptually not an | 57 // complexity (and after all the Service is conceptually not an |
| 58 // ImagerFetcherDeletage ;-)). Instead, the cleaner solution would be to define | 58 // ImagerFetcherDeletage ;-)). Instead, the cleaner solution would be to define |
| 59 // a CachedImageFetcher class that handles the caching aspects and looks like an | 59 // a CachedImageFetcher class that handles the caching aspects and looks like an |
| 60 // image fetcher to the NTPSnippetService. | 60 // image fetcher to the NTPSnippetService. |
| 61 class RemoteSuggestionsProvider final | 61 class RemoteSuggestionsProvider final |
| 62 : public ContentSuggestionsProvider, | 62 : public ContentSuggestionsProvider, |
| 63 public image_fetcher::ImageFetcherDelegate { | 63 public image_fetcher::ImageFetcherDelegate { |
| 64 public: | 64 public: |
| 65 // |application_language_code| should be a ISO 639-1 compliant string, e.g. | 65 // |application_language_code| should be a ISO 639-1 compliant string, e.g. |
| 66 // 'en' or 'en-US'. Note that this code should only specify the language, not | 66 // 'en' or 'en-US'. Note that this code should only specify the language, not |
| 67 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' | 67 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' |
| 68 // (British English person in the US) are not language codes. | 68 // (British English person in the US) are not language codes. |
| 69 RemoteSuggestionsProvider( | 69 RemoteSuggestionsProvider( |
| 70 Observer* observer, | 70 Observer* observer, |
| 71 CategoryFactory* category_factory, | |
| 72 PrefService* pref_service, | 71 PrefService* pref_service, |
| 73 const std::string& application_language_code, | 72 const std::string& application_language_code, |
| 73 CategoryRanker* category_ranker, |
| 74 const UserClassifier* user_classifier, | 74 const UserClassifier* user_classifier, |
| 75 NTPSnippetsScheduler* scheduler, | 75 NTPSnippetsScheduler* scheduler, |
| 76 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, | 76 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, |
| 77 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, | 77 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, |
| 78 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder, | 78 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder, |
| 79 std::unique_ptr<RemoteSuggestionsDatabase> database, | 79 std::unique_ptr<RemoteSuggestionsDatabase> database, |
| 80 std::unique_ptr<RemoteSuggestionsStatusService> status_service); | 80 std::unique_ptr<RemoteSuggestionsStatusService> status_service); |
| 81 | 81 |
| 82 ~RemoteSuggestionsProvider() override; | 82 ~RemoteSuggestionsProvider() override; |
| 83 | 83 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 378 |
| 379 PrefService* pref_service_; | 379 PrefService* pref_service_; |
| 380 | 380 |
| 381 const Category articles_category_; | 381 const Category articles_category_; |
| 382 | 382 |
| 383 std::map<Category, CategoryContent, Category::CompareByID> category_contents_; | 383 std::map<Category, CategoryContent, Category::CompareByID> category_contents_; |
| 384 | 384 |
| 385 // The ISO 639-1 code of the language used by the application. | 385 // The ISO 639-1 code of the language used by the application. |
| 386 const std::string application_language_code_; | 386 const std::string application_language_code_; |
| 387 | 387 |
| 388 // Ranker that orders the categories. Not owned. |
| 389 CategoryRanker* category_ranker_; |
| 390 |
| 388 // Classifier that tells us how active the user is. Not owned. | 391 // Classifier that tells us how active the user is. Not owned. |
| 389 const UserClassifier* user_classifier_; | 392 const UserClassifier* user_classifier_; |
| 390 | 393 |
| 391 // Scheduler for fetching snippets. Not owned. | 394 // Scheduler for fetching snippets. Not owned. |
| 392 NTPSnippetsScheduler* scheduler_; | 395 NTPSnippetsScheduler* scheduler_; |
| 393 | 396 |
| 394 // The snippets fetcher. | 397 // The snippets fetcher. |
| 395 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; | 398 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; |
| 396 | 399 |
| 397 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; | 400 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 418 | 421 |
| 419 // A clock for getting the time. This allows to inject a clock in tests. | 422 // A clock for getting the time. This allows to inject a clock in tests. |
| 420 std::unique_ptr<base::Clock> clock_; | 423 std::unique_ptr<base::Clock> clock_; |
| 421 | 424 |
| 422 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProvider); | 425 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProvider); |
| 423 }; | 426 }; |
| 424 | 427 |
| 425 } // namespace ntp_snippets | 428 } // namespace ntp_snippets |
| 426 | 429 |
| 427 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ | 430 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ |
| OLD | NEW |