Index: chrome/browser/android/offline_pages/offline_page_suggestions_observer.h |
diff --git a/chrome/browser/android/offline_pages/offline_page_suggestions_observer.h b/chrome/browser/android/offline_pages/offline_page_suggestions_observer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..be77ec8590a0067ba8777aac11e9196dcf097e7f |
--- /dev/null |
+++ b/chrome/browser/android/offline_pages/offline_page_suggestions_observer.h |
@@ -0,0 +1,78 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_OBSERVER_H_ |
+#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.
|
+ |
+#include <memory> |
+ |
+#include "base/callback.h" |
+#include "base/memory/weak_ptr.h" |
+#include "components/ntp_snippets/content_suggestions_service.h" |
+#include "components/offline_pages/core/prefetch/prefetch_service.h" |
+ |
+namespace content { |
+class BrowserContext; |
+} // namespace content |
+ |
+namespace ntp_snippets { |
+class Category; |
+} |
+ |
+namespace offline_pages { |
+ |
+// Observes the ContentSuggestionsService, listening for new suggestions of a |
+// single category (initially ARTICLES). When those suggestions arrive, it |
+// then forwards them to the Prefetch Service. |
+class SuggestionsObserver |
+ : public ntp_snippets::ContentSuggestionsService::Observer, |
+ base::SupportsUserData::Data { |
+ public: |
+ // Abstract delegate for easy dependency injection in testing. |
+ class Delegate { |
+ public: |
+ virtual std::vector<GURL> GetSuggestionURLs( |
+ const ntp_snippets::Category& category) = 0; |
+ virtual PrefetchService* GetPrefetchService( |
+ content::BrowserContext* context) = 0; |
+ virtual ~Delegate() = default; |
+ }; |
+ |
+ // This API creates a new SuggestionsObserver and adds it as an |
+ // observer to the ContentSuggestionsService provided. Its lifetime is |
+ // self-managed, and it deletes itself upon receiving the |
+ // |ContentSuggestionsServiceShutdown| signal using an asynchronous |
+ // |DeleteSoon|. |
+ static void ObserveContentSuggestionsService( |
+ content::BrowserContext* browser_context, |
+ ntp_snippets::ContentSuggestionsService* service); |
+ |
+ SuggestionsObserver(content::BrowserContext* browser_context, |
+ std::unique_ptr<Delegate> delegate, |
+ const ntp_snippets::Category& category); |
+ ~SuggestionsObserver() override; |
+ |
+ // ContentSuggestionsService::Observer overrides |
jianli
2017/04/11 22:39:55
nit: end with ":"
dewittj
2017/04/12 00:22:48
Done.
|
+ void OnNewSuggestions(ntp_snippets::Category category) override; |
+ void OnCategoryStatusChanged( |
+ ntp_snippets::Category category, |
+ ntp_snippets::CategoryStatus new_status) override; |
+ void OnSuggestionInvalidated( |
+ const ntp_snippets::ContentSuggestion::ID& suggestion_id) override; |
+ void OnFullRefreshRequired() override; |
+ void ContentSuggestionsServiceShutdown() override; |
+ |
+ private: |
+ std::unique_ptr<Delegate> delegate_; |
+ content::BrowserContext* browser_context_; |
+ ntp_snippets::CategoryStatus category_status_ = |
+ ntp_snippets::CategoryStatus::INITIALIZING; |
+ ntp_snippets::Category category_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SuggestionsObserver); |
+}; |
+ |
+} // namespace offline_pages |
+ |
+#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_OBSERVER_H_ |