Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / fetchers / manifest_fetcher.h
blob8b83b3aa1bfcc499f29424ea7ccf44c00f72f360
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_FETCHERS_MANIFEST_FETCHER_H_
6 #define CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/common/content_export.h"
14 #include "third_party/WebKit/public/platform/WebURLResponse.h"
16 class GURL;
18 namespace blink {
19 class WebFrame;
22 namespace content {
24 class ResourceFetcher;
26 // Helper class to download a Web Manifest. When an instance is created, the
27 // caller need to call Start() and wait for the passed callback to be executed.
28 // If the fetch fails, the callback will be called with two empty objects.
29 class CONTENT_EXPORT ManifestFetcher {
30 public:
31 // This will be called asynchronously after the URL has been fetched,
32 // successfully or not. If there is a failure, response and data will both be
33 // empty. |response| and |data| are both valid until the URLFetcher instance
34 // is destroyed.
35 typedef base::Callback<void(const blink::WebURLResponse& response,
36 const std::string& data)> Callback;
38 explicit ManifestFetcher(const GURL& url);
39 virtual ~ManifestFetcher();
41 void Start(blink::WebFrame* frame, const Callback& callback);
42 void Cancel();
44 private:
45 void OnLoadComplete(const blink::WebURLResponse& response,
46 const std::string& data);
48 bool completed_;
49 Callback callback_;
50 scoped_ptr<ResourceFetcher> fetcher_;
52 DISALLOW_COPY_AND_ASSIGN(ManifestFetcher);
55 } // namespace content
57 #endif // CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_