1// Copyright (c) 2012 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 CONTENT_RENDERER_FETCHERS_MULTI_RESOLUTION_IMAGE_RESOURCE_FETCHER_H_
6#define CONTENT_RENDERER_FETCHERS_MULTI_RESOLUTION_IMAGE_RESOURCE_FETCHER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/callback.h"
13#include "base/memory/scoped_ptr.h"
14#include "third_party/WebKit/public/platform/WebURLRequest.h"
15#include "url/gurl.h"
16
17class SkBitmap;
18
19namespace blink {
20class WebFrame;
21class WebURLResponse;
22}
23
24namespace content {
25
26class ResourceFetcher;
27
28// A resource fetcher that returns all (differently-sized) frames in
29// an image. Useful for favicons.
30class MultiResolutionImageResourceFetcher {
31 public:
32  typedef base::Callback<void(MultiResolutionImageResourceFetcher*,
33                              const std::vector<SkBitmap>&)> Callback;
34
35  MultiResolutionImageResourceFetcher(
36      const GURL& image_url,
37      blink::WebFrame* frame,
38      int id,
39      blink::WebURLRequest::TargetType target_type,
40      const Callback& callback);
41
42  virtual ~MultiResolutionImageResourceFetcher();
43
44  // URL of the image we're downloading.
45  const GURL& image_url() const { return image_url_; }
46
47  // Unique identifier for the request.
48  int id() const { return id_; }
49
50  // HTTP status code upon fetch completion.
51  int http_status_code() const { return http_status_code_; }
52
53 private:
54  // ResourceFetcher::Callback. Decodes the image and invokes callback_.
55  void OnURLFetchComplete(const blink::WebURLResponse& response,
56                          const std::string& data);
57
58  Callback callback_;
59
60  // Unique identifier for the request.
61  const int id_;
62
63  // HTTP status code upon fetch completion.
64  int http_status_code_;
65
66  // URL of the image.
67  const GURL image_url_;
68
69  // Does the actual download.
70  scoped_ptr<ResourceFetcher> fetcher_;
71
72  DISALLOW_COPY_AND_ASSIGN(MultiResolutionImageResourceFetcher);
73};
74
75}  // namespace content
76
77#endif  // CONTENT_RENDERER_FETCHERS_MULTI_RESOLUTION_IMAGE_RESOURCE_FETCHER_H_
78