Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / search / suggestions / image_fetcher_impl.h
blobbfd8d58f2374e5b97a4d006df70468491660bade
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_
8 #include <map>
9 #include <utility>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
15 #include "components/suggestions/image_fetcher.h"
16 #include "ui/gfx/image/image_skia.h"
17 #include "url/gurl.h"
19 namespace net {
20 class URLRequestContextGetter;
23 namespace suggestions {
25 // A class used to fetch server images.
26 class ImageFetcherImpl : public ImageFetcher,
27 public chrome::BitmapFetcherDelegate {
28 public:
29 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context);
30 ~ImageFetcherImpl() override;
32 void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) override;
34 void StartOrQueueNetworkRequest(
35 const GURL& url,
36 const GURL& image_url,
37 base::Callback<void(const GURL&, const SkBitmap*)> callback) override;
39 private:
40 // Inherited from BitmapFetcherDelegate. Runs on the UI thread.
41 void OnFetchComplete(const GURL& image_url, const SkBitmap* bitmap) override;
43 typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> >
44 CallbackVector;
46 // State related to an image fetch (associated website url, image_url,
47 // fetcher, pending callbacks).
48 struct ImageRequest {
49 ImageRequest();
50 // Struct takes ownership of |f|.
51 explicit ImageRequest(chrome::BitmapFetcher* f);
52 ~ImageRequest();
54 void swap(ImageRequest* other) {
55 std::swap(url, other->url);
56 std::swap(image_url, other->image_url);
57 std::swap(callbacks, other->callbacks);
58 std::swap(fetcher, other->fetcher);
61 GURL url;
62 GURL image_url;
63 chrome::BitmapFetcher* fetcher;
64 // Queue for pending callbacks, which may accumulate while the request is in
65 // flight.
66 CallbackVector callbacks;
69 typedef std::map<const GURL, ImageRequest> ImageRequestMap;
71 // Map from each image URL to the request information (associated website
72 // url, fetcher, pending callbacks).
73 ImageRequestMap pending_net_requests_;
75 ImageFetcherDelegate* delegate_;
77 net::URLRequestContextGetter* url_request_context_;
79 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl);
82 } // namespace suggestions
84 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_