| 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 #include "components/ntp_snippets/ntp_snippets_fetcher.h" | 5 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 base::StringPrintf(kAuthorizationRequestHeaderFormat, | 114 base::StringPrintf(kAuthorizationRequestHeaderFormat, |
| 115 access_token.c_str())); | 115 access_token.c_str())); |
| 116 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); | 116 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); |
| 117 url_fetcher_->SetExtraRequestHeaders(headers.ToString()); | 117 url_fetcher_->SetExtraRequestHeaders(headers.ToString()); |
| 118 std::string host_restricts; | 118 std::string host_restricts; |
| 119 for (const std::string& host : hosts_) | 119 for (const std::string& host : hosts_) |
| 120 host_restricts += base::StringPrintf(kHostRestrictFormat, host.c_str()); | 120 host_restricts += base::StringPrintf(kHostRestrictFormat, host.c_str()); |
| 121 url_fetcher_->SetUploadData("application/json", | 121 url_fetcher_->SetUploadData("application/json", |
| 122 base::StringPrintf(kRequestParameterFormat, | 122 base::StringPrintf(kRequestParameterFormat, |
| 123 host_restricts.c_str())); | 123 host_restricts.c_str())); |
| 124 |
| 125 // Fetchers are sometimes cancelled because a network change was detected. |
| 126 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); |
| 127 // Try to make fetching the files bit more robust even with poor connection. |
| 128 url_fetcher_->SetMaxRetriesOn5xx(3); |
| 124 url_fetcher_->Start(); | 129 url_fetcher_->Start(); |
| 125 } | 130 } |
| 126 | 131 |
| 127 void NTPSnippetsFetcher::OnGetTokenFailure( | 132 void NTPSnippetsFetcher::OnGetTokenFailure( |
| 128 const OAuth2TokenService::Request* request, | 133 const OAuth2TokenService::Request* request, |
| 129 const GoogleServiceAuthError& error) { | 134 const GoogleServiceAuthError& error) { |
| 130 oauth_request_.reset(); | 135 oauth_request_.reset(); |
| 131 DLOG(ERROR) << "Unable to get token: " << error.ToString(); | 136 DLOG(ERROR) << "Unable to get token: " << error.ToString(); |
| 132 } | 137 } |
| 133 | 138 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 160 } | 165 } |
| 161 | 166 |
| 162 std::string response; | 167 std::string response; |
| 163 bool stores_result_to_string = source->GetResponseAsString(&response); | 168 bool stores_result_to_string = source->GetResponseAsString(&response); |
| 164 DCHECK(stores_result_to_string); | 169 DCHECK(stores_result_to_string); |
| 165 | 170 |
| 166 callback_list_.Notify(response); | 171 callback_list_.Notify(response); |
| 167 } | 172 } |
| 168 | 173 |
| 169 } // namespace ntp_snippets | 174 } // namespace ntp_snippets |
| OLD | NEW |