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

Side by Side Diff: chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher.h

Issue 15295018: Continue bitmap fetching for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced Notification Bitmap Fetching - refactor to use delegates instead of notifications Created 7 years, 7 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
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H _
6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H _
7
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "chrome/browser/image_decoder.h"
12 #include "googleurl/src/gurl.h"
13 #include "net/url_request/url_fetcher_delegate.h"
14 #include "third_party/skia/include/core/SKBitmap.h"
15
16 namespace net {
17 class URLFetcher;
18 } // namespace net
19
20 class NotificationBitmapFetcherTest;
21 class NotificationBitmapFetcherBrowserTest;
22
23 namespace notifier {
24
25 // A delegate interface for users of NotificationBitmapFetcher.
26 class NotificationBitmapFetcherDelegate {
27 public:
28 // This will be called when the bitmap has been fetched, successfully or not.
29 virtual void OnFetchComplete(const bool success, SkBitmap* bitmap) = 0;
dcheng 2013/05/28 20:11:34 Generally, it's not required to add a const to int
Pete Williamson 2013/05/29 18:05:00 Done.
30
31 protected:
32 virtual ~NotificationBitmapFetcherDelegate() {}
33 };
34
35 class NotificationBitmapFetcher
36 : public net::URLFetcherDelegate,
37 public ImageDecoder::Delegate,
38 public base::RefCountedThreadSafe<NotificationBitmapFetcher> {
39 public:
40 explicit NotificationBitmapFetcher(
41 const GURL& url,
42 NotificationBitmapFetcherDelegate* delegate);
43 ~NotificationBitmapFetcher();
44
45 // Start fetching the URL with the fetcher. The operation will be continued
46 // in the OnURLFetchComplete callback.
47 void StartImageFetch();
48
49 // If a bitmap image decode fails, notify observers of the failure.
50 void HandleImageFailed();
dcheng 2013/05/28 20:11:34 This is declared but not defined anywhere. Perhaps
Pete Williamson 2013/05/29 18:05:00 Yep. Removed.
51
52 // Methods inherited from URLFetcherDelegate
53
54 // This will be called when the URL has been fetched, successfully or not.
55 // Use accessor methods on |source| to get the results.
56 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
57
58 // This will be called when some part of the response is read. |current|
59 // denotes the number of bytes received up to the call, and |total| is the
60 // expected total size of the response (or -1 if not determined).
61 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
62 int64 current, int64 total) OVERRIDE;
63
64 // Methods inherited from ImageDecoder::Delegate
65
66 // Called when image is decoded. |decoder| is used to identify the image in
67 // case of decoding several images simultaneously. This will not be called
68 // on the UI thread.
69 virtual void OnImageDecoded(const ImageDecoder* decoder,
70 const SkBitmap& decoded_image) OVERRIDE;
71
72 // Called when decoding image failed.
73 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
74
75 private:
76 scoped_ptr<net::URLFetcher> url_fetcher_;
77 scoped_refptr<ImageDecoder> image_decoder_;
78 // |image_ready_| will be set to true once the image is fetched and decoded.
79 bool image_ready_;
80 GURL url_;
dcheng 2013/05/28 20:11:34 Nit: constify this.
Pete Williamson 2013/05/29 18:05:00 Done.
81 scoped_ptr<SkBitmap> bitmap_;
82 NotificationBitmapFetcherDelegate* delegate_;
dcheng 2013/05/28 20:11:34 Nit: NotificationBitmapFetcherDelegate* const dele
Pete Williamson 2013/05/29 18:05:00 Done.
83
84 // Used to pass in a fetcher for dependency injection in tests.
85 void SetURLFetcherForTest(scoped_ptr<net::URLFetcher>& url_fetcher);
dcheng 2013/05/28 20:11:34 Just make this a public method. Also, is it intent
Pete Williamson 2013/05/29 18:05:00 Done. Yes, it is intentional. We need to overrid
dcheng 2013/05/29 20:40:29 Yes, but why does the argument have to a mutable r
Pete Williamson 2013/05/30 00:13:18 My thinking is that if this is a const reference,
dcheng 2013/05/30 00:38:14 Smart pointers aren't generally meant to be passed
Pete Williamson 2013/05/30 22:22:17 Done.
86
87 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, ImageReadyTest);
dcheng 2013/05/28 20:11:34 Are all these friend declarations required?
Pete Williamson 2013/05/29 18:05:00 Removed.
88 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, StartFetchTest);
89 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, OnImageDecodedTest);
90 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest,
91 OnURLFetchFailureTest);
92 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest,
93 HandleImageFailedTest);
94 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherBrowserTest,
95 OnURLFetchCompleteTest);
96
97
98 DISALLOW_COPY_AND_ASSIGN(NotificationBitmapFetcher);
99 };
100
101 } // namespace notifier
102
103 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHE R_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698