Chromium Code Reviews| 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_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> |
| 11 #include <utility> | |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/callback.h" | 14 #include "base/callback.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/optional.h" | 16 #include "base/optional.h" |
| 16 #include "base/time/tick_clock.h" | 17 #include "base/time/tick_clock.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "components/ntp_snippets/ntp_snippet.h" | 19 #include "components/ntp_snippets/ntp_snippet.h" |
| 20 #include "components/ntp_snippets/request_throttler.h" | |
| 19 #include "google_apis/gaia/oauth2_token_service.h" | 21 #include "google_apis/gaia/oauth2_token_service.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| 22 | 24 |
| 25 class PrefService; | |
| 23 class SigninManagerBase; | 26 class SigninManagerBase; |
| 24 | 27 |
| 25 namespace base { | 28 namespace base { |
| 26 class Value; | 29 class Value; |
| 27 } // namespace base | 30 } // namespace base |
| 28 | 31 |
| 29 namespace net { | 32 namespace net { |
| 30 class HttpRequestHeaders; | 33 class HttpRequestHeaders; |
| 31 } // namespace net | 34 } // namespace net |
| 32 | 35 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 enum class Personalization { | 72 enum class Personalization { |
| 70 kPersonal, | 73 kPersonal, |
| 71 kNonPersonal, | 74 kNonPersonal, |
| 72 kBoth | 75 kBoth |
| 73 }; | 76 }; |
| 74 | 77 |
| 75 NTPSnippetsFetcher( | 78 NTPSnippetsFetcher( |
| 76 SigninManagerBase* signin_manager, | 79 SigninManagerBase* signin_manager, |
| 77 OAuth2TokenService* oauth2_token_service, | 80 OAuth2TokenService* oauth2_token_service, |
| 78 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 81 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 82 PrefService* pref_service, | |
| 79 const ParseJSONCallback& parse_json_callback, | 83 const ParseJSONCallback& parse_json_callback, |
| 80 bool is_stable_channel); | 84 bool is_stable_channel); |
| 81 ~NTPSnippetsFetcher() override; | 85 ~NTPSnippetsFetcher() override; |
| 82 | 86 |
| 83 // Set a callback that is called when a new set of snippets are downloaded, | 87 // Set a callback that is called when a new set of snippets are downloaded, |
| 84 // overriding any previously set callback. | 88 // overriding any previously set callback. |
| 85 void SetCallback(const SnippetsAvailableCallback& callback); | 89 void SetCallback(const SnippetsAvailableCallback& callback); |
| 86 | 90 |
| 87 // Fetches snippets from the server. |hosts| restricts the results to a set of | 91 // Fetches snippets from the server. |hosts| restricts the results to a set of |
| 88 // hosts, e.g. "www.google.com". An empty host set produces an error. | 92 // hosts, e.g. "www.google.com". An empty host set produces an error. |
| 89 // | 93 // |
| 90 // If an ongoing fetch exists, it will be cancelled and a new one started, | 94 // If an ongoing fetch exists, it will be cancelled and a new one started, |
| 91 // without triggering an additional callback (i.e. not noticeable by | 95 // without triggering an additional callback (i.e. not noticeable by |
| 92 // subscriber of SetCallback()). | 96 // subscriber of SetCallback()). |
| 97 // | |
| 98 // Fetches snippets only if the daily quota not exceeded, unless |force| is | |
|
Marc Treib
2016/07/22 13:52:52
force_request (or rename the actual param below)
Bernhard Bauer
2016/07/22 13:59:14
Nit: The name of the parameter is |force_request|;
jkrcal
2016/07/25 10:05:38
Done.
| |
| 99 // set to true. Use force only for user-initiated fetches. | |
| 93 void FetchSnippetsFromHosts(const std::set<std::string>& hosts, | 100 void FetchSnippetsFromHosts(const std::set<std::string>& hosts, |
| 94 const std::string& language_code, | 101 const std::string& language_code, |
| 95 int count); | 102 int count, |
| 103 bool force_request); | |
| 96 | 104 |
| 97 // Debug string representing the status/result of the last fetch attempt. | 105 // Debug string representing the status/result of the last fetch attempt. |
| 98 const std::string& last_status() const { return last_status_; } | 106 const std::string& last_status() const { return last_status_; } |
| 99 | 107 |
| 100 // Returns the last JSON fetched from the server. | 108 // Returns the last JSON fetched from the server. |
| 101 const std::string& last_json() const { | 109 const std::string& last_json() const { |
| 102 return last_fetch_json_; | 110 return last_fetch_json_; |
| 103 } | 111 } |
| 104 | 112 |
| 105 // Returns the personalization setting of the fetcher. | 113 // Returns the personalization setting of the fetcher. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 bool is_stable_channel_; | 218 bool is_stable_channel_; |
| 211 | 219 |
| 212 // The variant of the fetching to use, loaded from variation parameters. | 220 // The variant of the fetching to use, loaded from variation parameters. |
| 213 Personalization personalization_; | 221 Personalization personalization_; |
| 214 // Should we apply host restriction? It is loaded from variation parameters. | 222 // Should we apply host restriction? It is loaded from variation parameters. |
| 215 bool use_host_restriction_; | 223 bool use_host_restriction_; |
| 216 | 224 |
| 217 // Allow for an injectable tick clock for testing. | 225 // Allow for an injectable tick clock for testing. |
| 218 std::unique_ptr<base::TickClock> tick_clock_; | 226 std::unique_ptr<base::TickClock> tick_clock_; |
| 219 | 227 |
| 228 // Request throttler for limiting requests. | |
| 229 RequestThrottler request_throttler_; | |
| 230 | |
| 220 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 231 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 221 | 232 |
| 222 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 233 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 223 }; | 234 }; |
| 224 } // namespace ntp_snippets | 235 } // namespace ntp_snippets |
| 225 | 236 |
| 226 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | 237 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |