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

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

Issue 2395753003: [NTP Snippets] Hook up background fetching scheduler to UserClassifier (Closed)
Patch Set: Created 4 years, 2 months 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_NTP_SNIPPETS_SERVICE_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_ 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_
7 7
8 #include <cstddef> 8 #include <cstddef>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 29 matching lines...) Expand all
40 class ImageFetcher; 40 class ImageFetcher;
41 } // namespace image_fetcher 41 } // namespace image_fetcher
42 42
43 namespace suggestions { 43 namespace suggestions {
44 class SuggestionsProfile; 44 class SuggestionsProfile;
45 } // namespace suggestions 45 } // namespace suggestions
46 46
47 namespace ntp_snippets { 47 namespace ntp_snippets {
48 48
49 class NTPSnippetsDatabase; 49 class NTPSnippetsDatabase;
50 class UserClassifier;
50 51
51 // Retrieves fresh content data (articles) from the server, stores them and 52 // Retrieves fresh content data (articles) from the server, stores them and
52 // provides them as content suggestions. 53 // provides them as content suggestions.
53 // This class is final because it does things in its constructor which make it 54 // This class is final because it does things in its constructor which make it
54 // unsafe to derive from it. 55 // unsafe to derive from it.
55 // TODO(treib): Introduce two-phase initialization and make the class not final? 56 // TODO(treib): Introduce two-phase initialization and make the class not final?
56 // TODO(pke): Rename this service to ArticleSuggestionsProvider and move to 57 // TODO(pke): Rename this service to ArticleSuggestionsProvider and move to
57 // a subdirectory. 58 // a subdirectory.
58 // TODO(jkrcal): this class grows really, really large. The fact that 59 // TODO(jkrcal): this class grows really, really large. The fact that
59 // NTPSnippetService also implements ImageFetcherDelegate adds unnecessary 60 // NTPSnippetService also implements ImageFetcherDelegate adds unnecessary
60 // complexity (and after all the Service is conceptually not an 61 // complexity (and after all the Service is conceptually not an
61 // ImagerFetcherDeletage ;-)). Instead, the cleaner solution would be to define 62 // ImagerFetcherDeletage ;-)). Instead, the cleaner solution would be to define
62 // a CachedImageFetcher class that handles the caching aspects and looks like an 63 // a CachedImageFetcher class that handles the caching aspects and looks like an
63 // image fetcher to the NTPSnippetService. 64 // image fetcher to the NTPSnippetService.
64 class NTPSnippetsService final : public ContentSuggestionsProvider, 65 class NTPSnippetsService final : public ContentSuggestionsProvider,
65 public image_fetcher::ImageFetcherDelegate { 66 public image_fetcher::ImageFetcherDelegate {
66 public: 67 public:
67 // |application_language_code| should be a ISO 639-1 compliant string, e.g. 68 // |application_language_code| should be a ISO 639-1 compliant string, e.g.
68 // 'en' or 'en-US'. Note that this code should only specify the language, not 69 // 'en' or 'en-US'. Note that this code should only specify the language, not
69 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' 70 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US'
70 // (British English person in the US) are not language codes. 71 // (British English person in the US) are not language codes.
71 NTPSnippetsService(Observer* observer, 72 NTPSnippetsService(Observer* observer,
72 CategoryFactory* category_factory, 73 CategoryFactory* category_factory,
73 PrefService* pref_service, 74 PrefService* pref_service,
74 suggestions::SuggestionsService* suggestions_service, 75 suggestions::SuggestionsService* suggestions_service,
75 const std::string& application_language_code, 76 const std::string& application_language_code,
77 const UserClassifier* user_classifier,
76 NTPSnippetsScheduler* scheduler, 78 NTPSnippetsScheduler* scheduler,
77 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, 79 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher,
78 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, 80 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher,
79 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder, 81 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder,
80 std::unique_ptr<NTPSnippetsDatabase> database, 82 std::unique_ptr<NTPSnippetsDatabase> database,
81 std::unique_ptr<NTPSnippetsStatusService> status_service); 83 std::unique_ptr<NTPSnippetsStatusService> status_service);
82 84
83 ~NTPSnippetsService() override; 85 ~NTPSnippetsService() override;
84 86
85 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 87 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 CategoryContent(); 331 CategoryContent();
330 CategoryContent(CategoryContent&&); 332 CategoryContent(CategoryContent&&);
331 ~CategoryContent(); 333 ~CategoryContent();
332 CategoryContent& operator=(CategoryContent&&); 334 CategoryContent& operator=(CategoryContent&&);
333 }; 335 };
334 std::map<Category, CategoryContent, Category::CompareByID> categories_; 336 std::map<Category, CategoryContent, Category::CompareByID> categories_;
335 337
336 // The ISO 639-1 code of the language used by the application. 338 // The ISO 639-1 code of the language used by the application.
337 const std::string application_language_code_; 339 const std::string application_language_code_;
338 340
341 // Classifier that tells us how active the user is. Not owned.
342 const UserClassifier* user_classifier_;
343
339 // Scheduler for fetching snippets. Not owned. 344 // Scheduler for fetching snippets. Not owned.
340 NTPSnippetsScheduler* scheduler_; 345 NTPSnippetsScheduler* scheduler_;
341 346
342 // The subscription to the SuggestionsService. When the suggestions change, 347 // The subscription to the SuggestionsService. When the suggestions change,
343 // SuggestionsService will call |OnSuggestionsChanged|, which triggers an 348 // SuggestionsService will call |OnSuggestionsChanged|, which triggers an
344 // update to the set of snippets. 349 // update to the set of snippets.
345 using SuggestionsSubscription = 350 using SuggestionsSubscription =
346 suggestions::SuggestionsService::ResponseCallbackList::Subscription; 351 suggestions::SuggestionsService::ResponseCallbackList::Subscription;
347 std::unique_ptr<SuggestionsSubscription> suggestions_service_subscription_; 352 std::unique_ptr<SuggestionsSubscription> suggestions_service_subscription_;
348 353
(...skipping 20 matching lines...) Expand all
369 374
370 // Request throttler for limiting requests to thumbnail images. 375 // Request throttler for limiting requests to thumbnail images.
371 RequestThrottler thumbnail_requests_throttler_; 376 RequestThrottler thumbnail_requests_throttler_;
372 377
373 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); 378 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService);
374 }; 379 };
375 380
376 } // namespace ntp_snippets 381 } // namespace ntp_snippets
377 382
378 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_ 383 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698