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

Side by Side Diff: components/ntp_snippets/ntp_snippets_fetcher.h

Issue 1974483002: Allow getting _only_ personalized snippets for NTP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After code review #3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 void(const std::string&, const SuccessCallback&, const ErrorCallback&)>; 45 void(const std::string&, const SuccessCallback&, const ErrorCallback&)>;
46 46
47 using OptionalSnippets = base::Optional<NTPSnippet::PtrVector>; 47 using OptionalSnippets = base::Optional<NTPSnippet::PtrVector>;
48 // |snippets| contains parsed snippets if a fetch succeeded. If problems 48 // |snippets| contains parsed snippets if a fetch succeeded. If problems
49 // occur, |snippets| contains no value (no actual vector in base::Optional). 49 // occur, |snippets| contains no value (no actual vector in base::Optional).
50 // Error details can be retrieved using last_status(). 50 // Error details can be retrieved using last_status().
51 using SnippetsAvailableCallback = 51 using SnippetsAvailableCallback =
52 base::Callback<void(OptionalSnippets snippets)>; 52 base::Callback<void(OptionalSnippets snippets)>;
53 53
54 // Enumeration listing all possible outcomes for fetch attempts. Used for UMA 54 // Enumeration listing all possible outcomes for fetch attempts. Used for UMA
55 // histograms, so do not change existing values. 55 // histograms, so do not change existing values. Insert new value at the end,
Marc Treib 2016/05/12 13:57:59 nit: values, plural.
56 // and update the histogram definition.
56 enum class FetchResult { 57 enum class FetchResult {
57 SUCCESS, 58 SUCCESS,
58 EMPTY_HOSTS, 59 EMPTY_HOSTS,
59 URL_REQUEST_STATUS_ERROR, 60 URL_REQUEST_STATUS_ERROR,
60 HTTP_ERROR, 61 HTTP_ERROR,
61 JSON_PARSE_ERROR, 62 JSON_PARSE_ERROR,
62 INVALID_SNIPPET_CONTENT_ERROR, 63 INVALID_SNIPPET_CONTENT_ERROR,
64 OAUTH_TOKEN_ERROR,
63 RESULT_MAX 65 RESULT_MAX
64 }; 66 };
65 67
66 NTPSnippetsFetcher( 68 NTPSnippetsFetcher(
67 SigninManagerBase* signin_manager, 69 SigninManagerBase* signin_manager,
68 OAuth2TokenService* oauth2_token_service, 70 OAuth2TokenService* oauth2_token_service,
69 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, 71 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
70 const ParseJSONCallback& parse_json_callback, 72 const ParseJSONCallback& parse_json_callback,
71 bool is_stable_channel); 73 bool is_stable_channel);
72 ~NTPSnippetsFetcher() override; 74 ~NTPSnippetsFetcher() override;
(...skipping 19 matching lines...) Expand all
92 const std::string& last_json() const { 94 const std::string& last_json() const {
93 return last_fetch_json_; 95 return last_fetch_json_;
94 } 96 }
95 97
96 // Overrides internal clock for testing purposes. 98 // Overrides internal clock for testing purposes.
97 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { 99 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) {
98 tick_clock_ = std::move(tick_clock); 100 tick_clock_ = std::move(tick_clock);
99 } 101 }
100 102
101 private: 103 private:
102 enum class Variant { kRestrictedPersonalized, kRestricted, kPersonalized }; 104 enum class Personalization { kPersonal, kNonPersonal, kBoth };
103 105
104 void FetchSnippetsImpl(const GURL& url, 106 void FetchSnippetsImpl(const GURL& url,
105 const std::string& auth_header, 107 const std::string& auth_header,
106 const std::string& request); 108 const std::string& request);
107 std::string GetHostRestricts() const; 109 std::string GetHostRestricts() const;
108 bool UseHostRestriction() const; 110 bool UseHostRestriction() const;
109 bool UseAuthentication() const; 111 bool UseAuthentication() const;
110 void FetchSnippetsNonAuthenticated(); 112 void FetchSnippetsNonAuthenticated();
111 void FetchSnippetsAuthenticated(const std::string& account_id, 113 void FetchSnippetsAuthenticated(const std::string& account_id,
112 const std::string& oauth_access_token); 114 const std::string& oauth_access_token);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 158
157 // The fetcher for downloading the snippets. 159 // The fetcher for downloading the snippets.
158 std::unique_ptr<net::URLFetcher> url_fetcher_; 160 std::unique_ptr<net::URLFetcher> url_fetcher_;
159 161
160 // The callback to notify when new snippets get fetched. 162 // The callback to notify when new snippets get fetched.
161 SnippetsAvailableCallback snippets_available_callback_; 163 SnippetsAvailableCallback snippets_available_callback_;
162 164
163 // Flag for picking the right (stable/non-stable) API key for Chrome Reader. 165 // Flag for picking the right (stable/non-stable) API key for Chrome Reader.
164 bool is_stable_channel_; 166 bool is_stable_channel_;
165 167
166 // The variant of the fetching to use. 168 // The variant of the fetching to use, loaded from variation parameters.
167 Variant variant_; 169 Personalization personalization_;
170 // Should we apply host restriction? It is loaded from variation parameters.
171 bool use_host_restriction_;
168 172
169 // Allow for an injectable tick clock for testing. 173 // Allow for an injectable tick clock for testing.
170 std::unique_ptr<base::TickClock> tick_clock_; 174 std::unique_ptr<base::TickClock> tick_clock_;
171 175
172 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; 176 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
173 177
174 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); 178 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);
175 }; 179 };
176 } // namespace ntp_snippets 180 } // namespace ntp_snippets
177 181
178 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ 182 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_fetcher.cc » ('j') | components/ntp_snippets/ntp_snippets_fetcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698