Commit da59d447 authored by Carlos Knippschild's avatar Carlos Knippschild Committed by Commit Bot

Adds new API between Offline Prefetch and the suggestions service.

Introduces the API to be used for the article suggestions provider to be
implemented by the new and upcoming Feed implementation.

Bug: 841516
Change-Id: I83181cc2f90a26a98bab2cd3c8a8717a6fac596b
Reviewed-on: https://chromium-review.googlesource.com/1176397
Commit-Queue: Carlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Reviewed-by: default avatarDan H <harringtond@google.com>
Cr-Commit-Position: refs/heads/master@{#583830}
parent 5868b6d9
...@@ -88,6 +88,7 @@ static_library("prefetch") { ...@@ -88,6 +88,7 @@ static_library("prefetch") {
"store/prefetch_store_utils.h", "store/prefetch_store_utils.h",
"suggested_articles_observer.cc", "suggested_articles_observer.cc",
"suggested_articles_observer.h", "suggested_articles_observer.h",
"suggestions_provider.h",
"thumbnail_fetcher.h", "thumbnail_fetcher.h",
] ]
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
class GURL;
namespace ntp_snippets { namespace ntp_snippets {
class ContentSuggestionsService; class ContentSuggestionsService;
} }
...@@ -24,26 +26,57 @@ class PrefetchImporter; ...@@ -24,26 +26,57 @@ class PrefetchImporter;
class PrefetchNetworkRequestFactory; class PrefetchNetworkRequestFactory;
class PrefetchStore; class PrefetchStore;
class SuggestedArticlesObserver; class SuggestedArticlesObserver;
class SuggestionsProvider;
class ThumbnailFetcher; class ThumbnailFetcher;
// TODO(https://crbug.com/874293): This class is midway through a refactoring so
// it might look as it offers an inconsistent API.
//
// External doc (will remain here):
// Main entry point for the Offline Prefetch feature for external users.
//
// Internal doc (to be eventually moved out of here):
// Main class and entry point for the Offline Pages Prefetching feature, that // Main class and entry point for the Offline Pages Prefetching feature, that
// controls the lifetime of all major subcomponents of the prefetching system. // controls the lifetime of all major subcomponents of the prefetching system.
// Setup and creation of concrete instances must be lightweight. All heavy work
// will be delayed to be done on-demand only.
class PrefetchService : public KeyedService { class PrefetchService : public KeyedService {
public: public:
~PrefetchService() override = default; ~PrefetchService() override = default;
// Externally used functions. They will remain part of this class.
// Sets the SuggestionsProvider instance. Should be called at startup time and
// before any other suggestion related calls are made.
virtual void SetContentSuggestionsService( virtual void SetContentSuggestionsService(
ntp_snippets::ContentSuggestionsService* content_suggestions) {} ntp_snippets::ContentSuggestionsService* content_suggestions) = 0;
// Sets the SuggestionsProvider instance. Should be called at startup time and
// before any other suggestion related calls are made.
virtual void SetSuggestionProvider(
SuggestionsProvider* suggestions_provider) = 0;
// Notifies that the list of suggestions has changed and contains fresh
// content. This should be called any time new suggestions are fetched.
virtual void NewSuggestionsAvailable() = 0;
// Signals that a specific suggestion was removed due to user action (i.e.
// user swiped out the item). This will cause the full removal of the
// suggestion from the Prefetching pipeline and/or the Offline Pages database.
virtual void RemoveSuggestion(GURL url) = 0;
// Subobjects that are created and owned by this service. Creation should be virtual PrefetchGCMHandler* GetPrefetchGCMHandler() = 0;
// lightweight, all heavy work must be done on-demand only.
// Internal usage only functions. They will eventually be moved out of this
// class.
// Sub-components that are created and owned by this service.
// The service manages lifetime, hookup and initialization of Prefetch // The service manages lifetime, hookup and initialization of Prefetch
// system that consists of multiple specialized objects, all vended by this // system that consists of multiple specialized objects, all vended by this
// service. // class.
virtual OfflineEventLogger* GetLogger() = 0; virtual OfflineEventLogger* GetLogger() = 0;
virtual OfflineMetricsCollector* GetOfflineMetricsCollector() = 0; virtual OfflineMetricsCollector* GetOfflineMetricsCollector() = 0;
virtual PrefetchDispatcher* GetPrefetchDispatcher() = 0; virtual PrefetchDispatcher* GetPrefetchDispatcher() = 0;
virtual PrefetchGCMHandler* GetPrefetchGCMHandler() = 0;
virtual PrefetchNetworkRequestFactory* GetPrefetchNetworkRequestFactory() = 0; virtual PrefetchNetworkRequestFactory* GetPrefetchNetworkRequestFactory() = 0;
virtual PrefetchDownloader* GetPrefetchDownloader() = 0; virtual PrefetchDownloader* GetPrefetchDownloader() = 0;
virtual PrefetchStore* GetPrefetchStore() = 0; virtual PrefetchStore* GetPrefetchStore() = 0;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h"
#include "components/offline_pages/core/client_id.h" #include "components/offline_pages/core/client_id.h"
#include "components/offline_pages/core/client_namespace_constants.h" #include "components/offline_pages/core/client_namespace_constants.h"
#include "components/offline_pages/core/prefetch/offline_metrics_collector.h" #include "components/offline_pages/core/prefetch/offline_metrics_collector.h"
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
#include "components/offline_pages/core/prefetch/prefetch_network_request_factory.h" #include "components/offline_pages/core/prefetch/prefetch_network_request_factory.h"
#include "components/offline_pages/core/prefetch/store/prefetch_store.h" #include "components/offline_pages/core/prefetch/store/prefetch_store.h"
#include "components/offline_pages/core/prefetch/suggested_articles_observer.h" #include "components/offline_pages/core/prefetch/suggested_articles_observer.h"
#include "components/offline_pages/core/prefetch/suggestions_provider.h"
#include "components/offline_pages/core/prefetch/thumbnail_fetcher.h" #include "components/offline_pages/core/prefetch/thumbnail_fetcher.h"
namespace offline_pages { namespace offline_pages {
...@@ -69,6 +71,22 @@ void PrefetchServiceImpl::SetContentSuggestionsService( ...@@ -69,6 +71,22 @@ void PrefetchServiceImpl::SetContentSuggestionsService(
thumbnail_fetcher_->SetContentSuggestionsService(content_suggestions); thumbnail_fetcher_->SetContentSuggestionsService(content_suggestions);
} }
void PrefetchServiceImpl::SetSuggestionProvider(
SuggestionsProvider* suggestions_provider) {
// TODO(https://crbug.com/841516): to be implemented soon.
NOTIMPLEMENTED();
}
void PrefetchServiceImpl::NewSuggestionsAvailable() {
// TODO(https://crbug.com/841516): to be implemented soon.
NOTIMPLEMENTED();
}
void PrefetchServiceImpl::RemoveSuggestion(GURL url) {
// TODO(https://crbug.com/841516): to be implemented soon.
NOTIMPLEMENTED();
}
OfflineMetricsCollector* PrefetchServiceImpl::GetOfflineMetricsCollector() { OfflineMetricsCollector* PrefetchServiceImpl::GetOfflineMetricsCollector() {
return offline_metrics_collector_.get(); return offline_metrics_collector_.get();
} }
......
...@@ -33,13 +33,18 @@ class PrefetchServiceImpl : public PrefetchService { ...@@ -33,13 +33,18 @@ class PrefetchServiceImpl : public PrefetchService {
~PrefetchServiceImpl() override; ~PrefetchServiceImpl() override;
// PrefetchService implementation:
// Externally used functions.
void SetContentSuggestionsService( void SetContentSuggestionsService(
ntp_snippets::ContentSuggestionsService* content_suggestions) override; ntp_snippets::ContentSuggestionsService* content_suggestions) override;
void SetSuggestionProvider(
// PrefetchService implementation: SuggestionsProvider* suggestions_provider) override;
void NewSuggestionsAvailable() override;
void RemoveSuggestion(GURL url) override;
PrefetchGCMHandler* GetPrefetchGCMHandler() override;
// Internal usage only functions.
OfflineMetricsCollector* GetOfflineMetricsCollector() override; OfflineMetricsCollector* GetOfflineMetricsCollector() override;
PrefetchDispatcher* GetPrefetchDispatcher() override; PrefetchDispatcher* GetPrefetchDispatcher() override;
PrefetchGCMHandler* GetPrefetchGCMHandler() override;
PrefetchNetworkRequestFactory* GetPrefetchNetworkRequestFactory() override; PrefetchNetworkRequestFactory* GetPrefetchNetworkRequestFactory() override;
OfflinePageModel* GetOfflinePageModel() override; OfflinePageModel* GetOfflinePageModel() override;
PrefetchStore* GetPrefetchStore() override; PrefetchStore* GetPrefetchStore() override;
......
// Copyright 2018 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 COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_SUGGESTIONS_PROVIDER_H_
#define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_SUGGESTIONS_PROVIDER_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "url/gurl.h"
namespace offline_pages {
// Data struct for a suggestion of an article to be prefetched.
struct PrefetchSuggestion {
PrefetchSuggestion();
~PrefetchSuggestion();
// The URL of the suggested article. It acts as a unique key for the
// suggestion and may be de-duplicated if the same URL is suggested more than
// once.
GURL article_url;
// The title of the suggested article.
std::string article_title;
// The publisher name/web site the article is attributed to.
std::string article_attribution;
// A snippet of the article's contents.
std::string article_snippet;
// The URL to the thumbnail image representing the suggested article.
GURL thumbnail_url;
// The URL to the favicon image of the article's hosting web site.
GURL favicon_url;
};
// Interface implemented by the suggestions provider.
class SuggestionsProvider {
using SuggestionCallback =
base::OnceCallback<void(std::vector<PrefetchSuggestion>)>;
// Request the list of current article suggestions, to be returned via the
// provided callback in descending priority order. Freshest articles are
// prefetched first based both on the order they are listed and on the
// timestamp at which the suggestion was last seen.
virtual void GetCurrentArticleSuggestions(
SuggestionCallback suggestions_callback) = 0;
// Notifies that a non-empty list of prefetched articles was presented to the
// user.
virtual void ReportArticleListViewed() = 0;
// Notifies that the a specific prefetched article was presented to the user.
// This will always provide the original suggested URL, not the potentially
// different downloaded one in case redirects take place during archive
// generation.
virtual void ReportArticleViewed(GURL article_url) = 0;
};
} // namespace offline_pages
#endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_SUGGESTIONS_PROVIDER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment