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/core/image_data_fetcher.h" | 5 #include "components/image_fetcher/core/image_data_fetcher.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 pending_requests_[request->url_fetcher.get()] = std::move(request); | 83 pending_requests_[request->url_fetcher.get()] = std::move(request); |
84 } | 84 } |
85 | 85 |
86 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 86 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
87 DCHECK(pending_requests_.find(source) != pending_requests_.end()); | 87 DCHECK(pending_requests_.find(source) != pending_requests_.end()); |
88 bool success = source->GetStatus().status() == net::URLRequestStatus::SUCCESS; | 88 bool success = source->GetStatus().status() == net::URLRequestStatus::SUCCESS; |
89 | 89 |
90 RequestMetadata metadata; | 90 RequestMetadata metadata; |
91 if (success && source->GetResponseHeaders()) { | 91 if (success && source->GetResponseHeaders()) { |
| 92 metadata.http_response_headers = source->GetResponseHeaders(); |
92 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type); | 93 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type); |
93 metadata.http_response_code = source->GetResponseHeaders()->response_code(); | 94 metadata.http_response_code = source->GetResponseHeaders()->response_code(); |
94 success &= (metadata.http_response_code == net::HTTP_OK); | 95 success &= (metadata.http_response_code == net::HTTP_OK); |
95 } | 96 } |
96 metadata.from_http_cache = source->WasCached(); | 97 metadata.from_http_cache = source->WasCached(); |
97 | 98 |
98 std::string image_data; | 99 std::string image_data; |
99 if (success) { | 100 if (success) { |
100 source->GetResponseAsString(&image_data); | 101 source->GetResponseAsString(&image_data); |
101 } | 102 } |
(...skipping 23 matching lines...) Expand all Loading... |
125 void ImageDataFetcher::FinishRequest(const net::URLFetcher* source, | 126 void ImageDataFetcher::FinishRequest(const net::URLFetcher* source, |
126 const RequestMetadata& metadata, | 127 const RequestMetadata& metadata, |
127 const std::string& image_data) { | 128 const std::string& image_data) { |
128 auto request_iter = pending_requests_.find(source); | 129 auto request_iter = pending_requests_.find(source); |
129 DCHECK(request_iter != pending_requests_.end()); | 130 DCHECK(request_iter != pending_requests_.end()); |
130 request_iter->second->callback.Run(image_data, metadata); | 131 request_iter->second->callback.Run(image_data, metadata); |
131 pending_requests_.erase(request_iter); | 132 pending_requests_.erase(request_iter); |
132 } | 133 } |
133 | 134 |
134 } // namespace image_fetcher | 135 } // namespace image_fetcher |
OLD | NEW |