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

Side by Side Diff: components/image_fetcher/image_fetcher_impl.h

Issue 2761303002: Move common ImageFetcher component files to core/ (Closed)
Patch Set: Rebased. Created 3 years, 9 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
(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 COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_
6 #define COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <utility>
12 #include <vector>
13
14 #include "base/callback.h"
15 #include "base/macros.h"
16 #include "components/image_fetcher/image_data_fetcher.h"
17 #include "components/image_fetcher/image_decoder.h"
18 #include "components/image_fetcher/image_fetcher.h"
19 #include "ui/gfx/geometry/size.h"
20 #include "url/gurl.h"
21
22 namespace gfx {
23 class Image;
24 }
25
26 namespace net {
27 class URLRequestContextGetter;
28 }
29
30 namespace image_fetcher {
31
32 // The standard (non-test) implementation of ImageFetcher.
33 class ImageFetcherImpl : public image_fetcher::ImageFetcher {
34 public:
35 ImageFetcherImpl(
36 std::unique_ptr<ImageDecoder> image_decoder,
37 net::URLRequestContextGetter* url_request_context);
38 ~ImageFetcherImpl() override;
39
40 // Sets the |delegate| of the ImageFetcherImpl. The |delegate| has to be alive
41 // during the lifetime of the ImageFetcherImpl object. It is the caller's
42 // responsibility to ensure this.
43 void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) override;
44
45 // Sets a service name against which to track data usage.
46 void SetDataUseServiceName(DataUseServiceName data_use_service_name) override;
47
48 void SetDesiredImageFrameSize(const gfx::Size& size) override;
49
50 void StartOrQueueNetworkRequest(
51 const std::string& id,
52 const GURL& image_url,
53 const ImageFetcherCallback& callback) override;
54
55 ImageDecoder* GetImageDecoder() override;
56
57 private:
58 // State related to an image fetch (id, pending callbacks).
59 struct ImageRequest {
60 ImageRequest();
61 ImageRequest(const ImageRequest& other);
62 ~ImageRequest();
63
64 void swap(ImageRequest* other) {
65 std::swap(id, other->id);
66 std::swap(callbacks, other->callbacks);
67 }
68
69 std::string id;
70 // Queue for pending callbacks, which may accumulate while the request is in
71 // flight.
72 std::vector<ImageFetcherCallback> callbacks;
73 };
74
75 using ImageRequestMap = std::map<const GURL, ImageRequest>;
76
77 // Processes image URL fetched events. This is the continuation method used
78 // for creating callbacks that are passed to the ImageDataFetcher.
79 void OnImageURLFetched(const GURL& image_url,
80 const std::string& image_data,
81 const RequestMetadata& metadata);
82
83 // Processes image decoded events. This is the continuation method used for
84 // creating callbacks that are passed to the ImageDecoder.
85 void OnImageDecoded(const GURL& image_url,
86 const RequestMetadata& metadata,
87 const gfx::Image& image);
88
89 ImageFetcherDelegate* delegate_;
90
91 gfx::Size desired_image_frame_size_;
92
93 scoped_refptr<net::URLRequestContextGetter> url_request_context_;
94
95 std::unique_ptr<ImageDecoder> image_decoder_;
96
97 std::unique_ptr<ImageDataFetcher> image_data_fetcher_;
98
99 // Map from each image URL to the request information (associated website
100 // url, fetcher, pending callbacks).
101 ImageRequestMap pending_net_requests_;
102
103 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl);
104 };
105
106 } // namespace image_fetcher
107
108 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_
OLDNEW
« no previous file with comments | « components/image_fetcher/image_fetcher_delegate.h ('k') | components/image_fetcher/image_fetcher_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698