| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_fetcher_impl.h" | 5 #include "components/image_fetcher/core/image_fetcher_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 void ImageFetcherImpl::SetImageDownloadLimit( | 46 void ImageFetcherImpl::SetImageDownloadLimit( |
| 47 base::Optional<int64_t> max_download_bytes) { | 47 base::Optional<int64_t> max_download_bytes) { |
| 48 image_data_fetcher_->SetImageDownloadLimit(max_download_bytes); | 48 image_data_fetcher_->SetImageDownloadLimit(max_download_bytes); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ImageFetcherImpl::StartOrQueueNetworkRequest( | 51 void ImageFetcherImpl::StartOrQueueNetworkRequest( |
| 52 const std::string& id, | 52 const std::string& id, |
| 53 const GURL& image_url, | 53 const GURL& image_url, |
| 54 const ImageFetcherCallback& callback) { | 54 const ImageFetcherCallback& callback, |
| 55 const net::NetworkTrafficAnnotationTag& traffic_annotation) { |
| 55 // Before starting to fetch the image. Look for a request in progress for | 56 // Before starting to fetch the image. Look for a request in progress for |
| 56 // |image_url|, and queue if appropriate. | 57 // |image_url|, and queue if appropriate. |
| 57 ImageRequestMap::iterator it = pending_net_requests_.find(image_url); | 58 ImageRequestMap::iterator it = pending_net_requests_.find(image_url); |
| 58 if (it == pending_net_requests_.end()) { | 59 if (it == pending_net_requests_.end()) { |
| 59 ImageRequest request; | 60 ImageRequest request; |
| 60 request.id = id; | 61 request.id = id; |
| 61 request.callbacks.push_back(callback); | 62 request.callbacks.push_back(callback); |
| 62 pending_net_requests_[image_url].swap(&request); | 63 pending_net_requests_[image_url].swap(&request); |
| 63 | 64 |
| 64 image_data_fetcher_->FetchImageData( | 65 image_data_fetcher_->FetchImageData( |
| 65 image_url, base::Bind(&ImageFetcherImpl::OnImageURLFetched, | 66 image_url, |
| 66 base::Unretained(this), image_url)); | 67 base::Bind(&ImageFetcherImpl::OnImageURLFetched, base::Unretained(this), |
| 68 image_url), |
| 69 traffic_annotation); |
| 67 } else { | 70 } else { |
| 68 // Request in progress. Register as an interested callback. | 71 // Request in progress. Register as an interested callback. |
| 69 it->second.callbacks.push_back(callback); | 72 it->second.callbacks.push_back(callback); |
| 70 } | 73 } |
| 71 } | 74 } |
| 72 | 75 |
| 73 void ImageFetcherImpl::OnImageURLFetched(const GURL& image_url, | 76 void ImageFetcherImpl::OnImageURLFetched(const GURL& image_url, |
| 74 const std::string& image_data, | 77 const std::string& image_data, |
| 75 const RequestMetadata& metadata) { | 78 const RequestMetadata& metadata) { |
| 76 // Inform the ImageFetcherDelegate. | 79 // Inform the ImageFetcherDelegate. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 106 | 109 |
| 107 // Erase the completed ImageRequest. | 110 // Erase the completed ImageRequest. |
| 108 pending_net_requests_.erase(image_iter); | 111 pending_net_requests_.erase(image_iter); |
| 109 } | 112 } |
| 110 | 113 |
| 111 ImageDecoder* ImageFetcherImpl::GetImageDecoder() { | 114 ImageDecoder* ImageFetcherImpl::GetImageDecoder() { |
| 112 return image_decoder_.get(); | 115 return image_decoder_.get(); |
| 113 } | 116 } |
| 114 | 117 |
| 115 } // namespace image_fetcher | 118 } // namespace image_fetcher |
| OLD | NEW |