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

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: Minor fixes 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 aa374b7078992485b5863cf19f15126c04143cca..2b83ecdfddfd8ceba98009258bb581f508c2c04e 100644
--- a/components/ntp_snippets/ntp_snippets_fetcher.h
+++ b/components/ntp_snippets/ntp_snippets_fetcher.h
@@ -11,19 +11,29 @@
#include <vector>
#include "base/callback.h"
+#include "base/callback_list.h"
Marc Treib 2016/05/09 12:33:34 Not needed I think?
jkrcal 2016/05/09 15:30:13 Done.
#include "base/memory/weak_ptr.h"
#include "components/ntp_snippets/ntp_snippet.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 base {
class Value;
-}
+} // namespace base
+
+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:
// Callbacks for JSON parsing, needed because the parsing is platform-
// dependent.
@@ -40,6 +50,8 @@ class NTPSnippetsFetcher : public net::URLFetcherDelegate {
const std::string& status_message)>;
NTPSnippetsFetcher(
+ SigninManagerBase* signin_manager,
+ OAuth2TokenService* oauth2_token_service,
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
const ParseJSONCallback& parse_json_callback,
bool is_stable_channel);
@@ -55,7 +67,9 @@ class NTPSnippetsFetcher : public net::URLFetcherDelegate {
// If an ongoing fetch exists, it will be cancelled and a new one started,
// without triggering an additional callback (i.e. not noticeable by
// subscriber of SetCallback()).
- void FetchSnippetsFromHosts(const std::set<std::string>& hosts, int count);
+ void FetchSnippetsFromHosts(const std::set<std::string>& hosts,
+ const std::string& language_code,
+ int count);
// Returns the last json fetched from the server.
const std::string& last_json() const {
@@ -63,18 +77,59 @@ class NTPSnippetsFetcher : public net::URLFetcherDelegate {
}
private:
+ enum Variant {
Marc Treib 2016/05/09 12:33:34 optional: Make this an enum class? Then it's membe
jkrcal 2016/05/09 15:30:13 Done.
+ kRestrictedPersonalized,
+ kRestricted,
+ kPersonalized
+ };
+
+ void FetchSnippetsImpl(const GURL& url,
+ const std::string& auth_header,
+ const std::string& request);
+ std::string GetHostRestricts() 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;
void OnJsonParsed(std::unique_ptr<base::Value> parsed);
void OnJsonError(const std::string& error);
+ // Authorization for signed-in users
Marc Treib 2016/05/09 12:33:34 nit: Period after comment
jkrcal 2016/05/09 15:30:13 Done.
+ SigninManagerBase* signin_manager_;
+ OAuth2TokenService* token_service_;
+ std::unique_ptr<OAuth2TokenService::Request> oauth_request_;
+ bool waiting_for_refresh_token_;
+
// Holds the URL request context.
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
const ParseJSONCallback parse_json_callback_;
std::string last_fetch_json_;
+ // Hosts to restrict the snippets to.
+ std::set<std::string> hosts_;
+
+ // Count of snippets to fetch.
+ int count_;
Marc Treib 2016/05/09 12:33:33 count_to_fetch_? Just count_ seems ambiguous.
jkrcal 2016/05/09 15:30:13 Done.
+
+ // Language code to restrict to for personalized results.
+ std::string locale_;
+
// The fetcher for downloading the snippets.
std::unique_ptr<net::URLFetcher> url_fetcher_;
@@ -84,6 +139,9 @@ class NTPSnippetsFetcher : public net::URLFetcherDelegate {
// 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_;
+
base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);

Powered by Google App Engine
This is Rietveld 408576698