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> |
| (...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 // Enumaration listing all possible variants of dealing with personalization. | |
|
Bernhard Bauer
2016/05/18 10:08:03
"Enumeration"
jkrcal
2016/05/19 07:30:28
Done.
| |
| 69 enum class Personalization { kPersonal, kNonPersonal, kBoth }; | |
|
Bernhard Bauer
2016/05/18 10:08:04
Put the values on individual lines :)
jkrcal
2016/05/19 07:30:28
One line is what "git cl format" produces. Should
Bernhard Bauer
2016/05/19 08:51:19
Yeah, it would be nice. I don't think clang-format
jkrcal
2016/05/19 10:58:16
I am afraid I do not understand. Do you suggest me
Bernhard Bauer
2016/05/19 11:05:46
That is correct. There are areas of the code base
jkrcal
2016/05/19 16:36:24
Done.
| |
| 70 | |
| 68 NTPSnippetsFetcher( | 71 NTPSnippetsFetcher( |
| 69 SigninManagerBase* signin_manager, | 72 SigninManagerBase* signin_manager, |
| 70 OAuth2TokenService* oauth2_token_service, | 73 OAuth2TokenService* oauth2_token_service, |
| 71 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 74 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 72 const ParseJSONCallback& parse_json_callback, | 75 const ParseJSONCallback& parse_json_callback, |
| 73 bool is_stable_channel); | 76 bool is_stable_channel); |
| 74 ~NTPSnippetsFetcher() override; | 77 ~NTPSnippetsFetcher() override; |
| 75 | 78 |
| 76 // Set a callback that is called when a new set of snippets are downloaded, | 79 // Set a callback that is called when a new set of snippets are downloaded, |
| 77 // overriding any previously set callback. | 80 // overriding any previously set callback. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 88 int count); | 91 int count); |
| 89 | 92 |
| 90 // Debug string representing the status/result of the last fetch attempt. | 93 // Debug string representing the status/result of the last fetch attempt. |
| 91 const std::string& last_status() const { return last_status_; } | 94 const std::string& last_status() const { return last_status_; } |
| 92 | 95 |
| 93 // Returns the last json fetched from the server. | 96 // Returns the last json fetched from the server. |
| 94 const std::string& last_json() const { | 97 const std::string& last_json() const { |
| 95 return last_fetch_json_; | 98 return last_fetch_json_; |
| 96 } | 99 } |
| 97 | 100 |
| 101 // Returns the last json fetched from the server. | |
|
Bernhard Bauer
2016/05/18 10:08:04
Nit: JSON
jkrcal
2016/05/19 07:30:28
Done.
| |
| 102 const Personalization personalization() const { return personalization_; } | |
|
Bernhard Bauer
2016/05/18 10:08:04
Const for a return type that is by itself immutabl
jkrcal
2016/05/19 07:30:28
Thanks. Interestingly, it even does not compile on
| |
| 103 | |
| 104 // Does the fetcher use host restriction? | |
| 105 bool UseHostRestriction() const; | |
|
Bernhard Bauer
2016/05/18 10:08:03
Nit: "host restrictions" (plural). Also, "uses", s
jkrcal
2016/05/19 07:30:28
Done.
| |
| 106 // Does the fetcher use authentication to get personalized results? | |
| 107 bool UseAuthentication() const; | |
|
Bernhard Bauer
2016/05/18 10:08:03
"Uses" here as well.
jkrcal
2016/05/19 07:30:28
Done.
| |
| 108 | |
| 98 // Overrides internal clock for testing purposes. | 109 // Overrides internal clock for testing purposes. |
| 99 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { | 110 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { |
| 100 tick_clock_ = std::move(tick_clock); | 111 tick_clock_ = std::move(tick_clock); |
| 101 } | 112 } |
| 102 | 113 |
| 103 private: | 114 private: |
| 104 enum class Personalization { kPersonal, kNonPersonal, kBoth }; | |
| 105 | |
| 106 void FetchSnippetsImpl(const GURL& url, | 115 void FetchSnippetsImpl(const GURL& url, |
| 107 const std::string& auth_header, | 116 const std::string& auth_header, |
| 108 const std::string& request); | 117 const std::string& request); |
| 109 std::string GetHostRestricts() const; | 118 std::string GetHostRestricts() const; |
| 110 bool UseHostRestriction() const; | |
| 111 bool UseAuthentication() const; | |
| 112 void FetchSnippetsNonAuthenticated(); | 119 void FetchSnippetsNonAuthenticated(); |
| 113 void FetchSnippetsAuthenticated(const std::string& account_id, | 120 void FetchSnippetsAuthenticated(const std::string& account_id, |
| 114 const std::string& oauth_access_token); | 121 const std::string& oauth_access_token); |
| 115 void StartTokenRequest(); | 122 void StartTokenRequest(); |
| 116 | 123 |
| 117 // OAuth2TokenService::Consumer overrides: | 124 // OAuth2TokenService::Consumer overrides: |
| 118 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 125 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 119 const std::string& access_token, | 126 const std::string& access_token, |
| 120 const base::Time& expiration_time) override; | 127 const base::Time& expiration_time) override; |
| 121 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 128 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 // Allow for an injectable tick clock for testing. | 180 // Allow for an injectable tick clock for testing. |
| 174 std::unique_ptr<base::TickClock> tick_clock_; | 181 std::unique_ptr<base::TickClock> tick_clock_; |
| 175 | 182 |
| 176 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 183 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 177 | 184 |
| 178 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 185 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 179 }; | 186 }; |
| 180 } // namespace ntp_snippets | 187 } // namespace ntp_snippets |
| 181 | 188 |
| 182 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | 189 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |