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 "chrome/browser/search/suggestions/image_fetcher_impl.h" | 5 #include "components/image_fetcher/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 "chrome/browser/search/suggestions/image_decoder_impl.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
13 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
14 #include "ui/gfx/image/image.h" | |
15 | 12 |
16 namespace suggestions { | 13 namespace image_fetcher { |
17 | 14 |
18 ImageFetcherImpl::ImageFetcherImpl( | 15 ImageFetcherImpl::ImageFetcherImpl( |
| 16 std::unique_ptr<ImageDecoder> image_decoder, |
19 net::URLRequestContextGetter* url_request_context) | 17 net::URLRequestContextGetter* url_request_context) |
20 : delegate_(nullptr), url_request_context_(url_request_context), | 18 : delegate_(nullptr), url_request_context_(url_request_context), |
21 image_decoder_(new suggestions::ImageDecoderImpl()), | 19 image_decoder_(std::move(image_decoder)), |
22 image_data_fetcher_( | 20 image_data_fetcher_(new ImageDataFetcher(url_request_context_.get())) { |
23 new image_fetcher::ImageDataFetcher(url_request_context_)) { | |
24 } | 21 } |
25 | 22 |
26 ImageFetcherImpl::~ImageFetcherImpl() {} | 23 ImageFetcherImpl::~ImageFetcherImpl() {} |
27 | 24 |
28 ImageFetcherImpl::ImageRequest::ImageRequest() {} | 25 ImageFetcherImpl::ImageRequest::ImageRequest() {} |
29 | 26 |
30 ImageFetcherImpl::ImageRequest::ImageRequest(const ImageRequest& other) = | 27 ImageFetcherImpl::ImageRequest::ImageRequest(const ImageRequest& other) = |
31 default; | 28 default; |
32 | 29 |
33 ImageFetcherImpl::ImageRequest::~ImageRequest() { } | 30 ImageFetcherImpl::ImageRequest::~ImageRequest() { } |
34 | 31 |
35 void ImageFetcherImpl::SetImageFetcherDelegate( | 32 void ImageFetcherImpl::SetImageFetcherDelegate(ImageFetcherDelegate* delegate) { |
36 image_fetcher::ImageFetcherDelegate* delegate) { | |
37 DCHECK(delegate); | 33 DCHECK(delegate); |
38 delegate_ = delegate; | 34 delegate_ = delegate; |
39 } | 35 } |
40 | 36 |
41 void ImageFetcherImpl::StartOrQueueNetworkRequest( | 37 void ImageFetcherImpl::StartOrQueueNetworkRequest( |
42 const std::string& id, | 38 const std::string& id, |
43 const GURL& image_url, | 39 const GURL& image_url, |
44 base::Callback<void(const std::string&, const gfx::Image&)> callback) { | 40 base::Callback<void(const std::string&, const gfx::Image&)> callback) { |
45 // Before starting to fetch the image. Look for a request in progress for | 41 // Before starting to fetch the image. Look for a request in progress for |
46 // |image_url|, and queue if appropriate. | 42 // |image_url|, and queue if appropriate. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 86 |
91 // Inform the ImageFetcherDelegate. | 87 // Inform the ImageFetcherDelegate. |
92 if (delegate_) { | 88 if (delegate_) { |
93 delegate_->OnImageFetched(request->id, image); | 89 delegate_->OnImageFetched(request->id, image); |
94 } | 90 } |
95 | 91 |
96 // Erase the completed ImageRequest. | 92 // Erase the completed ImageRequest. |
97 pending_net_requests_.erase(image_iter); | 93 pending_net_requests_.erase(image_iter); |
98 } | 94 } |
99 | 95 |
100 } // namespace suggestions | 96 } // namespace image_fetcher |
OLD | NEW |