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 #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 | |
| 123 if (!status.is_success()) { | 125 if (!status.is_success()) { |
| 126 // Error codes are guaranteed to be negative so let's negate to use positive | |
| 127 // buckets. | |
| 128 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.FailedRequestErrorCode", | |
| 129 -status.error()); | |
| 130 | |
| 124 message = base::StringPrintf(kStatusMessageURLRequestErrorFormat, | 131 message = base::StringPrintf(kStatusMessageURLRequestErrorFormat, |
| 125 status.error()); | 132 status.error()); |
| 126 } else if (source->GetResponseCode() != net::HTTP_OK) { | 133 } else { |
| 127 message = base::StringPrintf(kStatusMessageHTTPErrorFormat, | 134 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.FetchResponseCode", |
|
Alexei Svitkine (slow)
2016/05/02 17:15:14
You can actually log these two together, see Combi
| |
| 128 source->GetResponseCode()); | 135 source->GetResponseCode()); |
| 136 | |
| 137 if (source->GetResponseCode() != net::HTTP_OK) { | |
| 138 message = base::StringPrintf(kStatusMessageHTTPErrorFormat, | |
| 139 source->GetResponseCode()); | |
| 140 } | |
| 129 } | 141 } |
| 130 | 142 |
| 131 std::string response; | 143 std::string response; |
| 132 if (!message.empty()) { | 144 if (!message.empty()) { |
| 133 DLOG(WARNING) << message << " while trying to download " | 145 DLOG(WARNING) << message << " while trying to download " |
| 134 << source->GetURL().spec(); | 146 << source->GetURL().spec(); |
| 135 | 147 |
| 136 } else { | 148 } else { |
| 137 bool stores_result_to_string = source->GetResponseAsString(&response); | 149 bool stores_result_to_string = source->GetResponseAsString(&response); |
| 138 DCHECK(stores_result_to_string); | 150 DCHECK(stores_result_to_string); |
| 139 } | 151 } |
| 140 | 152 |
| 141 callback_list_.Notify(response, message); | 153 callback_list_.Notify(response, message); |
| 142 } | 154 } |
| 143 | 155 |
| 144 } // namespace ntp_snippets | 156 } // namespace ntp_snippets |
| OLD | NEW |