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

Unified Diff: content/child/notifications/notification_image_loader.h

Issue 939513002: Factor out a PendingNotificationTracker from the NotificationManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-sounds
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/child/notifications/notification_image_loader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/notifications/notification_image_loader.h
diff --git a/content/child/notifications/notification_image_loader.h b/content/child/notifications/notification_image_loader.h
index 14a36dafa72c4398e7a47f0d99b654a034ef52b9..33a38f065a97cedc753a03209f8d0da17103367b 100644
--- a/content/child/notifications/notification_image_loader.h
+++ b/content/child/notifications/notification_image_loader.h
@@ -10,8 +10,10 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/sequenced_task_runner_helpers.h"
#include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
+class GURL;
class SkBitmap;
namespace base {
@@ -26,33 +28,28 @@ class WebURLLoader;
namespace content {
-class NotificationImageLoader;
-
-// Callback to be invoked when an image load has been completed.
-using NotificationImageLoadedCallback =
- base::Callback<void(scoped_refptr<NotificationImageLoader>)>;
+struct NotificationImageLoaderDeleter;
// Downloads the image associated with a notification and decodes the received
// image. This must be completed before notifications are shown to the user.
-// Image downloaders must not be re-used for multiple notifications. The image
-// loader must be started from the main thread, but will invoke the callback on
-// the thread identified in the StartOnMainThread call.
+// Image downloaders must not be re-used for multiple notifications.
+//
+// All methods, except for the constructor, are expected to be used on the
+// renderer main thread.
class NotificationImageLoader
: public blink::WebURLLoaderClient,
- public base::RefCountedThreadSafe<NotificationImageLoader> {
+ public base::RefCountedThreadSafe<NotificationImageLoader,
+ NotificationImageLoaderDeleter> {
+ using ImageLoadCompletedCallback = base::Callback<void(int, const SkBitmap&)>;
+
public:
- explicit NotificationImageLoader(
- const NotificationImageLoadedCallback& callback);
-
- // Asynchronously starts loading |image_url|.
- // Must be called on the main thread. The callback should be executed by
- // |worker_task_runner|.
- void StartOnMainThread(
- const blink::WebURL& image_url,
+ NotificationImageLoader(
+ const ImageLoadCompletedCallback& callback,
const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner);
- // Returns the SkBitmap resulting from decoding the loaded buffer.
- SkBitmap GetDecodedImage() const;
+ // Asynchronously starts loading |image_url| using a Blink WebURLLoader. Must
+ // only be called on the main thread.
+ void StartOnMainThread(int notification_id, const GURL& image_url);
// blink::WebURLLoaderClient implementation.
virtual void didReceiveData(blink::WebURLLoader* loader,
@@ -66,7 +63,11 @@ class NotificationImageLoader
const blink::WebURLError& error);
private:
- friend class base::RefCountedThreadSafe<NotificationImageLoader>;
+ friend class base::DeleteHelper<NotificationImageLoader>;
+ friend class base::RefCountedThreadSafe<NotificationImageLoader,
+ NotificationImageLoaderDeleter>;
+ friend struct NotificationImageLoaderDeleter;
+
virtual ~NotificationImageLoader();
// Invokes the callback on the thread this image loader was started for. When
@@ -74,18 +75,34 @@ class NotificationImageLoader
// For all other threads a task will be posted to the appropriate task runner.
void RunCallbackOnWorkerThread();
- NotificationImageLoadedCallback callback_;
+ // Returns a Skia bitmap, empty if buffer_ was empty or could not be decoded
+ // as an image, or a valid bitmap otherwise.
+ SkBitmap GetDecodedImage() const;
+
+ // Ensures that we delete the image loader on the main thread.
+ void DeleteOnCorrectThread() const;
+
+ ImageLoadCompletedCallback callback_;
- scoped_ptr<blink::WebURLLoader> url_loader_;
scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
+
+ int notification_id_;
bool completed_;
+ scoped_ptr<blink::WebURLLoader> url_loader_;
+
std::vector<uint8_t> buffer_;
DISALLOW_COPY_AND_ASSIGN(NotificationImageLoader);
};
+struct NotificationImageLoaderDeleter {
+ static void Destruct(const NotificationImageLoader* context) {
+ context->DeleteOnCorrectThread();
+ }
+};
+
} // namespace content
#endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_IMAGE_LOADER_H_
« no previous file with comments | « no previous file | content/child/notifications/notification_image_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698