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 Notifications Bitmap Fetching improve unit tests 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
22 namespace notifier {
23
24 class NotificationBitmapFetcher
25 : public net::URLFetcherDelegate,
26 public ImageDecoder::Delegate,
27 public base::RefCountedThreadSafe<NotificationBitmapFetcher> {
28 public:
29 NotificationBitmapFetcher(GURL& url,
30 scoped_ptr<net::URLFetcher>& url_fetcher,
31 scoped_refptr<base::MessageLoopProxy> task_runner);
32 ~NotificationBitmapFetcher();
33
34 bool image_ready();
35
36 bool image_failed();
37
38 // Returns an unowned pointer to the fetched and decoded bitmap.
39 SkBitmap* bitmap();
40
41 // Start fetching the URL with the fetcher. The operation will be continued
42 // in the OnURLFetchComplete callback.
43 void StartImageFetch();
44
45 // Copy the output bitmap. This takes ownership of the bitmap. It is called
46 // on the UI thread. This also notifies observers.
47 void HandleImageDecoded(scoped_ptr<SkBitmap> bitmap);
48
49 // If a bitmap image decode fails, notify observers of the failure.
50 void HandleImageFailed();
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 scoped_refptr<base::MessageLoopProxy> task_runner_;
79 // |image_ready_| will be set to true once the image is fetched and decoded.
80 bool image_ready_;
81 // |image_failed_| will be set to true if we cannot fetch or decode the image.
82 bool image_failed_;
83 GURL url_;
84 scoped_ptr<SkBitmap> bitmap_;
85 int64 progress_current_;
86 int64 progress_total_;
87
88 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, ImageReadyTest);
89 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, StartFetchTest);
90 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest,
91 HandleImageDecodedTest);
92 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest,
93 HandleImageFailedTest);
94
95 DISALLOW_COPY_AND_ASSIGN(NotificationBitmapFetcher);
96 };
97
98 } // namespace notifier
99
100 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHE R_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698