Chromecast: extracts Linux window creation code to a common place.
[chromium-blink-merge.git] / content / renderer / notification_icon_loader.h
blob5bb95f80479f83d966111066dce457a03f524e68
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_
8 #include <vector>
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
14 class SkBitmap;
16 namespace blink {
17 class WebURL;
18 struct WebURLError;
19 class WebURLLoader;
22 namespace content {
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;
30 public:
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.
42 void Cancel();
44 // blink::WebURLLoaderClient implementation.
45 virtual void didReceiveData(blink::WebURLLoader* loader,
46 const char* data,
47 int data_length,
48 int encoded_data_length);
49 virtual void didFinishLoading(blink::WebURLLoader* loader,
50 double finish_time,
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_;
59 private:
60 int notification_id_;
61 DownloadCompletedCallback callback_;
63 scoped_ptr<blink::WebURLLoader> loader_;
64 bool completed_;
66 std::vector<uint8_t> buffer_;
68 DISALLOW_COPY_AND_ASSIGN(NotificationIconLoader);
71 } // namespace content
73 #endif // CONTENT_RENDERER_NOTIFICATION_ICON_LOADER_H_