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

Side by Side Diff: chrome/browser/bitmap_fetcher.h

Issue 155273002: Repurpose NotificationBitmapFetcher to BitmapFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Appease windows bot Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/bitmap_fetcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H _ 5 #ifndef CHROME_BROWSER_BITMAP_FETCHER_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H _ 6 #define CHROME_BROWSER_BITMAP_FETCHER_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/bitmap_fetcher_delegate.h"
9 #include "chrome/browser/image_decoder.h" 10 #include "chrome/browser/image_decoder.h"
10 #include "net/url_request/url_fetcher_delegate.h" 11 #include "net/url_request/url_fetcher_delegate.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "url/gurl.h" 13 #include "url/gurl.h"
13 14
14 namespace net { 15 namespace net {
15 class URLFetcher; 16 class URLFetcher;
16 } // namespace net 17 } // namespace net
17 18
18 class Profile; 19 class Profile;
19 20
20 namespace notifier { 21 namespace chrome {
21 22
22 // A delegate interface for users of NotificationBitmapFetcher. 23 // Asynchrounously fetches an image from the given URL and returns the
23 class NotificationBitmapFetcherDelegate { 24 // decoded Bitmap to the provided BitmapFetcherDelegate.
25 class BitmapFetcher : public net::URLFetcherDelegate,
26 public ImageDecoder::Delegate {
24 public: 27 public:
25 // This will be called when the bitmap has been requested, whether or not the 28 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate);
26 // request succeeds. |url| is the URL that was originally fetched so we can 29 virtual ~BitmapFetcher();
27 // match up the bitmap with a specific request.
28 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) = 0;
29 30
30 protected: 31 const GURL& url() const { return url_; }
31 virtual ~NotificationBitmapFetcherDelegate() {}
32 };
33 32
34 class NotificationBitmapFetcher 33 // Start fetching the URL with the fetcher. The delegate is notified
35 : public net::URLFetcherDelegate, 34 // asynchronously when done.
36 public ImageDecoder::Delegate {
37 public:
38 NotificationBitmapFetcher(
39 const GURL& url,
40 NotificationBitmapFetcherDelegate* delegate);
41 virtual ~NotificationBitmapFetcher();
42
43 GURL url() const { return url_; }
44
45 // Start fetching the URL with the fetcher. The operation will be continued
46 // in the OnURLFetchComplete callback.
47 void Start(Profile* profile); 35 void Start(Profile* profile);
48 36
49 // Methods inherited from URLFetcherDelegate 37 // Methods inherited from URLFetcherDelegate
50 38
51 // This will be called when the URL has been fetched, successfully or not. 39 // This will be called when the URL has been fetched, successfully or not.
52 // Use accessor methods on |source| to get the results. 40 // Use accessor methods on |source| to get the results.
53 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 41 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
54 42
55 // This will be called when some part of the response is read. |current| 43 // 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 44 // 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). 45 // expected total size of the response (or -1 if not determined).
58 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, 46 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
59 int64 current, int64 total) OVERRIDE; 47 int64 current,
48 int64 total) OVERRIDE;
60 49
61 // Methods inherited from ImageDecoder::Delegate 50 // Methods inherited from ImageDecoder::Delegate
62 51
63 // Called when image is decoded. |decoder| is used to identify the image in 52 // 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 53 // case of decoding several images simultaneously. This will not be called
65 // on the UI thread. 54 // on the UI thread.
66 virtual void OnImageDecoded(const ImageDecoder* decoder, 55 virtual void OnImageDecoded(const ImageDecoder* decoder,
67 const SkBitmap& decoded_image) OVERRIDE; 56 const SkBitmap& decoded_image) OVERRIDE;
68 57
69 // Called when decoding image failed. 58 // Called when decoding image failed.
70 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; 59 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
71 60
72 private: 61 private:
62 // Alerts the delegate that a failure occurred.
63 void ReportFailure();
64
73 scoped_ptr<net::URLFetcher> url_fetcher_; 65 scoped_ptr<net::URLFetcher> url_fetcher_;
74 scoped_refptr<ImageDecoder> image_decoder_; 66 scoped_refptr<ImageDecoder> image_decoder_;
75 const GURL url_; 67 const GURL url_;
76 scoped_ptr<SkBitmap> bitmap_; 68 BitmapFetcherDelegate* const delegate_;
77 NotificationBitmapFetcherDelegate* const delegate_;
78 69
79 DISALLOW_COPY_AND_ASSIGN(NotificationBitmapFetcher); 70 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher);
80 }; 71 };
81 72
82 } // namespace notifier 73 } // namespace chrome
83 74
84 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHE R_H_ 75 #endif // CHROME_BROWSER_BITMAP_FETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/bitmap_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698