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

Unified Diff: chrome/browser/android/offline_pages/offline_page_suggestions_observer.h

Issue 2811813002: [Offline Pages] Set up the initial prefetching service. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
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..fe3e31f5f761e4311bc174a1db672dd0bc5a2369
--- /dev/null
+++ b/chrome/browser/android/offline_pages/offline_page_suggestions_observer.h
@@ -0,0 +1,83 @@
+// 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_
+
+#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/offline_page_types.h"
+
+namespace content {
+class BrowserContext;
+} // namespace content
+
+namespace ntp_snippets {
+class Category;
+}
+
+namespace offline_pages {
+
+class OfflinePageModel;
+
+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.
+ : public ntp_snippets::ContentSuggestionsService::Observer,
+ base::SupportsUserData::Data {
+ public:
+ // Abstract delegate for easy testing.
+ class Delegate {
+ public:
+ virtual std::vector<GURL> GetSuggestionURLs() = 0;
+ virtual void GetPagesWithURLs(
+ const std::vector<GURL>& suggestion_urls,
+ const MultipleOfflinePageItemCallback& callback) = 0;
+ virtual ~Delegate() = default;
+ };
+
+ // This API creates a new OfflinePageSuggestionsObserver 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,
+ offline_pages::OfflinePageModel* offline_page_model,
+ ntp_snippets::ContentSuggestionsService* service);
+ 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.
+ std::unique_ptr<Delegate> delegate,
+ const ntp_snippets::Category& category);
+ ~OfflinePageSuggestionsObserver() override;
+
+ // ContentSuggestionsService::Observer overrides
+ 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:
+ void GotPagesMatchingSuggestions(const std::vector<GURL>& urls,
+ const MultipleOfflinePageItemResult& pages);
+
+ std::unique_ptr<Delegate> delegate_;
+ content::BrowserContext* browser_context_;
+ ntp_snippets::CategoryStatus category_status_ =
+ ntp_snippets::CategoryStatus::INITIALIZING;
+ ntp_snippets::Category category_;
+
+ // This must be the last member for happy destruction order.
+ base::WeakPtrFactory<OfflinePageSuggestionsObserver> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsObserver);
+};
+
+} // namespace offline_pages
+
+#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698