| OLD | NEW |
| 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_REMOTE_NTP_SNIPPETS_FETCHER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 // Returns the URL endpoint used by the fetcher. | 167 // Returns the URL endpoint used by the fetcher. |
| 168 const GURL& fetch_url() const { return fetch_url_; } | 168 const GURL& fetch_url() const { return fetch_url_; } |
| 169 | 169 |
| 170 // Overrides internal clock for testing purposes. | 170 // Overrides internal clock for testing purposes. |
| 171 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { | 171 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { |
| 172 tick_clock_ = std::move(tick_clock); | 172 tick_clock_ = std::move(tick_clock); |
| 173 } | 173 } |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestAuthenticated); | 176 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 177 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestUnauthenticated); | 177 BuildRequestAuthenticated); |
| 178 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestExcludedIds); | 178 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 179 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestNoUserClass); | 179 BuildRequestUnauthenticated); |
| 180 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, | 180 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 181 BuildRequestExcludedIds); |
| 182 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 183 BuildRequestNoUserClass); |
| 184 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 181 BuildRequestWithTwoLanguages); | 185 BuildRequestWithTwoLanguages); |
| 182 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, | 186 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 183 BuildRequestWithUILanguageOnly); | 187 BuildRequestWithUILanguageOnly); |
| 184 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, | 188 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 185 BuildRequestWithOtherLanguageOnly); | 189 BuildRequestWithOtherLanguageOnly); |
| 186 friend class NTPSnippetsFetcherTest; | 190 friend class ChromeReaderSnippetsFetcherTest; |
| 187 | 191 |
| 188 enum FetchAPI { | 192 enum FetchAPI { |
| 189 CHROME_READER_API, | 193 CHROME_READER_API, |
| 190 CHROME_CONTENT_SUGGESTIONS_API, | 194 CHROME_CONTENT_SUGGESTIONS_API, |
| 191 }; | 195 }; |
| 192 | 196 |
| 193 class JsonRequest; | 197 class JsonRequest; |
| 194 | 198 |
| 195 // A class that builds authenticated and non-authenticated JsonRequests. | 199 // A class that builds authenticated and non-authenticated JsonRequests. |
| 196 // This class is only in the header for testing. | 200 // This class is only in the header for testing. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // publicly. | 232 // publicly. |
| 229 // TODO(fhorschig): Remove these when moving the RequestBuilder to | 233 // TODO(fhorschig): Remove these when moving the RequestBuilder to |
| 230 // snippets::internal and trigger the request to intercept the request. | 234 // snippets::internal and trigger the request to intercept the request. |
| 231 std::string PreviewRequestBodyForTesting() { return BuildBody(); } | 235 std::string PreviewRequestBodyForTesting() { return BuildBody(); } |
| 232 std::string PreviewRequestHeadersForTesting() { return BuildHeaders(); } | 236 std::string PreviewRequestHeadersForTesting() { return BuildHeaders(); } |
| 233 RequestBuilder& SetUserClassForTesting(const std::string& user_class) { | 237 RequestBuilder& SetUserClassForTesting(const std::string& user_class) { |
| 234 user_class_ = user_class; | 238 user_class_ = user_class; |
| 235 return *this; | 239 return *this; |
| 236 } | 240 } |
| 237 | 241 |
| 238 protected: | |
| 239 // TODO(fhorschig): As soon as crbug.com/crbug.com/645447 is resolved, | |
| 240 // make these an implementation detail in the body and remove the mock. | |
| 241 virtual bool IsSendingTopLanguagesEnabled() const; | |
| 242 virtual bool IsSendingUserClassEnabled() const; | |
| 243 | |
| 244 private: | 242 private: |
| 245 std::string BuildHeaders() const; | 243 std::string BuildHeaders() const; |
| 246 std::string BuildBody() const; | 244 std::string BuildBody() const; |
| 247 std::unique_ptr<net::URLFetcher> BuildURLFetcher( | 245 std::unique_ptr<net::URLFetcher> BuildURLFetcher( |
| 248 net::URLFetcherDelegate* request, | 246 net::URLFetcherDelegate* request, |
| 249 const std::string& headers, | 247 const std::string& headers, |
| 250 const std::string& body) const; | 248 const std::string& body) const; |
| 251 | 249 |
| 252 bool ReturnOnlyPersonalizedResults() const { | 250 bool ReturnOnlyPersonalizedResults() const { |
| 253 return !obfuscated_gaia_id_.empty() && | 251 return !obfuscated_gaia_id_.empty() && |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 std::string last_status_; | 360 std::string last_status_; |
| 363 std::string last_fetch_json_; | 361 std::string last_fetch_json_; |
| 364 | 362 |
| 365 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 363 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 366 | 364 |
| 367 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 365 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 368 }; | 366 }; |
| 369 } // namespace ntp_snippets | 367 } // namespace ntp_snippets |
| 370 | 368 |
| 371 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ | 369 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |