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

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: rebase. 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 <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"
25 #include "components/ntp_snippets/category_status.h" 24 #include "components/ntp_snippets/category_status.h"
26 #include "components/ntp_snippets/content_suggestion.h" 25 #include "components/ntp_snippets/content_suggestion.h"
27 #include "components/ntp_snippets/content_suggestions_provider.h" 26 #include "components/ntp_snippets/content_suggestions_provider.h"
28 #include "components/ntp_snippets/remote/ntp_snippet.h" 27 #include "components/ntp_snippets/remote/ntp_snippet.h"
29 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" 28 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h"
30 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h" 29 #include "components/ntp_snippets/remote/ntp_snippets_scheduler.h"
31 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h" 30 #include "components/ntp_snippets/remote/remote_suggestions_status_service.h"
32 #include "components/ntp_snippets/remote/request_throttler.h" 31 #include "components/ntp_snippets/remote/request_throttler.h"
33 32
34 class PrefRegistrySimple; 33 class PrefRegistrySimple;
35 class PrefService; 34 class PrefService;
36 35
37 namespace gfx { 36 namespace gfx {
38 class Image; 37 class Image;
39 } // namespace gfx 38 } // namespace gfx
40 39
41 namespace image_fetcher { 40 namespace image_fetcher {
42 class ImageDecoder; 41 class ImageDecoder;
43 class ImageFetcher; 42 class ImageFetcher;
44 } // namespace image_fetcher 43 } // namespace image_fetcher
45 44
46 namespace ntp_snippets { 45 namespace ntp_snippets {
47 46
48 class RemoteSuggestionsDatabase; 47 class RemoteSuggestionsDatabase;
48 class CategoryRanker;
49 class UserClassifier; 49 class UserClassifier;
50 50
51 // CachedImageFetcher takes care of fetching images from the network and caching 51 // CachedImageFetcher takes care of fetching images from the network and caching
52 // them in the database. 52 // them in the database.
53 // TODO(tschumann): Move into a separate library and inject the 53 // TODO(tschumann): Move into a separate library and inject the
54 // CachedImageFetcher into the RemoteSuggestionsProvider. This allows us to get 54 // CachedImageFetcher into the RemoteSuggestionsProvider. This allows us to get
55 // rid of exposing this member for testing and lets us test the caching logic 55 // rid of exposing this member for testing and lets us test the caching logic
56 // separately. 56 // separately.
57 class CachedImageFetcher : public image_fetcher::ImageFetcherDelegate { 57 class CachedImageFetcher : public image_fetcher::ImageFetcherDelegate {
58 public: 58 public:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // unsafe to derive from it. 107 // unsafe to derive from it.
108 // TODO(treib): Introduce two-phase initialization and make the class not final? 108 // TODO(treib): Introduce two-phase initialization and make the class not final?
109 class RemoteSuggestionsProvider final : public ContentSuggestionsProvider { 109 class RemoteSuggestionsProvider final : public ContentSuggestionsProvider {
110 public: 110 public:
111 // |application_language_code| should be a ISO 639-1 compliant string, e.g. 111 // |application_language_code| should be a ISO 639-1 compliant string, e.g.
112 // 'en' or 'en-US'. Note that this code should only specify the language, not 112 // 'en' or 'en-US'. Note that this code should only specify the language, not
113 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' 113 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US'
114 // (British English person in the US) are not language codes. 114 // (British English person in the US) are not language codes.
115 RemoteSuggestionsProvider( 115 RemoteSuggestionsProvider(
116 Observer* observer, 116 Observer* observer,
117 CategoryFactory* category_factory,
118 PrefService* pref_service, 117 PrefService* pref_service,
119 const std::string& application_language_code, 118 const std::string& application_language_code,
119 CategoryRanker* category_ranker,
120 const UserClassifier* user_classifier, 120 const UserClassifier* user_classifier,
121 NTPSnippetsScheduler* scheduler, 121 NTPSnippetsScheduler* scheduler,
122 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, 122 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher,
123 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, 123 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher,
124 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder, 124 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder,
125 std::unique_ptr<RemoteSuggestionsDatabase> database, 125 std::unique_ptr<RemoteSuggestionsDatabase> database,
126 std::unique_ptr<RemoteSuggestionsStatusService> status_service); 126 std::unique_ptr<RemoteSuggestionsStatusService> status_service);
127 127
128 ~RemoteSuggestionsProvider() override; 128 ~RemoteSuggestionsProvider() override;
129 129
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 401
402 PrefService* pref_service_; 402 PrefService* pref_service_;
403 403
404 const Category articles_category_; 404 const Category articles_category_;
405 405
406 std::map<Category, CategoryContent, Category::CompareByID> category_contents_; 406 std::map<Category, CategoryContent, Category::CompareByID> category_contents_;
407 407
408 // The ISO 639-1 code of the language used by the application. 408 // The ISO 639-1 code of the language used by the application.
409 const std::string application_language_code_; 409 const std::string application_language_code_;
410 410
411 // Ranker that orders the categories. Not owned.
412 CategoryRanker* category_ranker_;
413
411 // Classifier that tells us how active the user is. Not owned. 414 // Classifier that tells us how active the user is. Not owned.
412 const UserClassifier* user_classifier_; 415 const UserClassifier* user_classifier_;
413 416
414 // Scheduler for fetching snippets. Not owned. 417 // Scheduler for fetching snippets. Not owned.
415 NTPSnippetsScheduler* scheduler_; 418 NTPSnippetsScheduler* scheduler_;
416 419
417 // The snippets fetcher. 420 // The snippets fetcher.
418 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; 421 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_;
419 422
420 // The database for persisting snippets. 423 // The database for persisting snippets.
(...skipping 17 matching lines...) Expand all
438 441
439 // A clock for getting the time. This allows to inject a clock in tests. 442 // A clock for getting the time. This allows to inject a clock in tests.
440 std::unique_ptr<base::Clock> clock_; 443 std::unique_ptr<base::Clock> clock_;
441 444
442 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProvider); 445 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProvider);
443 }; 446 };
444 447
445 } // namespace ntp_snippets 448 } // namespace ntp_snippets
446 449
447 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_ 450 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698