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

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

Issue 2068783003: Revert of Split the code for fetching images and for decoding images into two separate classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 "components/image_fetcher/image_data_fetcher.h" 15 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
16 #include "components/image_fetcher/image_decoder.h"
17 #include "components/image_fetcher/image_fetcher.h" 16 #include "components/image_fetcher/image_fetcher.h"
18 #include "url/gurl.h" 17 #include "url/gurl.h"
19 18
20 namespace gfx { 19 namespace gfx {
21 class Image; 20 class Image;
22 } 21 }
23 22
24 namespace net { 23 namespace net {
25 class URLRequestContextGetter; 24 class URLRequestContextGetter;
26 } 25 }
27 26
28 // TODO(markusheintz): Move the ImageFetcherImpl to components/image_fetcher
29 namespace suggestions { 27 namespace suggestions {
30 28
31 // image_fetcher::ImageFetcher implementation. 29 // image_fetcher::ImageFetcher implementation.
32 class ImageFetcherImpl : public image_fetcher::ImageFetcher { 30 class ImageFetcherImpl : public image_fetcher::ImageFetcher,
31 public chrome::BitmapFetcherDelegate {
33 public: 32 public:
34 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context); 33 explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context);
35 ~ImageFetcherImpl() override; 34 ~ImageFetcherImpl() override;
36 35
37 void SetImageFetcherDelegate( 36 void SetImageFetcherDelegate(
38 image_fetcher::ImageFetcherDelegate* delegate) override; 37 image_fetcher::ImageFetcherDelegate* delegate) override;
39 38
40 void StartOrQueueNetworkRequest( 39 void StartOrQueueNetworkRequest(
41 const std::string& id, 40 const std::string& id,
42 const GURL& image_url, 41 const GURL& image_url,
43 base::Callback<void(const std::string&, const gfx::Image&)> callback) 42 base::Callback<void(const std::string&, const gfx::Image&)> callback)
44 override; 43 override;
45 44
46 private: 45 private:
46 // Inherited from BitmapFetcherDelegate.
47 void OnFetchComplete(const GURL& image_url, const SkBitmap* bitmap) override;
48
47 using CallbackVector = 49 using CallbackVector =
48 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>; 50 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>;
49 51
50 // State related to an image fetch (id, pending callbacks). 52 // State related to an image fetch (id, image_url, fetcher, pending
53 // callbacks).
51 struct ImageRequest { 54 struct ImageRequest {
52 ImageRequest(); 55 ImageRequest();
56 // Struct takes ownership of |f|.
57 explicit ImageRequest(chrome::BitmapFetcher* f);
53 ImageRequest(const ImageRequest& other); 58 ImageRequest(const ImageRequest& other);
54 ~ImageRequest(); 59 ~ImageRequest();
55 60
56 void swap(ImageRequest* other) { 61 void swap(ImageRequest* other) {
57 std::swap(id, other->id); 62 std::swap(id, other->id);
63 std::swap(image_url, other->image_url);
58 std::swap(callbacks, other->callbacks); 64 std::swap(callbacks, other->callbacks);
65 std::swap(fetcher, other->fetcher);
59 } 66 }
60 67
61 std::string id; 68 std::string id;
69 GURL image_url;
70 chrome::BitmapFetcher* fetcher;
62 // Queue for pending callbacks, which may accumulate while the request is in 71 // Queue for pending callbacks, which may accumulate while the request is in
63 // flight. 72 // flight.
64 CallbackVector callbacks; 73 CallbackVector callbacks;
65 }; 74 };
66 75
67 using ImageRequestMap = std::map<const GURL, ImageRequest>; 76 using ImageRequestMap = std::map<const GURL, ImageRequest>;
68 77
69 // Processes image URL fetched events. This is the continuation method used 78 // Map from each image URL to the request information (associated website
70 // for creating callbacks that are passed to the ImageDataFetcher. 79 // url, fetcher, pending callbacks).
71 void OnImageURLFetched(const GURL& image_url, const std::string& image_data); 80 ImageRequestMap pending_net_requests_;
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 81
78 image_fetcher::ImageFetcherDelegate* delegate_; 82 image_fetcher::ImageFetcherDelegate* delegate_;
79 83
80 net::URLRequestContextGetter* url_request_context_; 84 net::URLRequestContextGetter* url_request_context_;
81 85
82 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder_;
83
84 std::unique_ptr<image_fetcher::ImageDataFetcher> image_data_fetcher_;
85
86 // Map from each image URL to the request information (associated website
87 // url, fetcher, pending callbacks).
88 ImageRequestMap pending_net_requests_;
89
90 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); 86 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl);
91 }; 87 };
92 88
93 } // namespace suggestions 89 } // namespace suggestions
94 90
95 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ 91 #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