summaryrefslogtreecommitdiffstats
path: root/content/renderer/fetchers/manifest_fetcher.h
blob: a75a660410df293accb5ef9523a2da6ce45786d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_
#define CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_

#include <string>

#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "content/common/content_export.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"

class GURL;

namespace blink {
class WebFrame;
}

namespace content {

class ResourceFetcher;

// Helper class to download a Web Manifest. When an instance is created, the
// caller need to call Start() and wait for the passed callback to be executed.
// If the fetch fails, the callback will be called with two empty objects.
class CONTENT_EXPORT ManifestFetcher {
 public:
  // This will be called asynchronously after the URL has been fetched,
  // successfully or not.  If there is a failure, response and data will both be
  // empty.  |response| and |data| are both valid until the URLFetcher instance
  // is destroyed.
  typedef base::Callback<void(const blink::WebURLResponse& response,
                              const std::string& data)> Callback;

  explicit ManifestFetcher(const GURL& url);
  virtual ~ManifestFetcher();

  void Start(blink::WebFrame* frame,
             bool use_credentials,
             const Callback& callback);
  void Cancel();

 private:
  void OnLoadComplete(const blink::WebURLResponse& response,
                      const std::string& data);

  bool completed_;
  Callback callback_;
  scoped_ptr<ResourceFetcher> fetcher_;

  DISALLOW_COPY_AND_ASSIGN(ManifestFetcher);
};

} // namespace content

#endif  // CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_