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/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
| 13 #include "google_apis/google_api_keys.h" | 14 #include "google_apis/google_api_keys.h" |
| 14 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 15 #include "net/http/http_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
| 16 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 17 #include "net/http/http_status_code.h" | 18 #include "net/http/http_status_code.h" |
| 18 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
| 19 | 20 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 // Try to make fetching the files bit more robust even with poor connection. | 104 // Try to make fetching the files bit more robust even with poor connection. |
| 104 url_fetcher_->SetMaxRetriesOn5xx(3); | 105 url_fetcher_->SetMaxRetriesOn5xx(3); |
| 105 url_fetcher_->Start(); | 106 url_fetcher_->Start(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 //////////////////////////////////////////////////////////////////////////////// | 109 //////////////////////////////////////////////////////////////////////////////// |
| 109 // URLFetcherDelegate overrides | 110 // URLFetcherDelegate overrides |
| 110 void NTPSnippetsFetcher::OnURLFetchComplete(const URLFetcher* source) { | 111 void NTPSnippetsFetcher::OnURLFetchComplete(const URLFetcher* source) { |
| 111 DCHECK_EQ(url_fetcher_.get(), source); | 112 DCHECK_EQ(url_fetcher_.get(), source); |
| 112 | 113 |
| 114 std::string response; | |
|
Marc Treib
2016/04/21 13:47:20
nit: Move the definition down to where it's actual
jkrcal
2016/04/22 09:30:28
Done.
| |
| 115 std::string message; | |
| 116 | |
| 113 const URLRequestStatus& status = source->GetStatus(); | 117 const URLRequestStatus& status = source->GetStatus(); |
| 114 if (!status.is_success()) { | 118 if (!status.is_success()) |
| 115 DLOG(WARNING) << "URLRequestStatus error " << status.error() | 119 message = "URLRequestStatus error " + base::IntToString(status.error()); |
| 116 << " while trying to download " << source->GetURL().spec(); | 120 else if (source->GetResponseCode() != net::HTTP_OK) |
| 117 return; | 121 message = "HTTP error " + base::IntToString(source->GetResponseCode()); |
| 122 | |
| 123 if (!message.empty()) { | |
| 124 DLOG(WARNING) << message << " while trying to download " | |
| 125 << source->GetURL().spec(); | |
| 126 | |
| 127 } else { | |
| 128 bool stores_result_to_string = source->GetResponseAsString(&response); | |
| 129 DCHECK(stores_result_to_string); | |
| 118 } | 130 } |
| 119 | 131 |
| 120 int response_code = source->GetResponseCode(); | 132 callback_list_.Notify(response, message); |
| 121 if (response_code != net::HTTP_OK) { | |
| 122 DLOG(WARNING) << "HTTP error " << response_code | |
| 123 << " while trying to download " << source->GetURL().spec(); | |
| 124 return; | |
| 125 } | |
| 126 | |
| 127 std::string response; | |
| 128 bool stores_result_to_string = source->GetResponseAsString(&response); | |
| 129 DCHECK(stores_result_to_string); | |
| 130 | |
| 131 callback_list_.Notify(response); | |
| 132 } | 133 } |
| 133 | 134 |
| 134 } // namespace ntp_snippets | 135 } // namespace ntp_snippets |
| OLD | NEW |