1 // Copyright 2014 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 CONTENT_RENDERER_NOTIFICATION_ICON_LOADER_H_
6 #define CONTENT_RENDERER_NOTIFICATION_ICON_LOADER_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
24 // Downloads the icon associated with a notification and decodes the received
25 // image. This must be completed before notifications are shown to the user.
26 // Icon downloaders must not be re-used for multiple notifications or icons.
27 class NotificationIconLoader
: public blink::WebURLLoaderClient
{
28 typedef base::Callback
<void(int, const SkBitmap
&)> DownloadCompletedCallback
;
31 NotificationIconLoader(int notification_id
,
32 const DownloadCompletedCallback
& callback
);
34 virtual ~NotificationIconLoader();
36 // Downloads the notification's image and invokes the callback with the
37 // decoded SkBitmap when the download has succeeded, or with an empty SkBitmap
38 // in case the download has failed.
39 void Start(const blink::WebURL
& icon_url
);
41 // Cancels the current image download. The callback will not be invoked.
44 // blink::WebURLLoaderClient implementation.
45 virtual void didReceiveData(blink::WebURLLoader
* loader
,
48 int encoded_data_length
);
49 virtual void didFinishLoading(blink::WebURLLoader
* loader
,
51 int64_t total_encoded_data_length
);
52 virtual void didFail(blink::WebURLLoader
* loader
,
53 const blink::WebURLError
& error
);
55 int notification_id() const {
56 return notification_id_
;
61 DownloadCompletedCallback callback_
;
63 scoped_ptr
<blink::WebURLLoader
> loader_
;
66 std::vector
<uint8_t> buffer_
;
68 DISALLOW_COPY_AND_ASSIGN(NotificationIconLoader
);
71 } // namespace content
73 #endif // CONTENT_RENDERER_NOTIFICATION_ICON_LOADER_H_