| 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> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 SUCCESS, | 58 SUCCESS, |
| 59 EMPTY_HOSTS, | 59 EMPTY_HOSTS, |
| 60 URL_REQUEST_STATUS_ERROR, | 60 URL_REQUEST_STATUS_ERROR, |
| 61 HTTP_ERROR, | 61 HTTP_ERROR, |
| 62 JSON_PARSE_ERROR, | 62 JSON_PARSE_ERROR, |
| 63 INVALID_SNIPPET_CONTENT_ERROR, | 63 INVALID_SNIPPET_CONTENT_ERROR, |
| 64 OAUTH_TOKEN_ERROR, | 64 OAUTH_TOKEN_ERROR, |
| 65 RESULT_MAX | 65 RESULT_MAX |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // Enum listing all possible variants of dealing with personalization. | 68 // Enumeration listing all possible variants of dealing with personalization. |
| 69 enum class Personalization { kPersonal, kNonPersonal, kBoth }; | 69 enum class Personalization { |
| 70 kPersonal, |
| 71 kNonPersonal, |
| 72 kBoth |
| 73 }; |
| 70 | 74 |
| 71 NTPSnippetsFetcher( | 75 NTPSnippetsFetcher( |
| 72 SigninManagerBase* signin_manager, | 76 SigninManagerBase* signin_manager, |
| 73 OAuth2TokenService* oauth2_token_service, | 77 OAuth2TokenService* oauth2_token_service, |
| 74 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 78 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 75 const ParseJSONCallback& parse_json_callback, | 79 const ParseJSONCallback& parse_json_callback, |
| 76 bool is_stable_channel); | 80 bool is_stable_channel); |
| 77 ~NTPSnippetsFetcher() override; | 81 ~NTPSnippetsFetcher() override; |
| 78 | 82 |
| 79 // Set a callback that is called when a new set of snippets are downloaded, | 83 // Set a callback that is called when a new set of snippets are downloaded, |
| 80 // overriding any previously set callback. | 84 // overriding any previously set callback. |
| 81 void SetCallback(const SnippetsAvailableCallback& callback); | 85 void SetCallback(const SnippetsAvailableCallback& callback); |
| 82 | 86 |
| 83 // Fetches snippets from the server. |hosts| restricts the results to a set of | 87 // Fetches snippets from the server. |hosts| restricts the results to a set of |
| 84 // hosts, e.g. "www.google.com". An empty host set produces an error. | 88 // hosts, e.g. "www.google.com". An empty host set produces an error. |
| 85 // | 89 // |
| 86 // If an ongoing fetch exists, it will be cancelled and a new one started, | 90 // If an ongoing fetch exists, it will be cancelled and a new one started, |
| 87 // without triggering an additional callback (i.e. not noticeable by | 91 // without triggering an additional callback (i.e. not noticeable by |
| 88 // subscriber of SetCallback()). | 92 // subscriber of SetCallback()). |
| 89 void FetchSnippetsFromHosts(const std::set<std::string>& hosts, | 93 void FetchSnippetsFromHosts(const std::set<std::string>& hosts, |
| 90 const std::string& language_code, | 94 const std::string& language_code, |
| 91 int count); | 95 int count); |
| 92 | 96 |
| 93 // Debug string representing the status/result of the last fetch attempt. | 97 // Debug string representing the status/result of the last fetch attempt. |
| 94 const std::string& last_status() const { return last_status_; } | 98 const std::string& last_status() const { return last_status_; } |
| 95 | 99 |
| 96 // Returns the last json fetched from the server. | 100 // Returns the last JSON fetched from the server. |
| 97 const std::string& last_json() const { | 101 const std::string& last_json() const { |
| 98 return last_fetch_json_; | 102 return last_fetch_json_; |
| 99 } | 103 } |
| 100 | 104 |
| 101 // Returns the personalization setting of the fetcher. | 105 // Returns the personalization setting of the fetcher. |
| 102 Personalization personalization() const { return personalization_; } | 106 Personalization personalization() const { return personalization_; } |
| 103 | 107 |
| 104 // Does the fetcher use host restriction? | 108 // Does the fetcher use host restrictions? |
| 105 bool UseHostRestriction() const; | 109 bool UsesHostRestrictions() const; |
| 106 // Does the fetcher use authentication to get personalized results? | 110 // Does the fetcher use authentication to get personalized results? |
| 107 bool UseAuthentication() const; | 111 bool UsesAuthentication() const; |
| 108 | 112 |
| 109 // Overrides internal clock for testing purposes. | 113 // Overrides internal clock for testing purposes. |
| 110 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { | 114 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { |
| 111 tick_clock_ = std::move(tick_clock); | 115 tick_clock_ = std::move(tick_clock); |
| 112 } | 116 } |
| 113 | 117 |
| 114 private: | 118 private: |
| 115 void FetchSnippetsImpl(const GURL& url, | 119 void FetchSnippetsImpl(const GURL& url, |
| 116 const std::string& auth_header, | 120 const std::string& auth_header, |
| 117 const std::string& request); | 121 const std::string& request); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // Allow for an injectable tick clock for testing. | 184 // Allow for an injectable tick clock for testing. |
| 181 std::unique_ptr<base::TickClock> tick_clock_; | 185 std::unique_ptr<base::TickClock> tick_clock_; |
| 182 | 186 |
| 183 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 187 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 184 | 188 |
| 185 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 189 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 186 }; | 190 }; |
| 187 } // namespace ntp_snippets | 191 } // namespace ntp_snippets |
| 188 | 192 |
| 189 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | 193 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |