Rename vector icon header files.
[chromium-blink-merge.git] / chrome / browser / bitmap_fetcher / bitmap_fetcher.h
blob9d3aa525f9a5e72ff2faaad1f75a33490e183415
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.
5 #ifndef CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_
6 #define CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
10 #include "chrome/browser/image_decoder.h"
11 #include "net/url_request/url_fetcher_delegate.h"
12 #include "net/url_request/url_request.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "url/gurl.h"
16 namespace net {
17 class URLFetcher;
18 class URLRequestContextGetter;
19 } // namespace net
21 namespace chrome {
23 // Asynchrounously fetches an image from the given URL and returns the
24 // decoded Bitmap to the provided BitmapFetcherDelegate.
25 class BitmapFetcher : public net::URLFetcherDelegate,
26 public ImageDecoder::ImageRequest {
27 public:
28 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate);
29 ~BitmapFetcher() override;
31 const GURL& url() const { return url_; }
32 net::URLFetcher* url_fetcher() { return url_fetcher_.get(); }
34 // Initializes internal fetcher. After this function returns url_fetcher()
35 // can be accessed to configure it further (eg. add user data to request).
36 // All configuration must be done before Start() is called.
37 // Values for |load_flags| are defined in net/base/load_flags.h. In general,
38 // |net::LOAD_NORMAL| is appropriate. Init may be called more than once in
39 // some cases. If so, subsequent starts will be ignored.
40 void Init(net::URLRequestContextGetter* request_context,
41 const std::string& referrer,
42 net::URLRequest::ReferrerPolicy referrer_policy,
43 int load_flags);
45 // Start fetching the URL with the fetcher. The delegate is notified
46 // asynchronously when done. Start may be called more than once in some
47 // cases. If so, subsequent starts will be ignored since the operation is
48 // already in progress.
49 void Start();
51 // Methods inherited from URLFetcherDelegate
53 // This will be called when the URL has been fetched, successfully or not.
54 // Use accessor methods on |source| to get the results.
55 void OnURLFetchComplete(const net::URLFetcher* source) override;
57 // Methods inherited from ImageDecoder::ImageRequest
59 // Called when image is decoded. |decoder| is used to identify the image in
60 // case of decoding several images simultaneously. This will not be called
61 // on the UI thread.
62 void OnImageDecoded(const SkBitmap& decoded_image) override;
64 // Called when decoding image failed.
65 void OnDecodeImageFailed() override;
67 private:
68 // Alerts the delegate that a failure occurred.
69 void ReportFailure();
71 scoped_ptr<net::URLFetcher> url_fetcher_;
72 const GURL url_;
73 BitmapFetcherDelegate* const delegate_;
75 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher);
78 } // namespace chrome
80 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_