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

Side by Side Diff: components/ntp_snippets/content_suggestions_service.h

Issue 2790743003: [Content suggestions] Implement fetching publishers' favicons (Closed)
Patch Set: Minor fix Created 3 years, 8 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
« no previous file with comments | « components/ntp_snippets/DEPS ('k') | components/ntp_snippets/content_suggestions_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_CONTENT_SUGGESTIONS_SERVICE_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/optional.h" 16 #include "base/optional.h"
17 #include "base/scoped_observer.h" 17 #include "base/scoped_observer.h"
18 #include "base/task/cancelable_task_tracker.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "components/history/core/browser/history_service.h" 20 #include "components/history/core/browser/history_service.h"
20 #include "components/history/core/browser/history_service_observer.h" 21 #include "components/history/core/browser/history_service_observer.h"
21 #include "components/keyed_service/core/keyed_service.h" 22 #include "components/keyed_service/core/keyed_service.h"
22 #include "components/ntp_snippets/callbacks.h" 23 #include "components/ntp_snippets/callbacks.h"
23 #include "components/ntp_snippets/category.h" 24 #include "components/ntp_snippets/category.h"
24 #include "components/ntp_snippets/category_rankers/category_ranker.h" 25 #include "components/ntp_snippets/category_rankers/category_ranker.h"
25 #include "components/ntp_snippets/category_status.h" 26 #include "components/ntp_snippets/category_status.h"
26 #include "components/ntp_snippets/content_suggestions_provider.h" 27 #include "components/ntp_snippets/content_suggestions_provider.h"
27 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" 28 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h"
28 #include "components/ntp_snippets/user_classifier.h" 29 #include "components/ntp_snippets/user_classifier.h"
29 #include "components/signin/core/browser/signin_manager.h" 30 #include "components/signin/core/browser/signin_manager.h"
30 31
31 class PrefService; 32 class PrefService;
32 class PrefRegistrySimple; 33 class PrefRegistrySimple;
33 34
35 namespace favicon {
36 class LargeIconService;
37 } // namespace favicon
38
39 namespace favicon_base {
40 struct LargeIconImageResult;
41 } // namespace favicon_base
42
34 namespace ntp_snippets { 43 namespace ntp_snippets {
35 44
36 class RemoteSuggestionsProvider; 45 class RemoteSuggestionsProvider;
37 46
38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves 47 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves
39 // them grouped into categories. There can be at most one provider per category. 48 // them grouped into categories. There can be at most one provider per category.
40 class ContentSuggestionsService : public KeyedService, 49 class ContentSuggestionsService : public KeyedService,
41 public ContentSuggestionsProvider::Observer, 50 public ContentSuggestionsProvider::Observer,
42 public SigninManagerBase::Observer, 51 public SigninManagerBase::Observer,
43 public history::HistoryServiceObserver { 52 public history::HistoryServiceObserver {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 92
84 enum State { 93 enum State {
85 ENABLED, 94 ENABLED,
86 DISABLED, 95 DISABLED,
87 }; 96 };
88 97
89 ContentSuggestionsService( 98 ContentSuggestionsService(
90 State state, 99 State state,
91 SigninManagerBase* signin_manager, // Can be nullptr in unittests. 100 SigninManagerBase* signin_manager, // Can be nullptr in unittests.
92 history::HistoryService* history_service, // Can be nullptr in unittests. 101 history::HistoryService* history_service, // Can be nullptr in unittests.
102 // Can be nullptr in unittests.
103 favicon::LargeIconService* large_icon_service,
93 PrefService* pref_service, 104 PrefService* pref_service,
94 std::unique_ptr<CategoryRanker> category_ranker, 105 std::unique_ptr<CategoryRanker> category_ranker,
95 std::unique_ptr<UserClassifier> user_classifier, 106 std::unique_ptr<UserClassifier> user_classifier,
96 std::unique_ptr<RemoteSuggestionsScheduler> 107 std::unique_ptr<RemoteSuggestionsScheduler>
97 remote_suggestions_scheduler // Can be nullptr in unittests. 108 remote_suggestions_scheduler // Can be nullptr in unittests.
98 ); 109 );
99 ~ContentSuggestionsService() override; 110 ~ContentSuggestionsService() override;
100 111
101 // Inherited from KeyedService. 112 // Inherited from KeyedService.
102 void Shutdown() override; 113 void Shutdown() override;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 void NotifyCategoryStatusChanged(Category category); 321 void NotifyCategoryStatusChanged(Category category);
311 322
312 void OnSignInStateChanged(); 323 void OnSignInStateChanged();
313 324
314 // Re-enables a dismissed category, making querying its provider possible. 325 // Re-enables a dismissed category, making querying its provider possible.
315 void RestoreDismissedCategory(Category category); 326 void RestoreDismissedCategory(Category category);
316 327
317 void RestoreDismissedCategoriesFromPrefs(); 328 void RestoreDismissedCategoriesFromPrefs();
318 void StoreDismissedCategoriesToPrefs(); 329 void StoreDismissedCategoriesToPrefs();
319 330
331 // Callbacks for fetching favicons.
332 void OnGetFaviconFromCacheFinished(
333 const GURL& publisher_url,
334 int minimum_size_in_pixel,
335 int desired_size_in_pixel,
336 const ImageFetchedCallback& callback,
337 bool continue_to_google_server,
338 const favicon_base::LargeIconImageResult& result);
339 void OnGetFaviconFromGoogleServerFinished(
340 const GURL& publisher_url,
341 int minimum_size_in_pixel,
342 int desired_size_in_pixel,
343 const ImageFetchedCallback& callback,
344 bool success);
345
320 // Whether the content suggestions feature is enabled. 346 // Whether the content suggestions feature is enabled.
321 State state_; 347 State state_;
322 348
323 // All registered providers, owned by the service. 349 // All registered providers, owned by the service.
324 std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_; 350 std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_;
325 351
326 // All registered categories and their providers. A provider may be contained 352 // All registered categories and their providers. A provider may be contained
327 // multiple times, if it provides multiple categories. The keys of this map 353 // multiple times, if it provides multiple categories. The keys of this map
328 // are exactly the entries of |categories_| and the values are a subset of 354 // are exactly the entries of |categories_| and the values are a subset of
329 // |providers_|. 355 // |providers_|.
(...skipping 25 matching lines...) Expand all
355 381
356 // Observer for the HistoryService. All providers are notified when history is 382 // Observer for the HistoryService. All providers are notified when history is
357 // deleted. 383 // deleted.
358 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> 384 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
359 history_service_observer_; 385 history_service_observer_;
360 386
361 base::ObserverList<Observer> observers_; 387 base::ObserverList<Observer> observers_;
362 388
363 const std::vector<ContentSuggestion> no_suggestions_; 389 const std::vector<ContentSuggestion> no_suggestions_;
364 390
391 base::CancelableTaskTracker favicons_task_tracker_;
392
365 // Keep a direct reference to this special provider to redirect debugging 393 // Keep a direct reference to this special provider to redirect debugging
366 // calls to it. If the RemoteSuggestionsProvider is loaded, it is also present 394 // calls to it. If the RemoteSuggestionsProvider is loaded, it is also present
367 // in |providers_|, otherwise this is a nullptr. 395 // in |providers_|, otherwise this is a nullptr.
368 RemoteSuggestionsProvider* remote_suggestions_provider_; 396 RemoteSuggestionsProvider* remote_suggestions_provider_;
369 397
398 favicon::LargeIconService* large_icon_service_;
399
370 PrefService* pref_service_; 400 PrefService* pref_service_;
371 401
372 // Interface for informing about external events that have influence on 402 // Interface for informing about external events that have influence on
373 // scheduling remote fetches. 403 // scheduling remote fetches.
374 std::unique_ptr<RemoteSuggestionsScheduler> remote_suggestions_scheduler_; 404 std::unique_ptr<RemoteSuggestionsScheduler> remote_suggestions_scheduler_;
375 405
376 // Classifies the user on the basis of long-term user interactions. 406 // Classifies the user on the basis of long-term user interactions.
377 std::unique_ptr<UserClassifier> user_classifier_; 407 std::unique_ptr<UserClassifier> user_classifier_;
378 408
379 // Provides order for categories. 409 // Provides order for categories.
380 std::unique_ptr<CategoryRanker> category_ranker_; 410 std::unique_ptr<CategoryRanker> category_ranker_;
381 411
382 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); 412 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService);
383 }; 413 };
384 414
385 } // namespace ntp_snippets 415 } // namespace ntp_snippets
386 416
387 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ 417 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_
OLDNEW
« no previous file with comments | « components/ntp_snippets/DEPS ('k') | components/ntp_snippets/content_suggestions_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698