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

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

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

Powered by Google App Engine
This is Rietveld 408576698