| 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 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ |
| 6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ | 6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 14 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| 15 #include "components/image_fetcher/image_fetcher.h" | 15 #include "components/image_fetcher/image_fetcher.h" |
| 16 #include "ui/gfx/image/image_skia.h" | |
| 17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 18 | 17 |
| 18 namespace gfx { |
| 19 class Image; |
| 20 } |
| 21 |
| 19 namespace net { | 22 namespace net { |
| 20 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
| 21 } | 24 } |
| 22 | 25 |
| 23 namespace suggestions { | 26 namespace suggestions { |
| 24 | 27 |
| 25 // A class used to fetch server images. It can be called from any thread and the | 28 // image_fetcher::ImageFetcher implementation. |
| 26 // callback will be called on the thread which initiated the fetch. | |
| 27 class ImageFetcherImpl : public image_fetcher::ImageFetcher, | 29 class ImageFetcherImpl : public image_fetcher::ImageFetcher, |
| 28 public chrome::BitmapFetcherDelegate { | 30 public chrome::BitmapFetcherDelegate { |
| 29 public: | 31 public: |
| 30 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context); | 32 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context); |
| 31 ~ImageFetcherImpl() override; | 33 ~ImageFetcherImpl() override; |
| 32 | 34 |
| 33 void SetImageFetcherDelegate( | 35 void SetImageFetcherDelegate( |
| 34 image_fetcher::ImageFetcherDelegate* delegate) override; | 36 image_fetcher::ImageFetcherDelegate* delegate) override; |
| 35 | 37 |
| 36 void StartOrQueueNetworkRequest( | 38 void StartOrQueueNetworkRequest( |
| 37 const GURL& url, | 39 const GURL& url, |
| 38 const GURL& image_url, | 40 const GURL& image_url, |
| 39 base::Callback<void(const GURL&, const SkBitmap*)> callback) override; | 41 base::Callback<void(const GURL&, const gfx::Image&)> callback) override; |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 // Inherited from BitmapFetcherDelegate. | 44 // Inherited from BitmapFetcherDelegate. |
| 43 void OnFetchComplete(const GURL& image_url, const SkBitmap* bitmap) override; | 45 void OnFetchComplete(const GURL& image_url, const SkBitmap* bitmap) override; |
| 44 | 46 |
| 45 typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> > | 47 typedef std::vector<base::Callback<void(const GURL&, const gfx::Image&)> > |
| 46 CallbackVector; | 48 CallbackVector; |
| 47 | 49 |
| 48 // State related to an image fetch (associated website url, image_url, | 50 // State related to an image fetch (associated website url, image_url, |
| 49 // fetcher, pending callbacks). | 51 // fetcher, pending callbacks). |
| 50 struct ImageRequest { | 52 struct ImageRequest { |
| 51 ImageRequest(); | 53 ImageRequest(); |
| 52 // Struct takes ownership of |f|. | 54 // Struct takes ownership of |f|. |
| 53 explicit ImageRequest(chrome::BitmapFetcher* f); | 55 explicit ImageRequest(chrome::BitmapFetcher* f); |
| 54 ImageRequest(const ImageRequest& other); | 56 ImageRequest(const ImageRequest& other); |
| 55 ~ImageRequest(); | 57 ~ImageRequest(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 78 image_fetcher::ImageFetcherDelegate* delegate_; | 80 image_fetcher::ImageFetcherDelegate* delegate_; |
| 79 | 81 |
| 80 net::URLRequestContextGetter* url_request_context_; | 82 net::URLRequestContextGetter* url_request_context_; |
| 81 | 83 |
| 82 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); | 84 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 } // namespace suggestions | 87 } // namespace suggestions |
| 86 | 88 |
| 87 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ | 89 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ |
| OLD | NEW |