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

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

Issue 2045233002: Split the code for fetching images and for decoding images into two separate classes. This will all… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make ~DecodeImageRequest() final 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
27 namespace suggestions { 28 namespace suggestions {
blundell 2016/06/10 08:38:12 If this code is intended to stay in //chrome it sh
markusheintz_ 2016/06/10 09:43:14 Done.
28 29
29 // image_fetcher::ImageFetcher implementation. 30 // image_fetcher::ImageFetcher implementation.
30 class ImageFetcherImpl : public image_fetcher::ImageFetcher, 31 class ImageFetcherImpl : public image_fetcher::ImageFetcher {
31 public chrome::BitmapFetcherDelegate {
32 public: 32 public:
33 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context); 33 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context);
34 ~ImageFetcherImpl() override; 34 ~ImageFetcherImpl() override;
35 35
36 void SetImageFetcherDelegate( 36 void SetImageFetcherDelegate(
37 image_fetcher::ImageFetcherDelegate* delegate) override; 37 image_fetcher::ImageFetcherDelegate* delegate) override;
38 38
39 void StartOrQueueNetworkRequest( 39 void StartOrQueueNetworkRequest(
40 const std::string& id, 40 const std::string& id,
41 const GURL& image_url, 41 const GURL& image_url,
42 base::Callback<void(const std::string&, const gfx::Image&)> callback) 42 base::Callback<void(const std::string&, const gfx::Image&)> callback)
43 override; 43 override;
44 44
45 private: 45 private:
46 // Inherited from BitmapFetcherDelegate.
47 void OnFetchComplete(const GURL& image_url, const SkBitmap* bitmap) override;
48
49 using CallbackVector = 46 using CallbackVector =
50 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>; 47 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>;
51 48
52 // State related to an image fetch (id, image_url, fetcher, pending 49 // State related to an image fetch (id, pending callbacks).
53 // callbacks).
54 struct ImageRequest { 50 struct ImageRequest {
55 ImageRequest(); 51 ImageRequest();
56 // Struct takes ownership of |f|.
57 explicit ImageRequest(chrome::BitmapFetcher* f);
58 ImageRequest(const ImageRequest& other); 52 ImageRequest(const ImageRequest& other);
59 ~ImageRequest(); 53 ~ImageRequest();
60 54
61 void swap(ImageRequest* other) { 55 void swap(ImageRequest* other) {
Marc Treib 2016/06/10 08:32:37 I think this can be removed now
markusheintz_ 2016/06/10 09:43:14 Done.
Bernhard Bauer 2016/06/10 12:48:25 Not really?
Marc Treib 2016/06/10 12:50:29 It could have been removed if we could use map::em
Bernhard Bauer 2016/06/10 12:52:11 Oh, sorry, I misinterpreted the meaning of "Done"
62 std::swap(id, other->id); 56 std::swap(id, other->id);
63 std::swap(image_url, other->image_url);
64 std::swap(callbacks, other->callbacks); 57 std::swap(callbacks, other->callbacks);
65 std::swap(fetcher, other->fetcher);
66 } 58 }
67 59
68 std::string id; 60 std::string id;
69 GURL image_url;
70 chrome::BitmapFetcher* fetcher;
71 // Queue for pending callbacks, which may accumulate while the request is in 61 // Queue for pending callbacks, which may accumulate while the request is in
72 // flight. 62 // flight.
73 CallbackVector callbacks; 63 CallbackVector callbacks;
74 }; 64 };
75 65
76 using ImageRequestMap = std::map<const GURL, ImageRequest>; 66 using ImageRequestMap = std::map<const GURL, ImageRequest>;
77 67
68 // Processes image URL fetched events. This is the continuation method used
69 // for creating callbacks that are passed to the ImageDataFetcher.
70 void OnImageURLFetched(const GURL& image_url, const std::string& image_data);
71
72 // Processes image decoded events. This is the continuation method used for
73 // creating callbacks that are passed to the ImageDecoder.
74 void OnImageDecoded(const GURL& image_url, const gfx::Image& image);
75
76
77 image_fetcher::ImageFetcherDelegate* delegate_;
78
79 net::URLRequestContextGetter* url_request_context_;
80
81 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder_;
82
83 std::unique_ptr<image_fetcher::ImageDataFetcher> image_url_fetcher_;
Marc Treib 2016/06/10 08:32:37 image_data_fetcher_ now?
markusheintz_ 2016/06/10 09:43:14 Done.
84
78 // Map from each image URL to the request information (associated website 85 // Map from each image URL to the request information (associated website
79 // url, fetcher, pending callbacks). 86 // url, fetcher, pending callbacks).
80 ImageRequestMap pending_net_requests_; 87 ImageRequestMap pending_net_requests_;
81 88
82 image_fetcher::ImageFetcherDelegate* delegate_;
83
84 net::URLRequestContextGetter* url_request_context_;
85
86 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); 89 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl);
87 }; 90 };
88 91
89 } // namespace suggestions 92 } // namespace suggestions
90 93
91 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ 94 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698