| 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/metrics/sparse_histogram.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 14 #include "google_apis/google_api_keys.h" | 15 #include "google_apis/google_api_keys.h" |
| 15 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 16 #include "net/http/http_request_headers.h" | 17 #include "net/http/http_request_headers.h" |
| 17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 18 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 url_fetcher_->Start(); | 114 url_fetcher_->Start(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 //////////////////////////////////////////////////////////////////////////////// | 117 //////////////////////////////////////////////////////////////////////////////// |
| 117 // URLFetcherDelegate overrides | 118 // URLFetcherDelegate overrides |
| 118 void NTPSnippetsFetcher::OnURLFetchComplete(const URLFetcher* source) { | 119 void NTPSnippetsFetcher::OnURLFetchComplete(const URLFetcher* source) { |
| 119 DCHECK_EQ(url_fetcher_.get(), source); | 120 DCHECK_EQ(url_fetcher_.get(), source); |
| 120 | 121 |
| 121 std::string message; | 122 std::string message; |
| 122 const URLRequestStatus& status = source->GetStatus(); | 123 const URLRequestStatus& status = source->GetStatus(); |
| 124 |
| 125 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 126 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode", |
| 127 status.is_success() ? source->GetResponseCode() : status.error()); |
| 128 |
| 123 if (!status.is_success()) { | 129 if (!status.is_success()) { |
| 124 message = base::StringPrintf(kStatusMessageURLRequestErrorFormat, | 130 message = base::StringPrintf(kStatusMessageURLRequestErrorFormat, |
| 125 status.error()); | 131 status.error()); |
| 126 } else if (source->GetResponseCode() != net::HTTP_OK) { | 132 } else if (source->GetResponseCode() != net::HTTP_OK) { |
| 127 message = base::StringPrintf(kStatusMessageHTTPErrorFormat, | 133 message = base::StringPrintf(kStatusMessageHTTPErrorFormat, |
| 128 source->GetResponseCode()); | 134 source->GetResponseCode()); |
| 129 } | 135 } |
| 130 | 136 |
| 131 std::string response; | 137 std::string response; |
| 132 if (!message.empty()) { | 138 if (!message.empty()) { |
| 133 DLOG(WARNING) << message << " while trying to download " | 139 DLOG(WARNING) << message << " while trying to download " |
| 134 << source->GetURL().spec(); | 140 << source->GetURL().spec(); |
| 135 | 141 |
| 136 } else { | 142 } else { |
| 137 bool stores_result_to_string = source->GetResponseAsString(&response); | 143 bool stores_result_to_string = source->GetResponseAsString(&response); |
| 138 DCHECK(stores_result_to_string); | 144 DCHECK(stores_result_to_string); |
| 139 } | 145 } |
| 140 | 146 |
| 141 callback_list_.Notify(response, message); | 147 callback_list_.Notify(response, message); |
| 142 } | 148 } |
| 143 | 149 |
| 144 } // namespace ntp_snippets | 150 } // namespace ntp_snippets |
| OLD | NEW |