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

Unified Diff: components/ntp_snippets/ntp_snippets_fetcher.h

Issue 1922083004: Allow fetching personalized snippets from ChromeReader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After code review #2 Created 4 years, 7 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: components/ntp_snippets/ntp_snippets_fetcher.h
diff --git a/components/ntp_snippets/ntp_snippets_fetcher.h b/components/ntp_snippets/ntp_snippets_fetcher.h
index 86c7685b6739bd1fc36b64a4369d9d32e9ddcdde..40c61b95b88b16945337910e95e2d20c3d7cc97a 100644
--- a/components/ntp_snippets/ntp_snippets_fetcher.h
+++ b/components/ntp_snippets/ntp_snippets_fetcher.h
@@ -12,13 +12,21 @@
#include "base/callback.h"
#include "base/callback_list.h"
#include "base/memory/weak_ptr.h"
+#include "google_apis/gaia/oauth2_token_service.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context_getter.h"
+class SigninManagerBase;
+namespace net {
+class HttpRequestHeaders;
+} // namespace net
+
namespace ntp_snippets {
// Fetches snippet data for the NTP from the server
-class NTPSnippetsFetcher : public net::URLFetcherDelegate {
+class NTPSnippetsFetcher : public OAuth2TokenService::Consumer,
+ public OAuth2TokenService::Observer,
+ public net::URLFetcherDelegate {
public:
// If problems occur (explained in |status_message|), |snippets_json| is
// empty; otherwise, |status_message| is empty.
@@ -29,6 +37,8 @@ class NTPSnippetsFetcher : public net::URLFetcherDelegate {
base::CallbackList<void(const std::string&, const std::string&)>;
NTPSnippetsFetcher(
+ SigninManagerBase* signin_manager,
+ OAuth2TokenService* oauth2_token_service,
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
bool is_stable_channel);
~NTPSnippetsFetcher() override;
@@ -44,24 +54,70 @@ class NTPSnippetsFetcher : public net::URLFetcherDelegate {
// If an ongoing fetch exists, it will be cancelled and a new one started,
// without triggering additional callbacks (i.e. not noticeable by
// subscribers).
- void FetchSnippets(const std::set<std::string>& hosts, int count);
+ void FetchSnippets(const std::set<std::string>& hosts,
+ const std::string& language_code,
+ int count);
private:
+ enum Variant {
+ kRestrictedPersonalized,
+ kRestricted,
+ kPersonalized
+ };
+
+ void FetchSnippetsImpl(const GURL& url,
+ const std::string& auth_header,
+ const std::string& request);
+ std::string GetHostsRestricts() const;
+ bool UseAuthentication();
+ void FetchSnippetsNonAuthenticated();
+ void FetchSnippetsAuthenticated(const std::string& account_id,
+ const std::string& oauth_access_token);
+ void StartTokenRequest();
+
+ // OAuth2TokenService::Consumer overrides:
+ void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) override;
+ void OnGetTokenFailure(const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) override;
+
+ // OAuth2TokenService::Observer overrides:
+ void OnRefreshTokenAvailable(const std::string& account_id) override;
+
// URLFetcherDelegate implementation.
void OnURLFetchComplete(const net::URLFetcher* source) override;
// Holds the URL request context.
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
+ // Hosts to restrict the snippets to.
+ std::set<std::string> hosts_;
+
+ // Count of snippets to fetch.
+ int count_;
+
+ // Language code to restrict to for personalized results.
+ std::string locale_;
+
// The fetcher for downloading the snippets.
std::unique_ptr<net::URLFetcher> url_fetcher_;
// The callbacks to notify when new snippets get fetched.
SnippetsAvailableCallbackList callback_list_;
+ // Authorization for signed-in users
+ SigninManagerBase* signin_manager_;
+ OAuth2TokenService* token_service_;
+ std::unique_ptr<OAuth2TokenService::Request> oauth_request_;
+ bool waiting_for_refresh_token_;
+
// Flag for picking the right (stable/non-stable) API key for Chrome Reader
bool is_stable_channel_;
+ // The variant of the fetching to use.
+ Variant variant_;
+
DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);
};
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698