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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 bool UsesHostRestrictions() const; | 109 bool UsesHostRestrictions() const; |
110 // Does the fetcher use authentication to get personalized results? | 110 // Does the fetcher use authentication to get personalized results? |
111 bool UsesAuthentication() const; | 111 bool UsesAuthentication() const; |
112 | 112 |
113 // Overrides internal clock for testing purposes. | 113 // Overrides internal clock for testing purposes. |
114 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { | 114 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { |
115 tick_clock_ = std::move(tick_clock); | 115 tick_clock_ = std::move(tick_clock); |
116 } | 116 } |
117 | 117 |
118 private: | 118 private: |
| 119 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestAuthenticated); |
| 120 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestUnauthenticated); |
| 121 |
| 122 static std::string BuildRequest(const std::string& obfuscated_gaia_id, |
| 123 bool only_return_personalized_results, |
| 124 const std::string& user_segment, |
| 125 const std::set<std::string>& host_restricts, |
| 126 int count_to_fetch); |
| 127 |
119 void FetchSnippetsImpl(const GURL& url, | 128 void FetchSnippetsImpl(const GURL& url, |
120 const std::string& auth_header, | 129 const std::string& auth_header, |
121 const std::string& request); | 130 const std::string& request); |
122 std::string GetHostRestricts() const; | |
123 void FetchSnippetsNonAuthenticated(); | 131 void FetchSnippetsNonAuthenticated(); |
124 void FetchSnippetsAuthenticated(const std::string& account_id, | 132 void FetchSnippetsAuthenticated(const std::string& account_id, |
125 const std::string& oauth_access_token); | 133 const std::string& oauth_access_token); |
126 void StartTokenRequest(); | 134 void StartTokenRequest(); |
127 | 135 |
128 // OAuth2TokenService::Consumer overrides: | 136 // OAuth2TokenService::Consumer overrides: |
129 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 137 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
130 const std::string& access_token, | 138 const std::string& access_token, |
131 const base::Time& expiration_time) override; | 139 const base::Time& expiration_time) override; |
132 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 140 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Allow for an injectable tick clock for testing. | 192 // Allow for an injectable tick clock for testing. |
185 std::unique_ptr<base::TickClock> tick_clock_; | 193 std::unique_ptr<base::TickClock> tick_clock_; |
186 | 194 |
187 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 195 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
188 | 196 |
189 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 197 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
190 }; | 198 }; |
191 } // namespace ntp_snippets | 199 } // namespace ntp_snippets |
192 | 200 |
193 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | 201 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
OLD | NEW |