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 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.FailedRequestErrorCode", | |
| 127 -status.error()); | |
|
Marc Treib
2016/05/02 14:41:22
I assume the minus is because the error codes tend
mastiz
2016/05/02 15:11:44
Although it's not explicitly documented, URLReques
Marc Treib
2016/05/02 15:20:56
Alright then. Maybe worth a comment?
| |
| 128 | |
| 124 message = base::StringPrintf(kStatusMessageURLRequestErrorFormat, | 129 message = base::StringPrintf(kStatusMessageURLRequestErrorFormat, |
| 125 status.error()); | 130 status.error()); |
| 126 } else if (source->GetResponseCode() != net::HTTP_OK) { | 131 } else { |
| 127 message = base::StringPrintf(kStatusMessageHTTPErrorFormat, | 132 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.FetchResponseCode", |
| 128 source->GetResponseCode()); | 133 source->GetResponseCode()); |
|
Marc Treib
2016/05/02 14:41:22
So this one is recorded on success too, which prob
mastiz
2016/05/02 15:11:44
You're right, the description was outdated, thanks
| |
| 134 | |
| 135 if (source->GetResponseCode() != net::HTTP_OK) { | |
| 136 message = base::StringPrintf(kStatusMessageHTTPErrorFormat, | |
| 137 source->GetResponseCode()); | |
| 138 } | |
| 129 } | 139 } |
| 130 | 140 |
| 131 std::string response; | 141 std::string response; |
| 132 if (!message.empty()) { | 142 if (!message.empty()) { |
| 133 DLOG(WARNING) << message << " while trying to download " | 143 DLOG(WARNING) << message << " while trying to download " |
| 134 << source->GetURL().spec(); | 144 << source->GetURL().spec(); |
| 135 | 145 |
| 136 } else { | 146 } else { |
| 137 bool stores_result_to_string = source->GetResponseAsString(&response); | 147 bool stores_result_to_string = source->GetResponseAsString(&response); |
| 138 DCHECK(stores_result_to_string); | 148 DCHECK(stores_result_to_string); |
| 139 } | 149 } |
| 140 | 150 |
| 141 callback_list_.Notify(response, message); | 151 callback_list_.Notify(response, message); |
| 142 } | 152 } |
| 143 | 153 |
| 144 } // namespace ntp_snippets | 154 } // namespace ntp_snippets |
| OLD | NEW |