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; | |
86 if (success && source->GetResponseHeaders()) { | 85 if (success && source->GetResponseHeaders()) { |
87 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type); | 86 source->GetResponseHeaders()->GetMimeType(&metadata.mime_type); |
88 metadata.response_code = source->GetResponseHeaders()->response_code(); | 87 success &= (source->GetResponseHeaders()->response_code() == net::HTTP_OK); |
89 success &= (metadata.response_code == net::HTTP_OK); | |
90 } | 88 } |
91 | 89 |
92 std::string image_data; | 90 std::string image_data; |
93 if (success) { | 91 if (success) { |
94 source->GetResponseAsString(&image_data); | 92 source->GetResponseAsString(&image_data); |
95 } | 93 } |
96 request_iter->second->callback.Run(image_data, metadata); | 94 request_iter->second->callback.Run(image_data, metadata); |
97 | 95 |
98 // Remove the finished request. | 96 // Remove the finished request. |
99 pending_requests_.erase(request_iter); | 97 pending_requests_.erase(request_iter); |
100 } | 98 } |
101 | 99 |
102 } // namespace image_fetcher | 100 } // namespace image_fetcher |
OLD | NEW |