Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / renderer / fetchers / manifest_fetcher.h
bloba75a660410df293accb5ef9523a2da6ce45786d1
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,
42 bool use_credentials,
43 const Callback& callback);
44 void Cancel();
46 private:
47 void OnLoadComplete(const blink::WebURLResponse& response,
48 const std::string& data);
50 bool completed_;
51 Callback callback_;
52 scoped_ptr<ResourceFetcher> fetcher_;
54 DISALLOW_COPY_AND_ASSIGN(ManifestFetcher);
57 } // namespace content
59 #endif // CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_