Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: chrome/browser/search/suggestions/image_fetcher_impl.h

Issue 2064793004: Reland: Split the code for fetching images and for decoding images into two separate classes. This w (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only start image requests once (Fixes a bug). Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" 15 #include "components/image_fetcher/image_data_fetcher.h"
16 #include "components/image_fetcher/image_decoder.h"
16 #include "components/image_fetcher/image_fetcher.h" 17 #include "components/image_fetcher/image_fetcher.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace gfx { 20 namespace gfx {
20 class Image; 21 class Image;
21 } 22 }
22 23
23 namespace net { 24 namespace net {
24 class URLRequestContextGetter; 25 class URLRequestContextGetter;
25 } 26 }
26 27
28 // TODO(markusheintz): Move the ImageFetcherImpl to components/image_fetcher
27 namespace suggestions { 29 namespace suggestions {
28 30
29 // image_fetcher::ImageFetcher implementation. 31 // image_fetcher::ImageFetcher implementation.
30 class ImageFetcherImpl : public image_fetcher::ImageFetcher, 32 class ImageFetcherImpl : public image_fetcher::ImageFetcher {
31 public chrome::BitmapFetcherDelegate {
32 public: 33 public:
33 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context); 34 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context);
34 ~ImageFetcherImpl() override; 35 ~ImageFetcherImpl() override;
35 36
36 void SetImageFetcherDelegate( 37 void SetImageFetcherDelegate(
37 image_fetcher::ImageFetcherDelegate* delegate) override; 38 image_fetcher::ImageFetcherDelegate* delegate) override;
38 39
39 void StartOrQueueNetworkRequest( 40 void StartOrQueueNetworkRequest(
40 const std::string& id, 41 const std::string& id,
41 const GURL& image_url, 42 const GURL& image_url,
42 base::Callback<void(const std::string&, const gfx::Image&)> callback) 43 base::Callback<void(const std::string&, const gfx::Image&)> callback)
43 override; 44 override;
44 45
45 private: 46 private:
46 // Inherited from BitmapFetcherDelegate.
47 void OnFetchComplete(const GURL& image_url, const SkBitmap* bitmap) override;
48
49 using CallbackVector = 47 using CallbackVector =
50 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>; 48 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>;
51 49
52 // State related to an image fetch (id, image_url, fetcher, pending 50 // State related to an image fetch (id, pending callbacks).
53 // callbacks).
54 struct ImageRequest { 51 struct ImageRequest {
55 ImageRequest(); 52 ImageRequest();
56 // Struct takes ownership of |f|.
57 explicit ImageRequest(chrome::BitmapFetcher* f);
58 ImageRequest(const ImageRequest& other); 53 ImageRequest(const ImageRequest& other);
59 ~ImageRequest(); 54 ~ImageRequest();
60 55
61 void swap(ImageRequest* other) { 56 void swap(ImageRequest* other) {
62 std::swap(id, other->id); 57 std::swap(id, other->id);
63 std::swap(image_url, other->image_url);
64 std::swap(callbacks, other->callbacks); 58 std::swap(callbacks, other->callbacks);
65 std::swap(fetcher, other->fetcher);
66 } 59 }
67 60
68 std::string id; 61 std::string id;
69 GURL image_url;
70 chrome::BitmapFetcher* fetcher;
71 // Queue for pending callbacks, which may accumulate while the request is in 62 // Queue for pending callbacks, which may accumulate while the request is in
72 // flight. 63 // flight.
73 CallbackVector callbacks; 64 CallbackVector callbacks;
74 }; 65 };
75 66
76 using ImageRequestMap = std::map<const GURL, ImageRequest>; 67 using ImageRequestMap = std::map<const GURL, ImageRequest>;
77 68
69 // Processes image URL fetched events. This is the continuation method used
70 // for creating callbacks that are passed to the ImageDataFetcher.
71 void OnImageURLFetched(const GURL& image_url, const std::string& image_data);
72
73 // Processes image decoded events. This is the continuation method used for
74 // creating callbacks that are passed to the ImageDecoder.
75 void OnImageDecoded(const GURL& image_url, const gfx::Image& image);
76
77
78 image_fetcher::ImageFetcherDelegate* delegate_;
79
80 net::URLRequestContextGetter* url_request_context_;
81
82 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder_;
83
84 std::unique_ptr<image_fetcher::ImageDataFetcher> image_data_fetcher_;
85
78 // Map from each image URL to the request information (associated website 86 // Map from each image URL to the request information (associated website
79 // url, fetcher, pending callbacks). 87 // url, fetcher, pending callbacks).
80 ImageRequestMap pending_net_requests_; 88 ImageRequestMap pending_net_requests_;
81 89
82 image_fetcher::ImageFetcherDelegate* delegate_;
83
84 net::URLRequestContextGetter* url_request_context_;
85
86 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); 90 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl);
87 }; 91 };
88 92
89 } // namespace suggestions 93 } // namespace suggestions
90 94
91 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ 95 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/search/suggestions/image_decoder_impl.cc ('k') | chrome/browser/search/suggestions/image_fetcher_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698