Repurpose NotificationBitmapFetcher to BitmapFetcher
[chromium-blink-merge.git] / chrome / browser / bitmap_fetcher.h
blob6c3508c64c25ce329854c58c39e7eff0bf232507
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_H_
6 #define CHROME_BROWSER_BITMAP_FETCHER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/bitmap_fetcher_delegate.h"
10 #include "chrome/browser/image_decoder.h"
11 #include "net/url_request/url_fetcher_delegate.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "url/gurl.h"
15 namespace net {
16 class URLFetcher;
17 } // namespace net
19 class Profile;
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::Delegate {
27 public:
28 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate);
29 virtual ~BitmapFetcher();
31 const GURL& url() const { return url_; }
33 // Start fetching the URL with the fetcher. The delegate is notified
34 // asynchronously when done.
35 void Start(Profile* profile);
37 // Methods inherited from URLFetcherDelegate
39 // This will be called when the URL has been fetched, successfully or not.
40 // Use accessor methods on |source| to get the results.
41 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
43 // This will be called when some part of the response is read. |current|
44 // denotes the number of bytes received up to the call, and |total| is the
45 // expected total size of the response (or -1 if not determined).
46 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
47 int64 current,
48 int64 total) OVERRIDE;
50 // Methods inherited from ImageDecoder::Delegate
52 // Called when image is decoded. |decoder| is used to identify the image in
53 // case of decoding several images simultaneously. This will not be called
54 // on the UI thread.
55 virtual void OnImageDecoded(const ImageDecoder* decoder,
56 const SkBitmap& decoded_image) OVERRIDE;
58 // Called when decoding image failed.
59 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
61 private:
62 // Alerts the delegate that a failure occurred.
63 void ReportFailure();
65 scoped_ptr<net::URLFetcher> url_fetcher_;
66 scoped_refptr<ImageDecoder> image_decoder_;
67 const GURL url_;
68 BitmapFetcherDelegate* const delegate_;
70 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher);
73 } // namespace chrome
75 #endif // CHROME_BROWSER_BITMAP_FETCHER_H_