| 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 <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 data_use_measurement::DataUseUserData::AttachToFetcher( | 249 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 250 url_fetcher_.get(), data_use_measurement::DataUseUserData::NTP_SNIPPETS); | 250 url_fetcher_.get(), data_use_measurement::DataUseUserData::NTP_SNIPPETS); |
| 251 | 251 |
| 252 HttpRequestHeaders headers; | 252 HttpRequestHeaders headers; |
| 253 if (!auth_header.empty()) | 253 if (!auth_header.empty()) |
| 254 headers.SetHeader("Authorization", auth_header); | 254 headers.SetHeader("Authorization", auth_header); |
| 255 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); | 255 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); |
| 256 url_fetcher_->SetExtraRequestHeaders(headers.ToString()); | 256 url_fetcher_->SetExtraRequestHeaders(headers.ToString()); |
| 257 url_fetcher_->SetUploadData("application/json", request); | 257 url_fetcher_->SetUploadData("application/json", request); |
| 258 // Log the request for debugging network issues. |
| 259 VLOG(1) << "Sending a NTP snippets request to " << url << ":" << std::endl |
| 260 << headers.ToString() << std::endl << request; |
| 258 // Fetchers are sometimes cancelled because a network change was detected. | 261 // Fetchers are sometimes cancelled because a network change was detected. |
| 259 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); | 262 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); |
| 260 // Try to make fetching the files bit more robust even with poor connection. | 263 // Try to make fetching the files bit more robust even with poor connection. |
| 261 url_fetcher_->SetMaxRetriesOn5xx(3); | 264 url_fetcher_->SetMaxRetriesOn5xx(3); |
| 262 url_fetcher_->Start(); | 265 url_fetcher_->Start(); |
| 263 } | 266 } |
| 264 | 267 |
| 265 std::string NTPSnippetsFetcher::GetHostRestricts() const { | 268 std::string NTPSnippetsFetcher::GetHostRestricts() const { |
| 266 std::string host_restricts; | 269 std::string host_restricts; |
| 267 if (UsesHostRestrictions()) { | 270 if (UsesHostRestrictions()) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 tick_clock_->NowTicks() - fetch_start_time_); | 436 tick_clock_->NowTicks() - fetch_start_time_); |
| 434 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", | 437 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", |
| 435 static_cast<int>(result), | 438 static_cast<int>(result), |
| 436 static_cast<int>(FetchResult::RESULT_MAX)); | 439 static_cast<int>(FetchResult::RESULT_MAX)); |
| 437 | 440 |
| 438 if (!snippets_available_callback_.is_null()) | 441 if (!snippets_available_callback_.is_null()) |
| 439 snippets_available_callback_.Run(std::move(snippets)); | 442 snippets_available_callback_.Run(std::move(snippets)); |
| 440 } | 443 } |
| 441 | 444 |
| 442 } // namespace ntp_snippets | 445 } // namespace ntp_snippets |
| OLD | NEW |