| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ | 5 #ifndef WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ |
| 6 #define WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ | 6 #define WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback_old.h" | 9 #include "base/callback.h" |
| 10 #include "webkit/glue/resource_fetcher.h" | 10 #include "webkit/glue/resource_fetcher.h" |
| 11 | 11 |
| 12 class SkBitmap; | 12 class SkBitmap; |
| 13 | 13 |
| 14 namespace webkit_glue { | 14 namespace webkit_glue { |
| 15 | 15 |
| 16 // ImageResourceFetcher handles downloading an image for a webview. Once | 16 // ImageResourceFetcher handles downloading an image for a webview. Once |
| 17 // downloading is done the supplied callback is notified. ImageResourceFetcher | 17 // downloading is done the supplied callback is notified. ImageResourceFetcher |
| 18 // is used to download the favicon and images for web apps. | 18 // is used to download the favicon and images for web apps. |
| 19 class ImageResourceFetcher { | 19 class ImageResourceFetcher { |
| 20 public: | 20 public: |
| 21 typedef Callback2<ImageResourceFetcher*, const SkBitmap&>::Type Callback; | 21 typedef base::Callback<void(ImageResourceFetcher*, const SkBitmap&)> Callback; |
| 22 | 22 |
| 23 ImageResourceFetcher(const GURL& image_url, | 23 ImageResourceFetcher(const GURL& image_url, |
| 24 WebKit::WebFrame* frame, | 24 WebKit::WebFrame* frame, |
| 25 int id, | 25 int id, |
| 26 int image_size, | 26 int image_size, |
| 27 WebKit::WebURLRequest::TargetType target_type, | 27 WebKit::WebURLRequest::TargetType target_type, |
| 28 Callback* callback); | 28 const Callback& callback); |
| 29 | 29 |
| 30 virtual ~ImageResourceFetcher(); | 30 virtual ~ImageResourceFetcher(); |
| 31 | 31 |
| 32 // URL of the image we're downloading. | 32 // URL of the image we're downloading. |
| 33 const GURL& image_url() const { return image_url_; } | 33 const GURL& image_url() const { return image_url_; } |
| 34 | 34 |
| 35 // Unique identifier for the request. | 35 // Unique identifier for the request. |
| 36 int id() const { return id_; } | 36 int id() const { return id_; } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 // ResourceFetcher::Callback. Decodes the image and invokes callback_. | 39 // ResourceFetcher::Callback. Decodes the image and invokes callback_. |
| 40 void OnURLFetchComplete(const WebKit::WebURLResponse& response, | 40 void OnURLFetchComplete(const WebKit::WebURLResponse& response, |
| 41 const std::string& data); | 41 const std::string& data); |
| 42 | 42 |
| 43 scoped_ptr<Callback> callback_; | 43 Callback callback_; |
| 44 | 44 |
| 45 // Unique identifier for the request. | 45 // Unique identifier for the request. |
| 46 const int id_; | 46 const int id_; |
| 47 | 47 |
| 48 // URL of the image. | 48 // URL of the image. |
| 49 const GURL image_url_; | 49 const GURL image_url_; |
| 50 | 50 |
| 51 // The size of the image. This is only a hint that is used if the image | 51 // The size of the image. This is only a hint that is used if the image |
| 52 // contains multiple sizes. A value of 0 results in using the first frame | 52 // contains multiple sizes. A value of 0 results in using the first frame |
| 53 // of the image. | 53 // of the image. |
| 54 const int image_size_; | 54 const int image_size_; |
| 55 | 55 |
| 56 // Does the actual download. | 56 // Does the actual download. |
| 57 scoped_ptr<ResourceFetcher> fetcher_; | 57 scoped_ptr<ResourceFetcher> fetcher_; |
| 58 | 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(ImageResourceFetcher); | 59 DISALLOW_COPY_AND_ASSIGN(ImageResourceFetcher); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 } // namespace webkit_glue | 62 } // namespace webkit_glue |
| 63 | 63 |
| 64 #endif // WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ | 64 #endif // WEBKIT_GLUE_IMAGE_RESOURCE_FETCHER_H_ |
| OLD | NEW |