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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_suggestions_observer.h

Issue 2811813002: [Offline Pages] Set up the initial prefetching service. (Closed)
Patch Set: Remove offline page model. 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_OBSERVER_H _
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_OBSERVER_H _
Dmitry Titov 2017/04/11 21:50:46 These ifdefs and file name need to match the class
dewittj 2017/04/12 00:22:48 Done.
7
8 #include <memory>
9
10 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h"
12 #include "components/ntp_snippets/content_suggestions_service.h"
13 #include "components/offline_pages/core/prefetch/prefetch_service.h"
14
15 namespace content {
16 class BrowserContext;
17 } // namespace content
18
19 namespace ntp_snippets {
20 class Category;
21 }
22
23 namespace offline_pages {
24
25 // Observes the ContentSuggestionsService, listening for new suggestions of a
26 // single category (initially ARTICLES). When those suggestions arrive, it
27 // then forwards them to the Prefetch Service.
28 class SuggestionsObserver
29 : public ntp_snippets::ContentSuggestionsService::Observer,
30 base::SupportsUserData::Data {
31 public:
32 // Abstract delegate for easy dependency injection in testing.
33 class Delegate {
34 public:
35 virtual std::vector<GURL> GetSuggestionURLs(
36 const ntp_snippets::Category& category) = 0;
37 virtual PrefetchService* GetPrefetchService(
38 content::BrowserContext* context) = 0;
39 virtual ~Delegate() = default;
40 };
41
42 // This API creates a new SuggestionsObserver and adds it as an
43 // observer to the ContentSuggestionsService provided. Its lifetime is
44 // self-managed, and it deletes itself upon receiving the
45 // |ContentSuggestionsServiceShutdown| signal using an asynchronous
46 // |DeleteSoon|.
47 static void ObserveContentSuggestionsService(
48 content::BrowserContext* browser_context,
49 ntp_snippets::ContentSuggestionsService* service);
50
51 SuggestionsObserver(content::BrowserContext* browser_context,
52 std::unique_ptr<Delegate> delegate,
53 const ntp_snippets::Category& category);
54 ~SuggestionsObserver() override;
55
56 // ContentSuggestionsService::Observer overrides
jianli 2017/04/11 22:39:55 nit: end with ":"
dewittj 2017/04/12 00:22:48 Done.
57 void OnNewSuggestions(ntp_snippets::Category category) override;
58 void OnCategoryStatusChanged(
59 ntp_snippets::Category category,
60 ntp_snippets::CategoryStatus new_status) override;
61 void OnSuggestionInvalidated(
62 const ntp_snippets::ContentSuggestion::ID& suggestion_id) override;
63 void OnFullRefreshRequired() override;
64 void ContentSuggestionsServiceShutdown() override;
65
66 private:
67 std::unique_ptr<Delegate> delegate_;
68 content::BrowserContext* browser_context_;
69 ntp_snippets::CategoryStatus category_status_ =
70 ntp_snippets::CategoryStatus::INITIALIZING;
71 ntp_snippets::Category category_;
72
73 DISALLOW_COPY_AND_ASSIGN(SuggestionsObserver);
74 };
75
76 } // namespace offline_pages
77
78 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_OBSERVE R_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698