OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ | |
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ | |
7 | |
8 #include <map> | |
9 #include <utility> | |
10 #include <vector> | |
11 | |
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" | |
18 | |
19 namespace net { | |
20 class URLRequestContextGetter; | |
21 } | |
22 | |
23 namespace suggestions { | |
24 | |
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 virtual ~ImageFetcherImpl(); | |
31 | |
32 virtual void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) OVERRIDE; | |
33 | |
34 virtual void StartOrQueueNetworkRequest( | |
35 const GURL& url, const GURL& image_url, | |
36 base::Callback<void(const GURL&, const SkBitmap*)> callback) OVERRIDE; | |
37 | |
38 private: | |
39 // Inherited from BitmapFetcherDelegate. Runs on the UI thread. | |
40 virtual void OnFetchComplete(const GURL image_url, | |
huangs
2014/09/22 21:51:13
const GURL or const GURL& ? Also check .cc file.
Mathieu
2014/09/23 14:59:06
The bitmap_fetcher_delegate is not controlled by m
| |
41 const SkBitmap* bitmap) OVERRIDE; | |
42 | |
43 typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> > | |
44 CallbackVector; | |
45 | |
46 // State related to an image fetch (associated website url, image_url, | |
47 // fetcher, pending callbacks). | |
48 struct ImageRequest { | |
49 ImageRequest(); | |
50 explicit ImageRequest(chrome::BitmapFetcher* f); | |
huangs
2014/09/22 21:51:13
Comment on the fact that the class takes ownership
Mathieu
2014/09/23 14:59:06
Done.
| |
51 ~ImageRequest(); | |
52 | |
53 void swap(ImageRequest* other) { | |
54 std::swap(url, other->url); | |
55 std::swap(image_url, other->image_url); | |
56 std::swap(callbacks, other->callbacks); | |
57 std::swap(fetcher, other->fetcher); | |
58 } | |
59 | |
60 GURL url; | |
61 GURL image_url; | |
62 chrome::BitmapFetcher* fetcher; | |
63 // Queue for pending callbacks, which may accumulate while the request is in | |
64 // flight. | |
65 CallbackVector callbacks; | |
66 }; | |
67 | |
68 typedef std::map<const GURL, ImageRequest> ImageRequestMap; | |
69 | |
70 // Map from each image URL to the request information (associated website | |
71 // url, fetcher, pending callbacks). | |
72 ImageRequestMap pending_net_requests_; | |
73 | |
74 ImageFetcherDelegate* delegate_; | |
75 | |
76 net::URLRequestContextGetter* url_request_context_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); | |
79 }; | |
80 | |
81 } // namespace suggestions | |
82 | |
83 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ | |
OLD | NEW |