OLD | NEW |
---|---|
(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 _ | |
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/offline_page_types.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 class OfflinePageModel; | |
26 | |
27 class OfflinePageSuggestionsObserver | |
Dmitry Titov
2017/04/11 01:17:13
Perhaps this can be just SuggestionObserver.
carlosk
2017/04/11 17:31:36
Please add class comment.
dewittj
2017/04/11 21:25:48
Done.
dewittj
2017/04/11 21:25:48
Done.
| |
28 : public ntp_snippets::ContentSuggestionsService::Observer, | |
29 base::SupportsUserData::Data { | |
30 public: | |
31 // Abstract delegate for easy testing. | |
32 class Delegate { | |
33 public: | |
34 virtual std::vector<GURL> GetSuggestionURLs() = 0; | |
35 virtual void GetPagesWithURLs( | |
36 const std::vector<GURL>& suggestion_urls, | |
37 const MultipleOfflinePageItemCallback& callback) = 0; | |
38 virtual ~Delegate() = default; | |
39 }; | |
40 | |
41 // This API creates a new OfflinePageSuggestionsObserver and adds it as an | |
42 // observer to the ContentSuggestionsService provided. Its lifetime is | |
43 // self-managed, and it deletes itself upon receiving the | |
44 // |ContentSuggestionsServiceShutdown| signal using an asynchronous | |
45 // |DeleteSoon|. | |
46 static void ObserveContentSuggestionsService( | |
47 content::BrowserContext* browser_context, | |
48 offline_pages::OfflinePageModel* offline_page_model, | |
49 ntp_snippets::ContentSuggestionsService* service); | |
50 OfflinePageSuggestionsObserver(content::BrowserContext* browser_context, | |
Dmitry Titov
2017/04/11 01:17:13
nice to add an empty line before ctor.
dewittj
2017/04/11 21:25:48
Done.
| |
51 std::unique_ptr<Delegate> delegate, | |
52 const ntp_snippets::Category& category); | |
53 ~OfflinePageSuggestionsObserver() override; | |
54 | |
55 // ContentSuggestionsService::Observer overrides | |
56 void OnNewSuggestions(ntp_snippets::Category category) override; | |
57 void OnCategoryStatusChanged( | |
58 ntp_snippets::Category category, | |
59 ntp_snippets::CategoryStatus new_status) override; | |
60 void OnSuggestionInvalidated( | |
61 const ntp_snippets::ContentSuggestion::ID& suggestion_id) override; | |
62 void OnFullRefreshRequired() override; | |
63 void ContentSuggestionsServiceShutdown() override; | |
64 | |
65 private: | |
66 void GotPagesMatchingSuggestions(const std::vector<GURL>& urls, | |
67 const MultipleOfflinePageItemResult& pages); | |
68 | |
69 std::unique_ptr<Delegate> delegate_; | |
70 content::BrowserContext* browser_context_; | |
71 ntp_snippets::CategoryStatus category_status_ = | |
72 ntp_snippets::CategoryStatus::INITIALIZING; | |
73 ntp_snippets::Category category_; | |
74 | |
75 // This must be the last member for happy destruction order. | |
76 base::WeakPtrFactory<OfflinePageSuggestionsObserver> weak_ptr_factory_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsObserver); | |
79 }; | |
80 | |
81 } // namespace offline_pages | |
82 | |
83 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_OBSERVE R_H_ | |
OLD | NEW |