| 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/url_request/url_fetcher.h" | 8 #include "net/url_request/url_fetcher.h" |
| 9 #include "net/url_request/url_request.h" | 9 #include "net/url_request/url_request.h" |
| 10 #include "net/url_request/url_request_context_getter.h" | 10 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 request->url_fetcher->SetReferrerPolicy(referrer_policy); | 70 request->url_fetcher->SetReferrerPolicy(referrer_policy); |
| 71 request->url_fetcher->Start(); | 71 request->url_fetcher->Start(); |
| 72 | 72 |
| 73 pending_requests_[request->url_fetcher.get()] = std::move(request); | 73 pending_requests_[request->url_fetcher.get()] = std::move(request); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 76 void ImageDataFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| 77 auto request_iter = pending_requests_.find(source); | 77 auto request_iter = pending_requests_.find(source); |
| 78 DCHECK(request_iter != pending_requests_.end()); | 78 DCHECK(request_iter != pending_requests_.end()); |
| 79 | 79 |
| 80 int response_code = source->GetResponseCode(); |
| 81 |
| 80 std::string image_data; | 82 std::string image_data; |
| 81 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS) { | 83 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS) { |
| 82 source->GetResponseAsString(&image_data); | 84 source->GetResponseAsString(&image_data); |
| 83 } | 85 } |
| 84 request_iter->second->callback.Run(image_data); | 86 request_iter->second->callback.Run(image_data, response_code); |
| 85 | 87 |
| 86 // Remove the finished request. | 88 // Remove the finished request. |
| 87 pending_requests_.erase(request_iter); | 89 pending_requests_.erase(request_iter); |
| 88 } | 90 } |
| 89 | 91 |
| 90 } // namespace image_fetcher | 92 } // namespace image_fetcher |
| OLD | NEW |