| 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/image_fetcher/image_data_fetcher.h" | 5 #include "components/image_fetcher/image_data_fetcher.h" |
| 6 | 6 |
| 7 #include "net/base/load_flags.h" | 7 #include "net/base/load_flags.h" |
| 8 #include "net/http/http_response_headers.h" | 8 #include "net/http/http_response_headers.h" |
| 9 #include "net/http/http_status_code.h" | 9 #include "net/http/http_status_code.h" |
| 10 #include "net/url_request/url_fetcher.h" | 10 #include "net/url_request/url_fetcher.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 pending_requests_[request->url_fetcher.get()] = std::move(request); | 75 pending_requests_[request->url_fetcher.get()] = std::move(request); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 78 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| 79 auto request_iter = pending_requests_.find(source); | 79 auto request_iter = pending_requests_.find(source); |
| 80 DCHECK(request_iter != pending_requests_.end()); | 80 DCHECK(request_iter != pending_requests_.end()); |
| 81 | 81 |
| 82 bool success = source->GetStatus().status() == net::URLRequestStatus::SUCCESS; | 82 bool success = source->GetStatus().status() == net::URLRequestStatus::SUCCESS; |
| 83 | 83 |
| 84 RequestMetadata metadata; | 84 RequestMetadata metadata; |
| 85 metadata.response_code = RESPONSE_CODE_INVALID; |
| 85 if (success && source->GetResponseHeaders()) { | 86 if (success && source->GetResponseHeaders()) { |
| 86 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type); | 87 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type); |
| 87 success &= (source->GetResponseHeaders()->response_code() == net::HTTP_OK); | 88 metadata.response_code = source->GetResponseHeaders()->response_code(); |
| 89 success &= (metadata.response_code == net::HTTP_OK); |
| 88 } | 90 } |
| 89 | 91 |
| 90 std::string image_data; | 92 std::string image_data; |
| 91 if (success) { | 93 if (success) { |
| 92 source->GetResponseAsString(&image_data); | 94 source->GetResponseAsString(&image_data); |
| 93 } | 95 } |
| 94 request_iter->second->callback.Run(image_data, metadata); | 96 request_iter->second->callback.Run(image_data, metadata); |
| 95 | 97 |
| 96 // Remove the finished request. | 98 // Remove the finished request. |
| 97 pending_requests_.erase(request_iter); | 99 pending_requests_.erase(request_iter); |
| 98 } | 100 } |
| 99 | 101 |
| 100 } // namespace image_fetcher | 102 } // namespace image_fetcher |
| OLD | NEW |