1 // Copyright 2013 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_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/image_decoder.h"
10 #include "net/url_request/url_fetcher_delegate.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
22 // A delegate interface for users of NotificationBitmapFetcher.
23 class NotificationBitmapFetcherDelegate
{
25 // This will be called when the bitmap has been requested, whether or not the
26 // request succeeds. |url| is the URL that was originally fetched so we can
27 // match up the bitmap with a specific request.
28 virtual void OnFetchComplete(const GURL url
, const SkBitmap
* bitmap
) = 0;
31 virtual ~NotificationBitmapFetcherDelegate() {}
34 class NotificationBitmapFetcher
35 : public net::URLFetcherDelegate
,
36 public ImageDecoder::Delegate
{
38 NotificationBitmapFetcher(
40 NotificationBitmapFetcherDelegate
* delegate
);
41 virtual ~NotificationBitmapFetcher();
43 GURL
url() const { return url_
; }
45 // Start fetching the URL with the fetcher. The operation will be continued
46 // in the OnURLFetchComplete callback.
47 void Start(Profile
* profile
);
49 // Methods inherited from URLFetcherDelegate
51 // This will be called when the URL has been fetched, successfully or not.
52 // Use accessor methods on |source| to get the results.
53 virtual void OnURLFetchComplete(const net::URLFetcher
* source
) OVERRIDE
;
55 // This will be called when some part of the response is read. |current|
56 // denotes the number of bytes received up to the call, and |total| is the
57 // expected total size of the response (or -1 if not determined).
58 virtual void OnURLFetchDownloadProgress(const net::URLFetcher
* source
,
59 int64 current
, int64 total
) OVERRIDE
;
61 // Methods inherited from ImageDecoder::Delegate
63 // Called when image is decoded. |decoder| is used to identify the image in
64 // case of decoding several images simultaneously. This will not be called
66 virtual void OnImageDecoded(const ImageDecoder
* decoder
,
67 const SkBitmap
& decoded_image
) OVERRIDE
;
69 // Called when decoding image failed.
70 virtual void OnDecodeImageFailed(const ImageDecoder
* decoder
) OVERRIDE
;
73 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
74 scoped_refptr
<ImageDecoder
> image_decoder_
;
76 scoped_ptr
<SkBitmap
> bitmap_
;
77 NotificationBitmapFetcherDelegate
* const delegate_
;
79 DISALLOW_COPY_AND_ASSIGN(NotificationBitmapFetcher
);
82 } // namespace notifier
84 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H_